Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. const translationGetters = {
  2. // lazy requires (metro bundler does not support symlinks)
  3. ar: () => require("./src/translations/ar.json"),
  4. en: () => require("./src/translations/en.json"),
  5. fr: () => require("./src/translations/fr.json")
  6. };
  7.  
  8. const translate = memoize(
  9. (key, config) => i18n.t(key, config),
  10. (key, config) => (config ? key + JSON.stringify(config) : key)
  11. );
  12.  
  13. const setI18nConfig = () => {
  14. // fallback if no available language fits
  15. const fallback = { languageTag: "en", isRTL: false };
  16.  
  17. const { languageTag, isRTL } =
  18. RNLocalize.findBestAvailableLanguage(Object.keys(translationGetters)) ||
  19. fallback;
  20.  
  21. // clear translation cache
  22. translate.cache.clear();
  23. // update layout direction
  24. I18nManager.forceRTL(isRTL);
  25. // set i18n-js config
  26. i18n.translations = { [languageTag]: translationGetters[languageTag]() };
  27. i18n.locale = languageTag;
  28. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement