react-native-i18n
react-native-i18n copied to clipboard
Updating I18n.translations with 'live' data: is it possible?
I would like to 'live' translate my app... I.e.: after I load static json translations files, I want to update it with possible live updates from a public url. But this does not seem too update translations...
This is my code:
import I18n from 'react-native-i18n';
import en from '../Assets/Locales/en.json';
import it from '../Assets/Locales/it.json';
import fr from '../Assets/Locales/fr.json';
// use static languages, initially
I18n.translations = { en, it, fr };
I18n.fallbacks = true;
// 'live' update
let language = 'it'; // (just update italian language, to make things simple...)
let url = `https://my.public.server/i18n/${language}.json`;
fetch(url)
.then(response => response.json())
.then(newTranslations => {
const mergedContents = Object.assign(I18n.translations[language], newTranslations);
I18n.translations[language] = mergedContents;
// add new json language merged with current JSON language to I18n.translations
/**
* NOTE: code reaches here, and I18n.translations[language] is updated with live
* contents, but new translations are not displayed by the app... :-(
* Probably I should call some I18n.translationsRefresh() method, here...
*/
})
;
export default I18n;
Any clue?
Please leave a comment here if you find a solution. I am looking for the same solution. So far the one option I can think of is to possibly register app for codePush and push your translation files as and when updates are there. I am interested to know if there is another easier option.
Have you given a shot at 'react-native-localization' ? They seem to support update with strings.setContent()
@getavinashm: I gave a shot to react-native-localization. I see they do update contents 'live', but I want to stay with i18n... I'm looking for some sort of I18m.translationsRefresh()
method...
Hey guys, any solution?
Hey you guys, Do you guys have any solution?