GithubHelp home page GithubHelp logo

Comments (2)

kenchangh avatar kenchangh commented on June 13, 2024 1

Moved on from this library to use https://github.com/stefalda/ReactNativeLocalization. It provides a better API with less crazy internal state. You can easily define it by component and also globally by exporting

from react-native-i18n.

Epotignano avatar Epotignano commented on June 13, 2024

I've made a service for do this task.


var I18n = require('react-native-i18n');
I18n.locale = 'ja-JP';

class I18nService {
constructor(){
this.I18n = I18n;
// intialization
this.I18n.translations = I18n.translations;

    //Set the default language of the app if there are no
    // locales for charge!
    this.I18n.missingTranslation = (arg) => {
        return this.I18n.translations['ja-JP'][arg]
    };

}

set(langKey, translationsObj) {
    if(!this.I18n.translations[langKey])  this.I18n.translations[langKey] = {};
    var _keys = Object.keys(translationsObj);
    _keys.map((key) => {
        this.I18n.translations[langKey][key] = translationsObj[key]
    });
};

getTranslations () {


    return this.I18n
};

}

var serv = new I18nService();

module.exports = serv;


Usage:

var I18nService = require('../i18n'); //the folder were you have the service

I18nService.set('ja-JP', {
'login' : 'ログイン',
'loginWithFacebook': 'Facebookで始める',
'register': "登録 "
}
);

var I18n = I18nService.getTranslations();

and when you call: I18n.t('login') // "ログイン'"

from react-native-i18n.

Related Issues (20)

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.