Coder Social home page Coder Social logo

reactnativelocalization's People

Contributors

alphasp avatar cbrevik avatar dependabot[bot] avatar esilverberg avatar fbacker avatar filiphorvei avatar hyochan avatar jevonj avatar jirikuba avatar kyle-ssg avatar lfkwtz avatar lucasbento avatar markmadlangbayan avatar mklb avatar monsjovis avatar neilco avatar nesvold avatar paalex avatar phogel avatar ratson avatar robertbiehl avatar rorycombe avatar seanrogs avatar stefalda avatar sudo-suhas avatar svbutko avatar twairball avatar william-normann avatar winkelsdorf avatar yuvalrakavy 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

reactnativelocalization's Issues

Compatibility with react-native 0.40

Since December version
react-native team introduce a breaking change that affects third party modules.
I'm quoting here the message from the release notes. It would be great if you could upgrade the package 🎉 Thanks !

iOS native headers moved

This change affects all native modules and application code on iOS that refer to react native .h files
After e1577df, Native code on iOS must refer to headers out of the react namespace. Previously the following would work:

#import "RCTUtils.h"

But now all headers have been moved:

#import <React/RCTUtils.h>

This means that all iOS native libraries need a major version bump for RN 0.40. We attempt to minimize changes of this magnitude, and we apologize for any inconvenience caused.

EDIT : Consider also using the macro suggested in the following article, to support 0.40 and keep compatibility with previous versions.
https://medium.com/@thisismissem/how-to-upgrade-react-native-modules-in-a-backwards-compatible-manner-a5b5c48d590c#.vh7nbtd26

[question] taking screenshots with snapshot

Hi,

thanks for publishing the lib.

I was trying to take screenshots using snapshot but the app keeps using the default locale.
And if I manually change the device language, everything works just fine.

Do you have any hints on how to make it work with snapshot?

Thanks,
Pavel

Return string item from default language if item in desired translation is missing

Let's have this code:

import LocalizedStrings from 'react-native-localization';
let strings = new LocalizedStrings({
  en:{
    how:"How do you want your egg today?",
    boiledEgg:"Boiled egg",
    softBoiledEgg:"Soft-boiled egg",
    choice:"How to choose the egg"
  },
  it: {
    how:"Come vuoi il tuo uovo oggi?",
    boiledEgg:"Uovo sodo",
    softBoiledEgg:"Uovo alla coque",
   // notice missing 'choice'
  }
});

If I use IT language and pick strings.choice, then now I get undefined object. It should return choice string from en (which is first language - thus default). This is also default behavior in Android native projects.

Please fix this.

Should there be a default value returned when the key does not exist ?

Hello,

Coming from the iOS world, when a localized string does not exist, we get the key itself as default value. I was wondering if this kind of feature would be considered/accepted in the ReactNativeLocalization library ?

Basically, in #23 example,

import LocalizedStrings from 'react-native-localization';
let strings = new LocalizedStrings({
  en:{
    how:"How do you want your egg today?",
    boiledEgg:"Boiled egg",
    softBoiledEgg:"Soft-boiled egg",
    // choice:"How to choose the egg" remove choice here as well
  },
  it: {
    how:"Come vuoi il tuo uovo oggi?",
    boiledEgg:"Uovo sodo",
    softBoiledEgg:"Uovo alla coque",
   // notice missing 'choice'
  }
});

strings.choice would print choice because it could not have been found.

Language matching doesn't account for scripts

The language matching function just cuts straight to the language tag and ignores any other relevant identifying tags. For example, zh-Hans-CN goes straight to zh instead of to zh-Hans.

Pull request here: #18

ios error in v.0.1.24

v0.1.22 works fine but v0.1.24 get this error:
ReactLocalization.m:37:63
"property 'languageCode' not found on object of type 'NSLocale *'

A WeakMap cannot have a non-object key

Hello,

When the Live reload and Hot reloading are enabled on my virtual device I get the error A WeakMap cannot have a non-object key.

This error occur when I save a file where I've imported and used my Translation service or when I save my translation json.

Here is the error screen:
screen shot 2016-09-08 at 17 52 58

The File with translations:

import LocalizedStrings from 'react-native-localization';

let Translate = new LocalizedStrings({
  en:{
    // Errors
    errorNetworkRequest: 'An error occurred while making a network request',
   ...
  },
  it: {
    ...
  }
});

export default Translate;

Then I import my translation file with import Translate from 'MyProject/src/lib/utils/Translate'; or user it from props

Thanks in advance

Installation not possible.

After going trhough the setps i get error:

* What went wrong:
A problem occurred configuring project ':app'.
> A problem occurred configuring project ':react-native-localization'.
   > Could not resolve all dependencies for configuration ':react-native-localization:_debugCompile'.
      > Could not find com.android.support:appcompat-v7:22.2.0.
        Searched in the following locations:
            file:/Users/karliscudars/.m2/repository/com/android/support/appcompat-v7/22.2.0/appcompat-v7-22.2.0.pom
            file:/Users/karliscudars/.m2/repository/com/android/support/appcompat-v7/22.2.0/appcompat-v7-22.2.0.jar
            https://jcenter.bintray.com/com/android/support/appcompat-v7/22.2.0/appcompat-v7-22.2.0.pom
            https://jcenter.bintray.com/com/android/support/appcompat-v7/22.2.0/appcompat-v7-22.2.0.jar
            file:/Users/karliscudars/Projects/Youbip/szymon/szymon-mobile/node_modules/react-native/android/com/android/support/appcompat-v7/22.2.0/appcompat-v7-22.2.0.pom
            file:/Users/karliscudars/Projects/Youbip/szymon/szymon-mobile/node_modules/react-native/android/com/android/support/appcompat-v7/22.2.0/appcompat-v7-22.2.0.jar
        Required by:
            StarterKit:react-native-localization:unspecified > com.facebook.react:react-native:0.11.0
      > Could not find com.android.support:support-v4:21.0.3.
        Searched in the following locations:
            file:/Users/karliscudars/.m2/repository/com/android/support/support-v4/21.0.3/support-v4-21.0.3.pom
            file:/Users/karliscudars/.m2/repository/com/android/support/support-v4/21.0.3/support-v4-21.0.3.jar
            https://jcenter.bintray.com/com/android/support/support-v4/21.0.3/support-v4-21.0.3.pom
            https://jcenter.bintray.com/com/android/support/support-v4/21.0.3/support-v4-21.0.3.jar
            file:/Users/karliscudars/Projects/Youbip/szymon/szymon-mobile/node_modules/react-native/android/com/android/support/support-v4/21.0.3/support-v4-21.0.3.pom
            file:/Users/karliscudars/Projects/Youbip/szymon/szymon-mobile/node_modules/react-native/android/com/android/support/support-v4/21.0.3/support-v4-21.0.3.jar
        Required by:
            StarterKit:react-native-localization:unspecified > com.facebook.react:react-native:0.11.0 > com.facebook.fresco:fresco:0.6.1 > com.facebook.fresco:drawee:0.6.1
            StarterKit:react-native-localization:unspecified > com.facebook.react:react-native:0.11.0 > com.facebook.fresco:fresco:0.6.1 > com.facebook.fresco:imagepipeline:0.6.1

On other developers computer it works. I tryed broth win snake case and camel case.

How to resolve this, thanks!

Set General Language!

Hi,

Is there a way to set all the LocalizedStrings created to a specific language without going to each of them and doing this strings.setLanguage('it')?

Thank You!

<Android> Changing localization does not work until app is restarted

Happens only in Android as iOS kills any application when language is changed.
Steps to reproduce:

  1. Run the application
  2. Put the app in the background, change the language.
  3. Go back to the application.
  4. Notice that localization is still the old one, even after you re-render the page by detecting app resume using AppState.

I have noticed that in your LocalizedStrings.js file you retrieve the language using
require('react-native').NativeModules.ReactLocalization.language.replace(/_/g,'-')
So I tried putting this inside the constructor instead and ensured new instance of LocalizedStrings is used everytime my application resumes from paused state.
However, this will still give me the old localized string, indicating that localization in the native side is cached.
I also tried to use require('react-native').NativeModules.ReactLocalization.getLanguage((language)=> { })

However language is null.

Correct localization is retrieved after app is restarted, which is not ideal.

Let me know if there is a workaround for this.

Thanks!

Localization not working for en-US/UK/etc.

When first integrating your library at version 0.1.22 in October, localization worked flawlessly (eg en-US, en-UK, etc). Thank you for that!

But for some reason, at some time in the past month, it no longer is setting the appropriate language for localization purposes, it simply seems to set the language based on the lowest-indexed en- key in the localizedStrings dictionary which is provided on initialization.

For instance, the following works properly for it, but always sets the language to en even when the application language is English (US).

import LocalizedStrings from 'react-native-localization'

const localizedStrings = new LocalizedStrings({
    'en': {
        bookmarkButtonActive: 'Favourited',
        bookmarkButtonInactive: 'Favourite',
    },
    'en-US': {
        bookmarkButtonActive: 'Favorited',
        bookmarkButtonInactive: 'Favorite',
    },
    'it': {
        bookmarkButtonActive: 'Italianoed',
        bookmarkButtonInactive: 'Italiano',
    },
})

export default localizedStrings

I have tried upgrading to the latest 0.1.25, but still seeing the same issue. It does, however, work properly for internationalization... perhaps something broke in one of your downstream localization deps? Haven't had a chance to debug the source code yet.

Application Scheme

image

Do you cache?

!This is not an issue.

Does this lib have caching implemented? Native or Javascript? So it's a smooth experience across the app once the app opens and while you're switching between Scenes/Screens/Activities.
If not, can you drop some info on the performance?

Add support in test

Hello! I am trying to test some of my js classes dependent on LocalizedStrings and I fail to do so.
I got the following output:

TypeError: Cannot read property 'language' of undefined

  at Object.<anonymous> (node_modules/react-native-localization/LocalizedStrings.js:21:35)
  at Object.<anonymous> (js/DemoTest.js:1:214)
  at Object.<anonymous> (__tests__/model/loctest.js:1:104)

Here is the DemoTest.js:

`import LocalizedStrings from 'react-native-localization';

const i18n = new LocalizedStrings({
de: {
active: 'active',
}
});

export const checkMyLocalization = () => {
console.log('Active = ' + i18n.de.active);
};`

And loctest.js:

`
import { checkMyLocalization } from '../../js/DemoTest';

test('Loc result', () => {
checkMyLocalization();
});
`

What am I supposed to do to make the test work?

Problem to register module on MainActivity.java - The code has changed

Hi!

I am trying to install your ReactNativeLocalization library on my project and I had success to install it to iOS. But I don´t know how can I install it on Android. When I was trying to modify my MainActivity.java I saw my file is different than yours.

This is my MainActivity.java:

package com.booksearch;

import com.facebook.react.ReactActivity;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;

import java.util.Arrays;
import java.util.List;

public class MainActivity extends ReactActivity {

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "BookSearch";
    }

    /**
     * Returns whether dev mode should be enabled.
     * This enables e.g. the dev menu.
     */
    @Override
    protected boolean getUseDeveloperSupport() {
        return BuildConfig.DEBUG;
    }

   /**
   * A list of packages used by the app. If the app uses additional views
   * or modules besides the default ones, add more packages here.
   */
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new MainReactPackage());
    }
}

I am using React Native 0.18

Set Language at runtime

Hi there :)
Is it possible to set the language in one screen for the hole application? I have the problem that I manually force set the language in a settings screen with setLanguage(), but this only applies to the current screen. So when I change to another screen, the language falls back to the default language. Thank you for any help!

Android: New Install Has Issue

Steps taken:

1 . install react-native-localization
2. rnpm link react-native-localization
3. Compile android successful and installed to device.

Error:

undefined is not an object ( evaluating 'localization.language' )

LocalizedStrings.js: 17

loadModuleImplementation
require.js: 122

A label based object definition (instead of a langage based)

Currently the structure to create a LocalizedString object is the following:

langage: {
  label: 'value'
},
langage-2: {
  label: 'value'
}

But as a develop is more likely that i'll delete and edit labels instead of deleting/editing languages. To fix this inefficiency I'd recommend allowing devs to define LocalizedString using the following format:

label: {
  langage-1: 'value',
  langage-2: 'value'
}

string keys support

Hello, I don't know if it's done specially, but string keys are not supported. Wouldn't it be more logical to write:

Hello {title}, you have ${amount} on your balance

and then

strings.formatString(strings.foo, {title : 'Mr', amount: 10000000})

?

Something went wrong initialing the ReactLocalization module.

Hi, I created a React-Native project yesterday, and I just installed your library.

I ran the installation commands as specified:

npm install react-native-localization --save
react-native link

My application in the simulator now displays this error:
capture d ecran 2017-02-03 12 00 27

I killed the simulator, killed the terminal launched by react-native run-ios and reran `react-native run-ios`` but I still got the error.

Any help would be appreciated, thanks :)

The default language doesn't work

Our project is now using ReactNativeLocalization. It supports English (en) and Simplified Chinese (zh-Hans). When i changed the localization of my iPhone to Chinese, Traditional (Hang Kong) i found it doesn't display English nor Simplified Chinese.

After i carefully read LocalizedStrings.js i found _getBestMatchingLanguage didn't return the first item in props as it expected. In addition, in setLanguage:

var localizedStrings = this.props[language];

Should be this?

var localizedStrings = this.props[this.language];

or this ?

var localizedStrings = this.props[bestLanguage];

Make LocalizedStrings.js independent of 'react-native'

I'm finding a way to do localization in the same way across react-native and browser based react for better consistency.
It turns out that by simply replacing the lines in LocalizedStrings.js

var localization = require('react-native').NativeModules.ReactLocalization;
var interfaceLanguage = localization.language;

with

let interfaceLanguage = (navigator.language || navigator.userLanguage);

the class will work just fine in browser.

So as a suggestion, I think the class itself could be made as a platform independent library.
For 'react-native' and browser, provide a wrapper module to pass in the correct device locale automatically.
Then we can have the same way to do localization across all react apps.

The build in react native 0.40 is fail with the plugin installed

/Users/xxx/www/letsgout/public_html/test/node_modules/react-native-localization/ReactLocalization.m:39:67: error: property 'languageCode' not found on object of type 'NSLocale *'
return [NSString stringWithFormat:@"%@-%@", currentLocale.languageCode, currentLocale.countryCode];

Why?

How to update text in multiple languages

How can I update a key for all the languages, e.g.:

let strings = new LocalizedStrings({
  en:{
    city:"original city in en",
    area:"original area in en",
  },
  ar: {
    city:"original city in ar",  
    area:"original area in ar",
  }
});

Now, how to update a particular key, like city, in this.

Class ReactLocalization was not exported

Ran through your installation steps, all worked fine - added the 2 files to the project:
screenshot 2015-04-30 07 46 29

Note, I am getting this warning about RCT_EXPORT:
screenshot 2015-04-30 07 47 35

In my index.ios.js, I added:
var LocalizedStrings = require('./node_modules/react-native-localization/LocalizedStrings');

I run project through Xcode and get this:
screenshot 2015-04-30 07 48 48

On missing string, non-default language is used

I'm changing the app language during runtime (see screenshot).
Once in a certain language a string is missing the default language should be used ('en' in my case, which is the first localization in the Strings.js file).

Instead, the 'last used' language is being displayed..

See attached screenshots. In both the Italian language is currently selected but for one screenshot the Chinese language was used prior to the Italian.

After restarting the app it works as intended (for missing italian strings the 'en' strings are being used)

When app loads:
screenshot 2017-03-07 13 29 13

After changing to Chinese and changing back to Italian
screenshot 2017-03-07 13 28 52

Lint InvalidPackage error due to okio jar https://github.com/square/okio/issues/58

Hi,

Your library is really useful, thanks.
I'm an iOS dev but had to integrate your library with both platforms and hit a problem with Android:

On running ./gradlew lintDebug I get an error

Correctness InvalidPackage: Package not included in Android <path stuff>/okio-1.5.0.jar: Invalid package reference in library; not included in Android: java.nio.file. Referenced from okio.Okio.

Googling brought me to square/okio#58 and I used that and adapted the workaround at http://stackoverflow.com/a/25149514 to find a solution for me that didn't involve editing your library's code because we install it as a node module during our CI job.

To help others who might hit the same issue I suggest you add a lintOptions to your gradle file like https://github.com/oblador/react-native-vector-icons/blob/master/android/build.gradle#L23

Regards
Donnie

remove react-native from dependencies

In your package.json file you specifed react-native as dependency causing npm to install it twice. Having upgraded react-native to version 0.7.1 your dependency caused some serious issues making my application unexecutable. Having removed the dependency and deleted the react-native folder in your module's module folder solved this. So please remove this dependency, as your great project works fine without it too.

Issue regarding React native localization

Hey stelfalda!

I ran into an issue when using your repo. In my android emulator (im using Windows OS), when running the code, i get an error;
"undefined is not an object (evaluating 'localization.language').
Is this an exception that is familiar to you? The problem seems to be located in LocalizedStrings.js
I did the installation exactly as described.

image

image

Thanks in advance,

Martin

Formatting?

As far as I can tell, this library does not yet support formatting localization. Do plan to support that?

ie: format(strings['This is a {$1} dog'], strings['big']) should return This is a big dog for en, but Este es un perro grande for es

It's something I'm sorely missing in React Native so far, with the React integration of Format.js not yet supporting React Native.

Please clarify if ReactNativeLocalization is compatible with RN 25+

Hi,
I've glanced over the code. Looks like this package is compatible with new import logic introduced in RN25. Although the code looks OK opening this issue anyway so we can track this.

Starting in RN 25 React Native imports wil change:

Requiring React API from react-native will be deprecated:
https://github.com/facebook/react-native/releases/tag/v0.25.1

Instead of:

import React, { Component, View } from 'react-native';

you should now:

import React, { Component } from 'react';
import { View } from 'react-native';

You can also try this codemod built by the community to automatically rewrite all the imports.
https://github.com/sibeliusseraphini/codemod-RN24-to-RN25

IOS, cant run.

Trying to deploy on Iphone 6 now, i get nasty error:
screen shot 2016-12-22 at 19 12 36

I tryed to reinstall with rnpm install ... command, still no luck.

getLanguage() method do not work?

I want to get current language and i'm using: LocalizedStrings.getLanguage() but it show an error: undefined is not funtion?
How to fix it?
Thank.

Get a string in a specified language

It may be useful to grab a string but in a different language without having to call setLanguage twice.
e.g.

LocalizedStrings.getString(key, language);

undefined is not an object (evaluating 'localization.language')

Hi,

I use your package in my app.
I work on windows with a device and it works. I try to work on Mac with Genymotion and I have a problem : undefined is not an object (evaluating 'localization.language')
The problem is on LocalizedStrings.js line 17.

I think it doesn't find the language ?

Incorrect package name

Both ReactNativeLocalization and ReactNativeLocalizationPackage are declared in the incorrect package. It should be com.babisoft instead of com.babisoft.ReactNativeLocalization.

Nested Default/Fallbacks Keys Fail

Hi stefalda,

Thanks for this great app that we're currently using. Our team decided to move to a single translation file to leverage PhraseApp.

Because of that, we use namespacing to keep things organized. This works great until we look at fall back.

// Using 'it'; translations.homepage.mottoSmall; //fails
{
  en: {
    homepage: {
      mottoSmall: "THIS IS A MOTTO SMALL",
      mottoLarge: "LARGE MOTTO",
    },
  },
  it: {
    homepage: {
      mottoLarge: "LARGE MOTTO IT",
    }
  }
}

// Using 'it'; translations.homepage.mottoSmall; // works
{
  en: {
    homepage: {
      mottoSmall: "THIS IS A MOTTO SMALL",
      mottoLarge: "LARGE MOTTO",
    },
  },
}

Fallbacks only work at 1 level deep (I'm sure that's how it was designed).

Support country and variant in locale identifiers

iOS supports a number of locales. Most locale identifiers use _ to separate language, country and locale variant.

As of now I'm unable to use this module to specify anything beyond the language, which becomes problematic for localizations where different countries or localities speak the same language or variants of a language thereof.

Reproducing this issue:

Force the locale in Xcode:

  [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"zh_Hans", nil] forKey:@"AppleLanguages"];

Run the project and access the key:

let localizedStatus = new LocalizedStrings({
  en: {
    playing: "Now playing commercial-free!",
    paused: "Tap above to continue listening.",
    stopped: "Tap above to tune in.",
    buffering: "Buffering... Hang tight.",
    error: "Long-press above to restart stream.",
    disconnected: "Connect to the Internet to listen."
  },
  zh_Hans: {
    playing: "现正播放无广告时段!",
    paused: "按上面来继续收听。",
    stopped: "按上面来切换电台。",
    buffering: "正在缓冲...请稍候。",
    error: "长按上面来重新开始播放。",
    disconnected: "收听电台需要连接到因特网。"
  }
});

The actual result is English is output. The expected result is that Simplified Han is output. The same issue occurs for en_US and en_GB locales. As a workaround I've chopped off the country and variant parts of the locale identifier, leaving only the language, i.e. zh.

Is anyone using default dictionaries?

It just would be super useful to load a couple of dictionaries by default, so we have a default translation for single words. E.g:

LocalizedStrings.translate('monday') // returns 'lunes' if user locale is Spanish

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.