Localization for some text not loading

  1. SDK Version: 3.20.1
  2. Platforms(Android/iOS/web/all): Android and iOS

Trying to set up an app with dual language support with typescript on expo. Default langauge is english but also wanting to have Chinese as well for some users.

When english, there doesn’t seem to be any issues, only when it’s in Chinese.
Most of the app will appear in Chinese, however, there are areas where language will remain in English.

  • It’ll look to en locale instead of chinese

Found that all of the content inside of a constant had issues with localization.

import { t } from '../../../constants/i18n'

const arrayOfObjects = 
[
    {
      handle: "test1",
      title: t("test1"),
    },
    {
      handle: "test2",
      title: t("test2"),
    }
]
import * as Localization from 'expo-localization';
import I18n from 'i18n-js';

// import translations
import en from './en.json'
import zh from './zh.json'

// bind translations to i18n
I18n.translations = {
  en,
  zh
}

// set phones language
const getLanguage = async() => {
  try {
    const choice = await Localization.locale
    I18n.locale = choice.substr(0, 2)
    I18n.initAsync()
  } catch (error) {
    console.log(Localization.locale)
  }
}

getLanguage()

// export function
export function t(name: string) {
  return I18n.t(name)
}

I got rid of the await and it seems to be working :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.