Respond to localized localization: global variable

I am new to React, and I come from a world iOS/Androidwhere localized strings are all defined in dedicated files. I looked through react-native-localization, and it seems to us that we need to define a string object in each class, and then use the values ​​in the rendering. This seems rather inefficient and fragmented for me, or maybe I misunderstood the use. I could not find good use cases react-native-localization. I would really appreciate some advice.

+4
source share
2 answers

We used local localization for our project, and it is very useful, this is our use:

... / ApplicationRoot / Utils / strings.js

import LocalizedStrings from 'react-native-localization';

let Strings = new LocalizedStrings({
  ar:{
    hello:'أهلاً',
    howareyou:'كيف حالك؟'
  },
  en:{
    hello:'Hello!',
    howareyou:'How Are You?'
  }

});


module.exports = Strings;

after that we import it into any component that we want to use in it:

TestComponent.js:

import Strings from './utils/strings.js'

...

<Text>Strings.hello</Text>
+9
source

You can use this reaction library to configure localization. It also has abbreviated methods. And it also supports automatic device language detection.

0
source

Source: https://habr.com/ru/post/1654024/


All Articles