stefalda / ReactNativeLocalization

Class to localize the ReactNative interface
MIT License
900 stars 123 forks source link

language not persisted between session #227

Closed pierroo closed 1 year ago

pierroo commented 1 year ago

Hi,

let's say I have 3 translation (en, es, fr) When I edit it, I use the "setLanguage" function, which works great.

However, upon restarting the app, if I use the "getLanguage" it will constantly return the default language of my device, and NOT the language I had set before

so I constantly have to reset the language upon launching the app based on my persisted redux state (separate)

is there anyway to make this library language persist too?

stefalda commented 1 year ago

Hi Pierre, I don't believe that is up to this Library to persist the info, as you say you're already using some kind of persistence and you should use it and restore the state when instantiating it...

Stefano

pierroo commented 1 year ago

Ideally yes @stefalda ; the problem seems to be that when I setLanguage VERY early in the app (directly in the App.js for example) it is completely ignored. I have to wait one or two seconds after app load for it to be taken into account (either through a timeout or a subpage)

Is there an "initialization delay" before which any setLanguage is ignored?

stefalda commented 1 year ago

Hi @pierroo, have you tried to pass a custom getCustomInterfaceLanguage method as explained here?

https://github.com/stefalda/localized-strings/tree/master#custom-getinterfacelanguage-method

pierroo commented 1 year ago

Thank you for the suggestion, although I am not sure how I would use it in React Native.

This function is meant to pick one of the translation as default? If that's the case and if I want to pass my persisted (redux) language for example, not sure how I could use my redux useSelector hook in that static isolated function; but I'll work around it thanks again