alexanderzaytsev / react-native-i18n Goto Github PK
View Code? Open in Web Editor NEWReact Native + i18n.js
License: MIT License
React Native + i18n.js
License: MIT License
Hi , I want to localize some images and other documents , is this handled here? or any leads how it can be done?
I would like to use this library for our project, but since the installation instructions are very much geared towards ios and android I was wondering if there is an easy way to get this library working on UWP, and if not are you planning on supporting react-native-windows any time soon?
When i set my device to e.g. French locale, the lib still yields the following (attached device-info library for comparison):
import ReactNativeI18N from 'react-native-i18n'
import DeviceInfo from 'react-native-device-info'
console.log(DeviceInfo.getDeviceLocale()) // fr-US
console.log(ReactNativeI18N.currentLocale()) // en
console.log(ReactNativeI18N.locale) // empty
"react-native": "0.41.2",
"react-native-i18n": "^1.0.0",
It's a feature request but I think it's quite important to be able to access resources that are translated in Localizable.strings already.
Should be something like if resource is missing in JavaScript then look for it Localizable.strings
It will show missing 'en-US' translations.
My code:
var I18n = require('react-native-i18n');
// render component here
I18n.fallbacks = true;
I18n.translations = {
en: {
appName: 'Chat',
},
zh: {
appName: '聊天室',
},
};
Is this gem no longer maintained? If so, a message in the README would be helpful 👍
System:
OS: Ubuntu 16.0.4
Node: v6.4.0
NPM: v3.10.3
react-native-cli: 2.0.1
react-native: 0.40.0
On start it immediately crashes with this error.
Package Error:
ERROR watch /home/user/Concise/react-native-app/node_modules/react-native-i18n/android/build/intermediates/bundles/release/aapt ENOSPC
{"code":"ENOSPC","errno":"ENOSPC","syscall":"watch /home/user/Concise/react-native-app/node_modules/react-native-i18n/android/build/intermediates/bundles/release/aapt","filename":"/home/user/Concise/react-native-app/node_modules/react-native-i18n/android/build/intermediates/bundles/release/aapt"}
Error: watch /home/user/Concise/react-native-app/node_modules/react-native-i18n/android/build/intermediates/bundles/release/aapt ENOSPC
at exports._errnoException (util.js:1026:11)
at FSWatcher.start (fs.js:1429:19)
at Object.fs.watch (fs.js:1456:11)
at NodeWatcher.watchdir (/home/user/Concise/react-native-app/node_modules/sane/src/node_watcher.js:144:20)
at Walker. (/home/user/Concise/react-native-app/node_modules/sane/src/node_watcher.js:353:12)
at emitTwo (events.js:106:13)
at Walker.emit (events.js:191:7)
at Walker.EventEmitter.emit (/home/user/Concise/react-native-app/node_modules/sc-domain/index.js:12:31)
at /home/user/Concise/react-native-app/node_modules/walker/lib/walker.js:69:16
at go$readdir$cb (/home/user/Concise/react-native-app/node_modules/graceful-fs/graceful-fs.js:149:14)
Stack Trace:
0 info it worked if it ends with ok
1 verbose cli [ '/home/user/.nvm/versions/node/v6.4.0/bin/node',
1 verbose cli '/home/user/.nvm/versions/node/v6.4.0/bin/npm',
1 verbose cli 'start' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle [email protected]prestart: [email protected]prestart: no script for prestart, continuing
6 silly lifecycle [email protected]
7 info lifecycle [email protected]start: [email protected]start: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]
9 verbose lifecycle [email protected]start: PATH: /home/user/.nvm/versions/node/v6.4.0/lib/node_modules/npm/bin/node-gyp-bin:/home/user/Concise/react-native-app/node_modules/.bin:/home/user/.nvm/versions/node/v6.4.0/bin:/home/user/.nvm/versions/node/v6.4.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/usr/local/bin:/home/user/Android/Sdk/tools:/home/user/Android/Sdk/platform-toolsstart: CWD: /home/user/Concise/react-native-app
10 verbose lifecycle [email protected]
11 silly lifecycle [email protected]start: Args: [ '-c',start: Returned: code: 11 signal: null
11 silly lifecycle 'node node_modules/react-native/local-cli/cli.js start' ]
12 silly lifecycle [email protected]
13 info lifecycle [email protected]~start: Failed to exec start script
14 verbose stack Error: [email protected] start: node node_modules/react-native/local-cli/cli.js start
14 verbose stack Exit status 11
14 verbose stack at EventEmitter. (/home/user/.nvm/versions/node/v6.4.0/lib/node_modules/npm/lib/utils/lifecycle.js:242:16)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at EventEmitter.emit (events.js:191:7)
14 verbose stack at ChildProcess. (/home/user/.nvm/versions/node/v6.4.0/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at ChildProcess.emit (events.js:191:7)
14 verbose stack at maybeClose (internal/child_process.js:852:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)
15 verbose pkgid [email protected]
16 verbose cwd /home/user/Concise/react-native-app
17 error Linux 4.4.0-59-generic
18 error argv "/home/user/.nvm/versions/node/v6.4.0/bin/node" "/home/user/.nvm/versions/node/v6.4.0/bin/npm" "start"
19 error node v6.4.0
20 error npm v3.10.3
21 error code ELIFECYCLE
22 error [email protected] start: node node_modules/react-native/local-cli/cli.js start
22 error Exit status 11
23 error Failed at the [email protected] start script 'node node_modules/react-native/local-cli/cli.js start'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the react-native-app package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error node node_modules/react-native/local-cli/cli.js start
23 error You can get information on how to open an issue for this project with:
23 error npm bugs react-native-app
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls react-native-app
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]
Hi
I would like to have all my localization stuff inside a unique file that could be called by any component needing it.
So I would like to have something like this:
Localization.js file
var I18n = require('react-native-i18n');
// Enable fallbacks if you want `en-US` and `en-GB` to fallback to `en`
I18n.fallbacks = true;
I18n.translations = {
en: {
greeting: 'Hi!'
},
fr: {
greeting: 'Bonjour!'
}
}
Demo.js file
var Demo = React.createClass({
render: function() {
return (
<Text>{I18n.t('greeting')}</Text>
)
}
});
How can I achieve that?
Thanks
is there podfile support?
I am using this library and I am trying to include HTML
symbols in the strings to be translated. For instance, a string like I will display €
does not get converted to I will display €.
.
Any ideias how to handle this?
Thanks
I would like to define per-component localization, is it possible? Currently, defining I18n.translations
in two or more components is not working.
Hi,
I've got a problem: the module works fine in normal app, but when I'm trying to run it inside extension app (launched via "share" button inside mobile Safari), I see in Xcode console:
2016-03-02 10:41:12.134 [error][tid:com.facebook.React.JavaScript] undefined is not an object (evaluating 'RNI18n.locale')
2016-03-02 10:41:12.137 [fatal][tid:com.facebook.React.RCTExceptionsManagerQueue] Unhandled JS Exception: undefined is not an object (evaluating 'RNI18n.locale')
2016-03-02 10:41:12.314 [error][tid:com.facebook.React.JavaScript] Module AppRegistry is not a registered callable module.
2016-03-02 10:41:12.315 [fatal][tid:com.facebook.React.RCTExceptionsManagerQueue] Unhandled JS Exception: Module AppRegistry is not a registered callable module.
Any ideas how to fix it and make it work in extension app?
Hello,
I notices that tin the fnando/i18n-js doc there is an easy way to pluralize the words by doing
Car: {
counting:{
one: 'Car',
other: 'Cars'
}}
and call it with i18n.t('Car', {count: 10}}
which should here return Cars
When I define my translations like that I have an error saying that my key, value translation schema is wrong, and that I can't define an object of translations.
So I'm probably not defining my translations schema as I should, and I can't find any example with a JSON formatted translation file. Any idea ?
Hello there,
do you have any plan on updating this repo? Is this project still alive? 🙍
Steps to produce:
Run the application
Put the app in the background, change the language.
Go back to the application.
Notice that localization is still the old one.
is there any solution except setting Locale at runtime ?
First of all thanks for the effort in creating and maintaining this module, it works like a charm.
But, there's something crucial (imo) I'm missing and that is a function or some way to let the user set the language to their choice (given the supported languages the app would provide).
(I tried requiring the new translations in 'i18n.translations = ....' but it only works for some of the screens.. I believe this is because the screens (and their translations) have to be re-rendered?)
Is this something that could be added or is it not feasible?
So basically I have it translated if I am working inside the React Component, but this will give me missing translation
warning
import I18n from 'react-native-i18n'
const PICKER_OPTIONS = {
title: I18n.t('avatar_title'),
}
export default PICKER_OPTIONS
Trying to use this
<Text>
{I18n.t('login_condition', {
appName: <Text style={{color: 'blue'}} onPress={() => Linking.openURL('http://google.com')}>Google</Text>
})}
</Text>
UNMET PEER DEPENDENCY react-native@>=0.4.0 <1.0.0
notsup Not compatible with your operating system or architecture: [email protected]
[email protected] requires a peer of react-native@>=0.4.0 <1.0.0 but none was installed.
I'm getting a [missing "ja-US.help" translation]
as of late.
I have the following console.log
-ing from the lib:
{
defaultLocale: "en",
locale: "ja-US",
fallbacks: true,
translations: {
en: {
help: "Help"
},
ja: {
help: "ヘルプ"
}
}
// ... etc.
}
RNI18n.xcodeproj and libRNI18n.a are a part of the iOS project.
Has the behavior changed with the fallbacks?
I recall in previous installs I would be defaulting to ja
if my device was ja-US
.
Hi, thanks for this awesome lib!
Is it possible to manually set locale?
For example: user's phone locale is en-US, but user has an option to switch language in the app settings -- how can I manually set a different locale for this plugin?
Please can you update to new react-native version?
https://github.com/facebook/react-native/releases/tag/v0.40.0
Hey there,
i am not sure if I use the plugin in the correct architecture.
In my index.ios.js I call a component which includes the
The Navigator calls another component (a login screen).
The i18n.t functions says ['missing en-US … translation']. (in the login component)
If I console.log() the I18n Object I can find every translations in the translations object.
What goes wrong? Is there a function to re-init?
Does this plugin work on Windows devices? I see there is a windows folder with source code in it. I installed this plugin and tried to use it on my Windows desktop. I manually linked this plugin to my project. However, my project does not even build after the plugin is added. This is the build error:
cannot convert from 'ReactNative.Modules.RNI18n.ReactNativeI18n' to 'ReactNative.Modules.Core.IReactPackage'.
Looks like ReactNativeI18n does not implement the IReactPackage interface.
Any help is appreciated.
Hey, i am just testing this module, but i always get false return values on ios.
this call: I18n.currentLocale();
always returns "en" even though the app is running on a german iphone, with german language and used in germany.
What rules are connected to currentLocale() ?
I already added german xliff in xcode , but no changes…
Can somebody help me on that?
Android seems to be working properly
Many Thanks!
running version 0.1.1
I notice that if I have periods in property name like
"Downloading...": "Downloading",
The translation doesn't work and it displays "missing "en.Downloading..."
Any idea? thanks
var I18n = require('react-native-i18n')
import Translations from '../lib/Translations'
I18n.translations = Translations
I18n.fallbacks = true //added to make sure default is used and things start to work
I18n.t('Profile.username') results in [missing "en.Profile.username" translation]
this works
I18n.translations.en.Profile.username
Seems that I18n.locale is not set, I18n.fallbacks is false so I18n.defaultLocale which is "en" is not being added to the locales list.
Is I18n.locale supposed to be set manually?
In the same way that the geolocation API for react-native is exposed through navigator.geolocation
, it would be great to have this exposed as navigator.language
and possibly even upstreamed. Thoughts?
I just found out if you immediately renders a component that needs i18n. The translations will be marked as not found :(
RN: 0.39.0
i18n: 0.1.1
iOS 10.1 running on simulator iPhone 6.
Here's my excerpt of code:
import React, { Component } from 'react';
import ReactNativeI18n from 'react-native-i18n';
const deviceLocale = ReactNativeI18n.locale;
console.log('LOCALE: ' + deviceLocale);
And the sample greeting in the README.
The Android simulator is returning the French translation: "Bonjour!" and logs "LOCALE: fr-CA", while iOS fallsback to English, and the console log returns "LOCALE: ". I can manually set the locale and it translates properly, but it's not reading the locale automatically from the device.
When i use [email protected]
, and execute npm install
,i encountered :
npm WARN EPEERINVALID [email protected] requires a peer of react-native@>=0.4.0 <1.0.0 but none was installed.
because in react-native-i18n 's package.json ,you defined
"peerDependencies": {
"react-native": ">=0.4.0 <1.0.0"
}
can you fix it ?
Thanks a lot~
How can I set a default language when missing translation?
Example:
I18n.translations = {
en: {
choose: 'Choose'
},
es: {
choose: 'seleccionar!'
}
}
If I run this code on device with pt-BR language, It will cause an error saying that the language is missing pt-BR
Hi - I'm seeing this compile warning:
ld: warning: object file (/Users/nickpomfret/Library/Developer/Xcode/DerivedData/pomochat-cvkhcsdfxgmgokbegzcqhdxmcngh/Build/Products/Debug-iphonesimulator/libRNI18n.a(RNI18n.o)) was built for newer iOS version (8.0) than being linked (7.0)
Would it be possible to release it linking to IOS 7?
Hi.
I was curious if anyone imported a yml file and set the translations to this. I am trying to reuse a yml file from a web react app for use in react native app. Anyone have done this and can provide some info to accomplish this?
Thanks.
Hi, thanks for the great lib.
One of my texts in the app is:
{
en: {
termsOfUseText: "By click Submit you agree to Terms of Use and Privacy Policy"
}
}
I need to have Terms of Service
and Privacy Policy
Links that open WebView.
I don't want to separate it into separate keys because it harder to translate and in some language the order of words can change so I need to allow the translators to translate it as a whole line.
Any suggestions on how to implement that?
Thanks,
Ran.
Hi,
The locale in iOS is comprised of both the language and the device's locale. For example: "en_US".
Is there a way to ignore the "_US" part? Many people use a language different from the locale.
Is there a way to do this?
Thanks.
First off, I'm really enjoying this lib.
I'm running into an issue where I have two translation sets.
One belongs to my main app, and the other belongs to a package containing lots of reusable components with translated text in them.
They both import react-native-i18n
, then set translations and fallbacks=true
.
The problem seems to be that one of them is overriding the other and ignoring the values.
I'm ok with 'dog' in main app being 'dog', but overrode in the package to 'woof' or something if I specify, but right now the translations I set in the main app are completely ignored.
there is an empty locale return from
import ReactNativeI18n from 'react-native-i18n'
const deviceLocale = ReactNativeI18n.locale
os: macosx
core: 0.41.1
version: 1.0.0
Is there a way to hot reload translations?
I follow readme to use this plugin,but show error:
Could not find method compile() for arguments [project ':react-native-i18n'] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@c43dfcc.
react native version:0.22.2
I get the following error when unit testing a component that uses I18n:
node_modules/react-native-i18n/index.js:7
I18n.locale = RNI18n.locale.replace(/_/, '-');
^
TypeError: Cannot read property 'locale' of undefined
Is there a way to set a locale before unit testing.
Thanks!
Hi
I wonder if I am doing something wrong or if this is a bug.
When I change a translation string like in english.json
I change
"welcome": "Welcome",
to
"welcome": "Welcomeeee",
The app crashes with the following error:
Unexpected token :handleException @ C:\git\awhina\node_modules\react-native\Libraries\Core\ExceptionsManager.js:63handleError @ C:\git\awhina\node_modules\react-native\Libraries\Core\InitializeCore.js:114reportFatalError @ C:\git\awhina\node_modules\react-native\packager\react-packager\src\Resolver\polyfills\error-guard.…:44guard @ C:\git\awhina\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:48callFunctionReturnFlushedQueue @ C:\git\awhina\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:107message @ index.js:73
which might originate from here
message @ RNDebuggerWorker.js:123
...
returnValue = __fbBatchedBridge[object.method].apply(null, object.arguments);
...
This makes it a very unpleasant development experience.
Any idea how to fix this?
Hello,
It is possible to upgrade the compatibility with react-native 0.6 and 0.7 ?
Best,
My iPhone is configured to use en-US language but the region is Russia.
So here is what I get from objective-C:
[[NSBundle mainBundle] preferredLocalizations]; //= "en"
[NSLocale preferredLanguages]; //= en-US
NSLocalizedString(@"newPhrasebooksAvailable", nil); //returns an English-localized string from Localizable.strings
And this is what I get in JavaScript:
console.log(require('react-native').NativeModules.RNI18n.locale, I18n.locale); // output is 'ru_RU', 'ru-RU'
I'm not sure when it started but maybe this wasn't the issue before iOS 9.3. Anyway, it is now.
run jest test: TypeError: _reactNativeI18n2.default.t is not a function
"react-native": "0.39.2"
Hi
Using react-native-i18n in an React-Native Android app breaks it with the following error:
undefined is not an object (evaluating 'RNI18n.locale')
Since Ract-Native Android is now open-sourced and this is currently the defacto i18n component for react-native it would be great if you guys could fix this soon.
Thank you
Bernd
Although the package.json specified the license as MIT but there is no license file in the repo and I am not able to get the exact license text to ship with my app. Mainly, there are some placeholders that need to be filled in the license such as the year and the copyright holders which I can't fill myself. It would be great if you could add a LICENSE file to the repo.
are there any plans to support formatting feature like them
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.