
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
translated-react
Advanced tools
Component for managing and using simple translations in React.js. Easily implement i18n with this dependency free internationalization library.
Component for managing and using simple translations in React.js. Easily implement i18n with this dependency free internationalization library, with a minimum footprint of 1,91 KB gzipped.
npm install translated-react
Or:
yarn add translated-react
import React from 'react'
import ReactDOM from 'react-dom'
import TranslatedProvider, { translated } from 'translated-react'
import PropTypes from 'prop-types'
const langTable = {
en: {
moreText: 'Some more text',
textForTesting: 'Some text for testing with {nWords} words'
},
es: {
moreText: 'Algo más de texto',
textForTesting: 'Algo de texto de prueba con {nWords} palabras'
}
}
const MyComponent = ({lookup: t}) => [t('textForTesting', { nWords: '8' }), t('moreText')]
MyComponent.propTypes = {
lookup: PropTypes.func.isRequired
}
const MyTranslatedComponent = translated(MyComponent)
const MyApp = () => (
<TranslatedProvider lang="es" defaultLang="en" langTable={langTable}>
<MyTranslatedComponent />
</TranslatedProvider>
)
ReactDOM.render(<MyApp />, document.getElementsByTagName('body')[0].appendChild(document.createElement('div')))
Currently only one TranslatedProvider component is supported; this means that, if you use two TranslatedProvider components only the last created one will have effect in setting the language, default language and translations table.
You can change the current language with the exported function setLang(newLang)
. This will trigger rerendering of the TranslatedProvider component and its children with the new language (if it's different from the current one).
Texts without vars are cached.
npm test
Or:
yarn test
translated-react is available under MIT. See LICENSE for more details.
FAQs
Component for managing and using simple translations in React.js. Easily implement i18n with this dependency free internationalization library.
The npm package translated-react receives a total of 0 weekly downloads. As such, translated-react popularity was classified as not popular.
We found that translated-react demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.