Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
react-localization
Advanced tools
Simple module to localize the React interface using the same syntax used in the ReactNativeLocalization module
Simple module to localize the React interface using the same syntax used in the ReactNativeLocalization module.
The library uses the current interface language, then it loads and displays the strings matching the current interface locale or the default language (the first one if a match is not found) if a specific localization can't be found.
It's possible to force a language different from the interface one.
In the React class that you want to localize require the library and define the strings object passing to the constructor a simple object containing a language key (i.e. en, it, fr..) and then a list of key-value pairs with the needed localized strings.
\\ES6 module syntax
import LocalizedStrings from 'react-localization';
let strings = new LocalizedStrings({
en:{
how:"How do you want your egg today?",
boiledEgg:"Boiled egg",
softBoiledEgg:"Soft-boiled egg",
choice:"How to choose the egg"
},
it: {
how:"Come vuoi il tuo uovo oggi?",
boiledEgg:"Uovo sodo",
softBoiledEgg:"Uovo alla coque",
choice:"Come scegliere l'uovo"
}
});
Then use the strings
object literal directly in the render method accessing the key of the localized string.
<Text style={styles.title}>
{strings.how}
</Text>
en:{
bread:"bread",
butter:"butter",
question:"I'd like {0} and {1}, or just {0}"
}
...
strings.formatString(strings.question, strings.bread, strings.butter)
Beware: do not define a string key as formatString!
To force a particular language use something like this:
_onSetLanguageToItalian() {
strings.setLanguage('it');
this.setState({});
}
Feel free to contact me on Twitter or open an issue.
FAQs
Simple module to localize the React interface using the same syntax used in the ReactNativeLocalization module, use 'npm run build' before publishing
The npm package react-localization receives a total of 9,623 weekly downloads. As such, react-localization popularity was classified as popular.
We found that react-localization demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.