Skip to content

setLanguage() on fly. React Native 0.64.2 #207

@rusakovic

Description

@rusakovic

"react-native-localization": "^2.1.7",
"react-native": "0.64.2",

Language in iOS: 'ru'
Trying change to: 'it'

But after pressing the button, state is not changeable.
If I leave strings.setLanguage('it'); in the component, after reloading the app, language is switched to 'it'.
So, is it not possible to change the language on fly?
Should I save the language to database, and set the language from database during app loading?

Thank you!

My code:

const App = () => {
  let strings = new LocalizedStrings({
    'en-US': {
      how: 'How do you want your egg today?',
    },
    en: {
      how: 'How do you want your egg today?',
    },
    ru: {
      how: 'даd',
    },
    it: {
      how: 'si',
    },
  });

  const [, setLanguage] = useState(0);

  const setLanguageHandler = () => {
    console.log('language');
    strings.setLanguage('it');
    setLanguage(1);
  }
return (
<>
     <Button  onPress={setLanguageHandler}/>
    <Text>{strings.how}</Text>
</>
)
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions