Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-redux-translate

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-redux-translate

easy internationalization with react-redux

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

#react-redux-translate

Features

*Easy Internationalization for your react app

Installing

$ npm i --save react-redux-translate

Usage

Create instance

Create Translate instance in any place within the src directory.

import React from 'react';
import { connect } from 'react-redux';
import translate from 'react-redux-translate';

let T = translate('language', 'languageKeyInState', 'pathToI18nDirectoryFromProjectRoot');

export default T = connect(state => ({languageKeyInState: state.languageKeyInState}))(T);

If pure string needed to insert as the function argument

export const funcT = ({keys, insertions = []}) => <T keys={keys} insertions={insertions} />;

Keep in mind

1. 'language' must correspond name of the JSON file in i18n directory.

2. 'languageKeyInState' must correspond name language key in the redux state.

3.  'pathToI18nDirectoryProjectRoot' path form root of the project (the same level where is the node-modules directory) to 'i18n' directory.

Instance usage

Import T component where is needed

import T from 'pathToYourTranslateInstance';

Insert as React Component with required properties

<div><T keys="home.title" /><div>

'Keys' property can be either string with dot delimiter or array of string.

If case you have some words in the text, which you will not translate you could use insertions property and add placeholders ${} to the source string.

The insertions must be an array of string.

For example, if you have en-EN JSON file with property

  `"home": {"event": "Meet ${} and ${} at GitHub" }` 

and you set follow params to the <T/>component

  `<div><T keys="home.event" insertions={['Mary', 'John']} /><div>`

you will get "Meet Mary and John at GitHub" string inside div.

Of cause you can add any HTML tags with class attribute:

"home": "<a href='some-link' class="this-string-will-blue-as-link">Some text <i>some text with italic style</i></span>" 

You don't need to do any special to insert HTML tags into translation string!

Keywords

FAQs

Package last updated on 17 Dec 2019

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