Help us understand the problem. What is going on with this article?

i18nを使いReact Native(CRNA)で多言語化

More than 1 year has passed since last update.

react-native-i18nのエラー

CRNAreact-native-i18nを使用すると下記のエラーが出てしまう

"react-native-i18n module is not correctly linked"

Expo用にラップされたex-react-native-i18nを使う

I18n.localeがenしか取得できない

App.js
import React from 'react'
import { AppLoading } from 'expo'
import I18n from 'ex-react-native-i18n'
import Top from './Top'

export default class App extends React.Component {
  state = { isAssetsLoaded: false }

  componentWillMount() {
    this.loadAssetsAsync()
  }

  loadAssetsAsync = async () => {
    try {
      await I18n.initAsync()
    } catch (e) {
      // console.log(e.message)
    } finally {
      this.setState({ isAssetsLoaded: true })
    }
  }

  render() {
    return this.state.isAssetsLoaded ? <Top /> : <AppLoading />
  }
}

ファイルで管理する方法

i18n/index.js
import I18n from 'ex-react-native-i18n'
import en from './locales/en'
import ja from './locales/ja'

I18n.fallbacks = true

I18n.translations = {
  en,
  ja
}

export default I18n
i18n/locales/en.js
export default {
  cat: 'Cat',
  hello: 'Hello'
}
i18n/locales/ja.js
export default {
  cat: 'ねこ',
  hello: 'やぁやぁ'
}
HorieH
自分用のメモが多い ReactNativeでゲーム作ってます 猫が好き 履歴: Perl→PHP(CakePHP2,3)→AWS(ソリューションアーキテクト)、Lambda(Python)→JS(React/ReactNative/Redux)
https://horieapp.firebaseapp.com
admin-guild
「Webサービスの運営に必要なあらゆる知見」を共有できる場として作られた、運営者のためのコミュニティです。
https://admin-guild.slack.com
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした