2023年10月6日金曜日

react native 国際化対応 その3

http://shinogono.blogspot.com/2023/10/react-native_2.html

からの続き


1.変数を埋める

ja.json

{
"Welcome to React": "ようこそ {{arg1}} と {{arg2}} "
}


App.js

  return (
    <View>
      <Text>
        {t('Welcome to React', {arg1: 'React', arg2: 'react-i18next'})}
      </Text>
    </View>
  );



2.prefixをつける

ja.json

{
  "title": {
    "welcome": "タイトル ようこそ"
  },
  "message": {
    "welcome": "メッセージ ようこそ"
  }
}


App.js

  return (
    <View>
      <Text>{t('title.welcome')}</Text>
      <Text>{t('message.welcome')}</Text>
    </View>
  );


0 件のコメント:

コメントを投稿