Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
replace deprecated react-native-i18n (#105)
Browse files Browse the repository at this point in the history
* replace deprecated react-native-i18n

use react-native-languages and i18n-js instead

* fix linting errors
  • Loading branch information
marcelkalveram authored and kevinvangelder committed Sep 26, 2018
1 parent afd34f3 commit 62e816e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion boilerplate/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"mobx-react": "5.1.2",
"mobx-state-tree": "2.0.5",
"ramda": "0.25.0",
"react-native-i18n": "2.0.12",
"react-native-languages": "^3.0.0",
"i18n-js": "^3.0.11",
"react-native-keychain": "3.0.0-rc.3",
"react-native-splash-screen": "3.0.6",
"react-navigation": "2.3.1",
Expand Down
8 changes: 5 additions & 3 deletions boilerplate/src/i18n/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import I18n from "react-native-i18n"
import RNLanguages from "react-native-languages"
import i18n from "i18n-js"

const en = require("./en")
const ja = require("./ja")

I18n.fallbacks = true
I18n.translations = { en, ja }
i18n.locale = RNLanguages.language
i18n.fallbacks = true
i18n.translations = { en, ja }
6 changes: 3 additions & 3 deletions boilerplate/src/i18n/translate.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import I18n from "react-native-i18n"
import i18n from "i18n-js"

/**
* Translates text.
*
* @param key The i18n key.
*/
export function translate(key: string) {
return key ? I18n.t(key) : null
return key ? i18n.t(key) : null
}

/**
Expand All @@ -16,5 +16,5 @@ export function translate(key: string) {
* @param vars Additional values sure to replace.
*/
export function translateWithVars(key: string, vars: object) {
return key ? I18n.t(key, vars) : null
return key ? i18n.t(key, vars) : null
}
2 changes: 1 addition & 1 deletion boilerplate/test/mock-i18n.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jest.mock("react-native-i18n", () => {
jest.mock("i18n-js", () => {
return {
t: key => `${key}.test`,
}
Expand Down

0 comments on commit 62e816e

Please sign in to comment.