This library help you to translate easy in 50 languages and its easy to use
npm install react-native-language-translations
Make sure to build project again after installing the dependency
This package first downloads the modal which you want to use for that you have to call a method createLanguageTranslator giving parameters as languages codes.
import {
createLanguageTranslator,
translate,
getAllLanguages,
} from 'react-native-language-translations';
// english to chinese
const t = (text: string) => {
createLanguageTranslator('en', 'zh', () => {
translate(text, (result: string) => {
setResult(result);
});
});
};
getAllLanguages((val: String) => {
console.log(val);
let langVal = [];
Object.keys(val).forEach((i) => langVal.push(i));
});
// ...
Parameter | Type | Description | iOS | Android |
---|---|---|---|---|
createLanguageTranslator | Function | Downloads the trasnlator modal just pass to and from language code | X | ✔ |
translate | Function | used too translate text | X | ✔ |
| getAllLanguages | Function | returns all the supported languages | X | ✔ |
MIT