Shared I18n
Internationalization (i18n) infrastructure for the Substrate project, built on i18next.
This package provides i18n utilities (initialization, React provider, hooks) but does not store translation JSON files. Each application provides its own translations at initialization time.
For detailed usage documentation, see the Shared I18n documentation on the docs site.
Contributing
Prerequisites
- Node.js 20+ and Yarn
- Understanding of i18next and internationalization concepts
- Familiarity with React (for using the provider and hooks)
Commands
# Build the package
nx build shared-i18n
# Run tests
nx test shared-i18n
# Lint the package
nx lint shared-i18n
Project Structure
packages/shared-i18n/
├── src/
│ ├── lib/
│ │ ├── i18n.ts # Core i18n initialization and helpers
│ │ ├── i18n.spec.ts # Tests
│ │ └── react.tsx # React provider and hooks
│ └── index.ts # Package exports
├── docs/ # Documentation (built to docs site)
└── README.md # This file
Adding New Translations
Translation JSON files are owned by each application (e.g., apps/web/src/locales/en.json).
- Open the translation file in the relevant application
- Add your translation following the key format:
project.scope.purpose.term - For other languages, add the same key to their respective files
- Use the new translation key in your code
Translation Key Format
Keys follow the format: project.scope.purpose.term
Examples:
global.company.name- Shared across all projectsweb.navigation.warning.text- Specific to the web app's navigationweb.home.welcome- For the web app's home page
Adding New Languages
- Create a new JSON file in the application's locales directory (e.g.,
apps/web/src/locales/fr.json) - Copy the structure from
en.jsonand translate all values - Update the application's i18n provider to include the new language in the
resourcesobject
Environment Variables
No environment variables required for this package.
React Usage
The package provides:
I18nProvider- React context provider (requiresresourcesprop with translation data)useTranslation()- Hook to get translation functionuseI18nContext()- Hook to access language context
Node.js Usage
The package also exports standalone functions for use in Node.js code:
initI18n({ resources })- Initialize i18n with translation resourcest(key)- Translate a key
Related Documentation
- Root README - Substrate overview
- Docs README - Documentation site