ignite-i18n
Advanced tools
Comparing version 1.1.1 to 1.2.0
{ | ||
"name": "ignite-i18n", | ||
"description": "An Ignite plugin which installs react-native-i18n.", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"license": "MIT", | ||
@@ -34,3 +34,7 @@ "files": [ | ||
"standard": "^8.6.0" | ||
}, | ||
"prettier": { | ||
"singleQuote": true, | ||
"semi": false | ||
} | ||
} |
const NPM_MODULE_NAME = 'react-native-i18n' | ||
const NPM_MODULE_VERSION = '2.0.14' // update in `add.test.js` too | ||
const EXAMPLE_FILE = 'i18nExample.js.ejs' | ||
const add = async function (context) { | ||
const add = async function(context) { | ||
const { ignite, filesystem } = context | ||
// install a npm module | ||
await ignite.addModule(NPM_MODULE_NAME, { version: '1.0.0', link: true }) | ||
await ignite.addModule(NPM_MODULE_NAME, { | ||
version: NPM_MODULE_VERSION, | ||
link: true | ||
}) | ||
// copy the example file (if examples are turned on) | ||
await ignite.addPluginComponentExample(EXAMPLE_FILE, { title: 'i18n Example' }) | ||
await ignite.addPluginComponentExample(EXAMPLE_FILE, { | ||
title: 'i18n Example' | ||
}) | ||
@@ -28,3 +34,3 @@ // Copy templates/I18n to App/I18n if it doesn't already exist | ||
*/ | ||
const remove = async function (context) { | ||
const remove = async function(context) { | ||
const { ignite, filesystem, patching } = context | ||
@@ -42,8 +48,14 @@ | ||
) | ||
if (removeI18n) { filesystem.remove(`${process.cwd()}/App/I18n`) } | ||
if (removeI18n) { | ||
filesystem.remove(`${process.cwd()}/App/I18n`) | ||
} | ||
// Remove i18n from AppConfig | ||
patching.replaceInFile(`${process.cwd()}/App/Config/AppConfig.js`, `import '../I18n/I18n'\n`, '') | ||
patching.replaceInFile( | ||
`${process.cwd()}/App/Config/AppConfig.js`, | ||
`import '../I18n/I18n'\n`, | ||
'' | ||
) | ||
} | ||
module.exports = { add, remove } |
# ignite-i18n | ||
An [ignite plugin](https://github.com/infinitered/ignite) for [react-native-i18n](https://github.com/AlexanderZaytsev/react-native-i18n). | ||
An [Ignite plugin](https://github.com/infinitered/ignite) for adding [react-native-i18n](https://github.com/AlexanderZaytsev/react-native-i18n) to your React Native project. | ||
@@ -5,0 +5,0 @@ ## Premium Support |
@@ -73,5 +73,2 @@ // @flow | ||
break | ||
case 'in': | ||
I18n.translations.in = require('./languages/id.json') | ||
break | ||
case 'id': | ||
@@ -78,0 +75,0 @@ I18n.translations.id = require('./languages/id.json') |
@@ -6,7 +6,10 @@ import I18n from 'react-native-i18n' | ||
// This function is a wrapper to avoid exception wich leads in a crash | ||
const translateOrFallback = initialMsg => { | ||
const translateOrFallback = (initialMsg, options) => { | ||
// We tried to translate something else than a string | ||
// The native I18n function will simply crash instead of rejecting the attempt with an error message | ||
if (typeof initialMsg !== 'string') { | ||
__DEV__ && console.log(`I18n: you must give a string to translate instead of "${typeof initialMsg}"`) | ||
__DEV__ && | ||
console.log( | ||
`I18n: you must give a string to translate instead of "${typeof initialMsg}"` | ||
) | ||
@@ -16,3 +19,3 @@ return '' // We don't return any message as we don't know what to send | ||
let localMsg = I18n.t(initialMsg) | ||
let localMsg = I18n.t(initialMsg, options) | ||
@@ -22,3 +25,6 @@ // The translation does not exist, the default message is not very sexy | ||
if (missingTranslationRegex.test(localMsg)) { | ||
__DEV__ && console.log(`translation "${initialMsg}" does not exists in translations files`) | ||
__DEV__ && | ||
console.log( | ||
`translation "${initialMsg}" does not exists in translations files` | ||
) | ||
@@ -25,0 +31,0 @@ return initialMsg |
Sorry, the diff of this file is not supported yet
14192
313