How to make my application in React-Note identify our language?

Asked

Viewed 195 times

-1

When I enter a text, e.g.:

<Text>Maçã</Text>

He doesn’t recognize it! I know it’s the goal utf8, but I don’t know where to insert it! Grateful from now on!

2 answers

0

From what I understand, you want to internationalize your application, correct? You will need a plugin such as the :

https://github.com/react-community/react-native-languages

npm install --save react-native-languages
react-native link react-native-languages

Use :

import RNLanguages from 'react-native-languages';

// Current device language
console.log('language', RNLanguages.language);

// User preferred languages (in order)
console.log('languages', RNLanguages.languages);

// Listening for languages changes (on Android)
RNLanguages.addEventListener('change', ({ language, languages }) => {
  // Do languages related things…
});

There is also the https://github.com/stefalda/ReactNativeLocalization

npm install react-native-localization --save
react-native link react-native-localization

And you can use creating components for the location

// ES6 module syntax
import LocalizedStrings from 'react-native-localization';

// CommonJS syntax
// let LocalizedStrings  = require ('react-native-localization');

let strings = new LocalizedStrings({
 "en-US":{
   how:"How do you want your egg today?",
   boiledEgg:"Boiled egg",
   softBoiledEgg:"Soft-boiled egg",
   choice:"How to choose the egg"
 },
 en:{
   how:"How do you want your egg today?",
   boiledEgg:"Boiled egg",
   softBoiledEgg:"Soft-boiled egg",
   choice:"How to choose the egg"
 },
 it: {
   how:"Come vuoi il tuo uovo oggi?",
   boiledEgg:"Uovo sodo",
   softBoiledEgg:"Uovo alla coque",
   choice:"Come scegliere l'uovo"
 }
});

And call

<Text style={styles.title}>
  {strings.how}
</Text>
  • Hello, Friend! First, thank you so much for trying to help me! I created a new project, installed the React-Native-Languages, following the first example you gave me... I downloaded the project folder and Linkei! I don’t know if this is the right way, but it didn’t work! maybe I did it the wrong way, if you can help me by being more specific, I’m grateful!

  • What happened? Did you use the same example? Nothing came out on the console? And the second example? I suggest trying it, it’s simpler

0

Solved! My editor’s settings were not utf8! So I set out to utf8, the characters appeared. Thanks for the help!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.