Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setLanguage() on fly. React Native 0.64.2 #207

Open
rusakovic opened this issue Aug 19, 2021 · 0 comments
Open

setLanguage() on fly. React Native 0.64.2 #207

rusakovic opened this issue Aug 19, 2021 · 0 comments

Comments

@rusakovic
Copy link

rusakovic commented Aug 19, 2021

"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>
</>
)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant