Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TypeScript-based internationalization (i18n) package for the React ecosystem.

License

NotificationsYou must be signed in to change notification settings

jereztech/i18n-react

Repository files navigation

NPM VersionGPL LicenseTest Coverage

TypeScript-based internationalization (i18n) package for the React ecosystem, including but not limited toReact,Next.js, andReact Native.

Features

  • Auto-detection: Automatically detects user's language preferences.
  • Namespace Support: Organize your translations using namespaces.
  • Lightweight: Minimal overhead with efficient performance.
  • Fallback Message: Fall back to default message if TranslationKey is not resolved.

Installation

Install the package via npm:

npm install @jereztech/i18n-react

Usage

Configuration

Create ani18n.config.ts file at the root of your project. See/examples/i18n.config.ts for reference.

I18nConfig Options

FieldTypeDefaultDescription
defaultLocalestring'en'The default locale to use when no user preference is detected or for fallback translations.
dictionariesMap{}A Map of translation dictionaries for supported locales.
autodetectLanguagebooleantrueAutomatically detect the user's language preferences.
initializeWithDefaultbooleantrueInitialize with the default locale if autodetection is disabled or fails.

Note: The fieldsautodetectLanguage andinitializeWithDefault default totrue. They can be disabled by setting them toundefined in your configuration:

import{DictionaryMap,I18nConfig}from"@jereztech/i18n-react";importenfrom'./assets/dictionaries/en.json';importesfrom'./assets/dictionaries/es.json';constdictionaries:DictionaryMap={ en, es};consti18nConfig:I18nConfig={defaultLocale:'en',    dictionaries,autodetectLanguage:undefined,};exportdefaulti18nConfig;

Setting Up theI18nProvider

Wrap your application with theI18nProvider to provide localization context:

import{ReactNode}from'react';import{I18nProvider}from'@jereztech/i18n-react';importi18nConfigfrom'../i18n.config';exportdefaultasyncfunctionRootLayout({ children, params}:{children:ReactNode;params:{locale:string};}){const{ locale}=awaitparams;return(<htmllang={locale}><body><I18nProviderconfig={i18nConfig}>{children}</I18nProvider></body></html>);};

Using theuseI18n Hook

Access translations within your components using theuseI18n hook:

"use client";import{useI18n}from'@jereztech/i18n-react';exportdefaultfunctionHome(){const{ t}=useI18n();return<div>{t('greeting',{name:'John'},'fallbackTranslationKey')}</div>;};

License

This project is licensed under theGNU General Public License v3.0 - see theLICENSE file for details.

Copyright (C) 2025Jerez Tech

About

TypeScript-based internationalization (i18n) package for the React ecosystem.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp