Socket
Book a DemoInstallSign in
Socket

@4react/localize

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@4react/localize

React-to-use **i18n** configuration and components for React Applications.

2020.1.2
latest
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

@4react / localize

React-to-use i18n configuration and components for React Applications.

NOTE

The purpose of this package is to provide a simple and standard solution for the largest amount of projects.

It is mainly based on react-i18next. Please consider to support their work.

Usage

Import dependency

npm i @4react/localize

Init i18n

Initialize i18n with initI18n, optionally specifying languages and namespaces.

import { initI18n } from '@4react/localize'

initI18n(
  ['en', 'it', 'es'], // languages
  ['common', 'profile'] // namespaces
)

Provide localization

Use the Localization component to provide translations over the application.

import { Localization } from '@4react/localize'

const App = () => (
  <Localization>
    // content
  </Localization>
)

Translate labels

Use the Localized component to translate labels.

import { Localized } from '@4react/localize'

const CustomComponent = () => (
  <Localized label="awesome" />
)

...and use any kind of filler (also components)

const CustomComponent = () => (
  <Localized
    label="my-fillable-label"
    fillers={{
      name: 'Matteo',
      age: 28,
      component: <MyCustomFiller />
    }}
  />
)

// Hi, I'm {{name}} and I'm {{age}} years old. Look at this {{component}}!

Translations are rendered as simple text with no additional style or structure.

Documentation

initI18n()

ParameterTypeDefaultDescription
languagesstring[]['en'][optional] Set of supported languages. The first element is considered as fallback.
namespacesstring[]['translations'][optional] Set of supported namespaces.

<Localization>

PropsTypeDefaultDescription
defaultNSstring'translations'[optional] Specify the default namespace.

<Localized>

PropsTypeDefaultDescription
labelstring-Label to localize.
nsstring-[optional] Namespace to witch the label belongs. In case of no namespace specified, the defaultNS of the Localization component is used.
fillersobject-[optional] Maps of elements to fills placeholders in label. Fillers could be of type string, number or components.
langstring-[optional] Language to override the current selected one.

FAQs

Package last updated on 02 Apr 2020

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.