Skip to content
Alex Fomushkin edited this page Aug 18, 2018 · 10 revisions

Welcome to the ReactNativeLocalization wiki!

Testing your localization

Add code to project based on instructions in README. Then drop the following into your App to set the language used by the app at runtime (in this case we're using German):

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

The above trick was pulled from Change the application locale on the fly with iOS internationalization. For a listing of locales please refer to and help maintain the following list:

Unit testing with Jest

Add jest-setup.js to your root project directory with the following code:

import { NativeModules } from 'react-native'
NativeModules.ReactLocalization = {
  language: 'en',
}

in your package.json add:

  "jest": {
    "preset": "react-native",
    ...
    "setupFiles": [
      "./jest-setup.js"
    ]
  }

Configuring Xcode to use localizations

In order to list your app as supporting multiple languages Xcode must be made aware of it. Trick Xcode into believing your app is localized by creating a Localizable.strings file and adding localizations to your project based as described on StackOverflow. These files can be blank, though it's a good idea to leave a comment as to why or figure out a way to use the strings file with this native module.

Use country and variant in locale identifiers

To get more specific than just language while translating you can leverage country and variant parts of the locale code by using a hyphenated string literal as the key values while instantiating the LocalizedStrings object with translated text, e.g.

let localizedStatus = new LocalizedStrings({
  de: {
    playing: "Jetzt spielt lizenzfreie Musik!",
    paused: "Tippe oben um weiter zu hören.",
    stopped: "Tippe oben um rein zu hören.",
    buffering: "Lädt... Bitte warten.",
    error: "Tippe oben lange um neu zu starten.",
    disconnected: "Verbinde dich mit dem Internet um zu hören."
  },
  "zh-Hans": {
    playing: "现正播放无广告时段!",
    paused: "按上面来继续收听。",
    stopped: "按上面来切换电台。",
    buffering: "正在缓冲...请稍候。",
    error: "长按上面来重新开始播放。",
    disconnected: "收听电台需要连接到因特网。"
  }
});

While you're localizing

Consider setting-up automated screenshots to take snaps of your app in various languages for the App Store. Snapshot is just one option for doing so.