GithubHelp home page GithubHelp logo

alexanderzaytsev / react-native-i18n Goto Github PK

View Code? Open in Web Editor NEW
2.2K 2.2K 492.0 1.35 MB

React Native + i18n.js

License: MIT License

Objective-C 36.51% JavaScript 17.03% Java 30.31% Ruby 4.67% Starlark 11.47%

react-native-i18n's People

Contributors

alexanderzaytsev avatar c100k avatar chris-verclytte avatar cptfabulouso avatar crash-- avatar davepack avatar falsecz avatar flexsurfer avatar giantss avatar hakoniemi avatar hstaudacher avatar josephan avatar julienkode avatar lfkwtz avatar magrinj avatar maraujop avatar marudy avatar mmazzarolo avatar nabati avatar ndbroadbent avatar npomfret avatar ognen avatar olegserov avatar patoroco avatar pilot4u avatar rayronvictor avatar rborn avatar shic avatar tiagojdferreira avatar zoontek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-i18n's Issues

Hot reload

Is there a way to hot reload translations?

HTML symbols support

Hi @AlexanderZaytsev,

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

show error "A problem occurred evaluating root project"

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

cannot have any period in the property name

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

How to localise text with links?

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.

Missing Translation

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?

Manually set locale

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?

Support for react-native-windows

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?

Very weird results on iOS 9.3

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.

Change language

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?

incorrect locale name

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.

local locale

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

Missing translations

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.

localization stuff inside a unique file rather than in each component file

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

iOS Device Locale Returns Nothing

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.

Cannot run in extension app (iOS)

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?

Error when unit testing component

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!

Fallbacks don't work at all

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: '聊天室',
  },
};

Overriding happening when different translation sets present

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.

Changing a translation crashes the app during development!

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?

Lib does not identify device locale

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",

I18n breaks React-Native Android Apps

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

Missing translation outside of Component.

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

Can not use React Native 'RC' version

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~

Does this plugin work on Windows devices?

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.

I18n.currentLocale() on iOS always returns "en"

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!

Pluralize translations

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 ?

Here are screen shot of the error/warning
screen shot 2016-09-19 at 16 10 59

screen shot 2016-09-19 at 16 11 30

Add fallback to Localizable.strings

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

Is it possible to Interpolate objects?

Trying to use this

<Text>
          {I18n.t('login_condition', {
            appName: <Text style={{color: 'blue'}} onPress={() => Linking.openURL('http://google.com')}>Google</Text>
          })}
</Text>

Default language when missing translation

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

Add a license file to the repo

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.

again with missing translation

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?

Per-component localization

I would like to define per-component localization, is it possible? Currently, defining I18n.translations in two or more components is not working.

react-native link does not work correctly

On iOS all fine. If device lang is ru then I see this locale. On android it is empty string. I've tested it on virtual device and real device.

See next code:

import I18n from 'react-native-i18n';
console.log('I18n', I18n);

2016-10-19 16 32 08

Error watch - (react-native-i18n/android/build/intermediates)

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]
6 silly lifecycle [email protected]
prestart: no script for prestart, continuing
7 info lifecycle [email protected]start: [email protected]
8 verbose lifecycle [email protected]
start: unsafe-perm in lifecycle true
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-tools
10 verbose lifecycle [email protected]
start: CWD: /home/user/Concise/react-native-app
11 silly lifecycle [email protected]start: Args: [ '-c',
11 silly lifecycle 'node node_modules/react-native/local-cli/cli.js start' ]
12 silly lifecycle [email protected]
start: Returned: code: 11 signal: null
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 ]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.