Gathering detailed insights and metrics for i18next-lite
Gathering detailed insights and metrics for i18next-lite
Gathering detailed insights and metrics for i18next-lite
Gathering detailed insights and metrics for i18next-lite
Lightweight and super simple i18n/internationalization module for React.
npm install i18next-lite
Typescript
Module System
Node Version
NPM Version
69
Supply Chain
99.3
Quality
80.4
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Total Downloads
4,730
Last Day
1
Last Week
17
Last Month
67
Last Year
2,173
MIT License
4 Stars
43 Commits
1 Watchers
1 Branches
2 Contributors
Updated on Apr 16, 2025
Minified
Minified + Gzipped
Latest Version
2.2.26
Package Id
i18next-lite@2.2.26
Unpacked Size
13.93 kB
Size
4.67 kB
File Count
5
NPM Version
10.9.0
Node Version
22.11.0
Published on
Apr 16, 2025
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
88.9%
17
Compared to previous week
Last Month
-64.7%
67
Compared to previous month
Last Year
87.8%
2,173
Compared to previous year
3
i18next-lite is a lightweight and super simple i18n/internationalization module for React.
Why this? i18next-lite is specially designed only for React. Developed using modern React APIs. It is super simple, lightweight, fast and provides the necessary APIs to implement multiple language support.
1npm i i18next-lite
A minimal example of implementing 3 languages with the ability to switch languages. Try/run this live on CodeSandbox.
1import { createRoot } from 'react-dom/client' 2import { TranslationProvider, useTranslate, useTranslatorConfigurer } from 'i18next-lite' 3 4const translations = { 5 en: { 6 translation: { 7 hello: 'Hello {{userName}}', 8 good_morning: 'Good morning.', 9 how_are_you: 'How are you today?' 10 } 11 }, 12 es: { 13 translation: { 14 hello: 'Hola {{userName}}', 15 good_morning: 'Buenos dias.', 16 how_are_you: '¿Cómo estás hoy?' 17 } 18 }, 19 bn: { 20 translation: { 21 hello: 'হ্যালো {{userName}}', 22 good_morning: 'সুপ্রভাত.', 23 how_are_you: 'আপনি আজ কেমন আছেন?' 24 } 25 } 26} 27 28function App() { 29 return ( 30 <TranslationProvider translations={translations} defaultLanguage='en'> 31 <ExampleComponent /> 32 </TranslationProvider> 33 ) 34} 35 36function ExampleComponent() { 37 const translate = useTranslate() 38 return ( 39 <div> 40 <h2>{translate('hello', { userName: 'John Doe' })}</h2> 41 <h3> 42 {translate('good_morning')} 43 <br /> 44 {translate('how_are_you')} 45 </h3> 46 <ExampleLanguageSwitcher /> 47 </div> 48 ) 49} 50 51function ExampleLanguageSwitcher() { 52 const configure = useTranslatorConfigurer(); 53 return ( 54 <div> 55 <div>Select language:</div> 56 <div> 57 <span onClick={() => configure({ language: 'en' })}>English</span> | 58 <span onClick={() => configure({ language: 'es' })}>Spanish</span> | 59 <span onClick={() => configure({ language: 'bn' })}>Bangla</span> 60 </div> 61 </div> 62 ) 63} 64 65const rootElement = document.getElementById('root') 66const root = createRoot(rootElement) 67 68root.render(<App />)
The props of the TranslationProvider component:
Example:
1function App() { 2 return ( 3 <TranslationProvider 4 translations={translations} 5 defaultLanguage='en' 6 language='es' 7 > 8 ... 9 </TranslationProvider> 10 ) 11}
In your React components, you can use the useTranslate hook to get the translate function.
1const translate = useTranslate()
The parameters of the translate function:
For substitution, the keys are surrounded by curly brackets:
1{ 2 "greeting_message": "Hi {{userName}}. You have {{totalUnread}} messages." 3}
Example:
1translate("greeting_message", { userName: "Mr. White", totalUnread: 5 }) 2// → "Hi Mr. White. You have 5 messages."
In your React components, you can use the useTranslatorConfigurer hook to get the translator configure function. You can change the language or set the translations dynamically using this function.
1const configure = useTranslatorConfigurer()
You can pass the following keys to the parameter of the configure function:
To change language:
1const configure = useTranslatorConfigurer() 2configure({ language: 'en' }) // Changes language to English.
Load/import translation data from one more JSON files. Check this CodeSandbox example for detailed instructions and file/folder structure.
1const translations = { 2 ...require('../src/locales/en.json'), 3 ...require('../src/locales/es.json'), 4 ...require('../src/locales/bn.json') 5}
You are welcome to contribute! If you are adding a feature or fixing a bug, please contribute to the GitHub repository.
i18next-lite is licensed under the MIT license.
@SheikhAminul |
No vulnerabilities found.
No security vulnerabilities found.