1.2.1 • Published 6 years ago
@fooxly/translation v1.2.1
Fooxly translation
This is a simple custom translation module.
Usage
setup
import { Language, Translation, string } from "@fooxly/translation";
const languages = {
'en-US': require('./translations/en-US.json'),
'nl-NL': require('./translations/nl-NL.json')
}
Language.setup(languages, {
default: 'en-US',
useBrowserLanguage: false
});
update language
To update the current language run:
myUpdateMethod() {
if(Language.set('nl-NL')) {
// a valid language code was given
}
this.forceUpdate();
}
add language elements
Language items can be created by importing the Translation
component:
<Translation id='foo.bar'/>
Language items can also be given as props:
string('foo.bar')
The ID is the key from the language file(defined before). The language file will look look like this:
{
"foo": {
"bar": "Bar"
}
}