New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

internationalization-js

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

internationalization-js

Lightweight i18n for your javascript applications

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

Internationalization.js

Add to your project

NPM

npm install internationalization-js

Yarn

yarn add internationalization-js

Add translation files to your project

I prefer to make one file per language and then combine them in one js file, but you could also put all translations in one big file or use seperate files and import them seperatly.

export default {
  en: {
    welcome: 'Welcome to my cool React app',
    log_in: 'Log in',
    log_out: 'Log out',
    account: 'Account',
  }
};
export default {
  nl: {
    welcome: 'Welkom bij mijn coole React app',
    log_in: 'Log in',
    log_out: 'Log out',
    account: 'Account',
  }
};
import nl from './nl';
import en from './en';

export default {
  nl,
  en,
};

Setup in your project

Now it's time to import the translations and import them into the plugin.

import I from 'internationalization-js';
import Translations from './localisation';

...
L.setStringsForLanguages(Translations); // This function adds the translation strings into our plugin
L.setDefaultLanguage('nl', true); // You can use whatever language code styling you prefer, as long as you keep the key in the language file the same

Let's translate!

import I from 'internationalization-js';
const localizedWelcome = I.translate('welcome'); // returns => 'Welkom bij mijn coole React app'

Or for example in your react app

import I from 'internationalization-js';

...
render () {
    return (
        <View>
            <Text>{I.translate('welcome')}</Text>
        </View>
    );
}

Available methods

MethodDescriptionParametersReturns
setStringsForLanguageSet the strings from the strings object for a given languagelanguage: string strings: object
setStringsForLanguagesLoops over object of language strings objects and set them as string for the given languagelanguages: Object
setDefaultLanguageSet the default language to be used when no language has been set yetlanguage: string isCurrentLanguage: boolean
getLanguageGet the currently selected language Or the default language when no language has been set yetstring: current or default language
getAvailableLanguagesGet all available languagesarray: array of language codes (string)
getAllStringsForCurrentLanguageGet all available strings (with translation) for current languageobject: all available strings
translateGet a translation for given key Returns key when no translation could be foundkey: stringstring: translation or key

License

MIT

Keywords

FAQs

Package last updated on 03 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc