# preact-i18n **Repository Path**: mirrors_developit/preact-i18n ## Basic Information - **Project Name**: preact-i18n - **Description**: Simple localization for Preact. - **Primary Language**: Unknown - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-08 - **Last Updated**: 2026-08-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # preact-i18n 🌎 [![npm](https://img.shields.io/npm/v/preact-i18n.svg?style=flat)](https://npm.im/preact-i18n) [![travis](https://travis-ci.org/synacor/preact-i18n.svg?branch=master)](https://travis-ci.org/synacor/preact-i18n) [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fsynacor%2Fpreact-i18n.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fsynacor%2Fpreact-i18n?ref=badge_shield) Usage example **Simple localization for Preact.** - Tiny: about 1.3kb gzipped - Supports dictionary and key scopes/namespaces while maintaining a global dictionary - Supports nested dictionaries: - Wrap your component in a default dictionary and scope key - Wrap it again later on (in an app!) to override the defaults - Supports pluralization of strings using nested objects. - Supports template `{{fields}}` in definition values - Has a companion [ESLint plugin](https://www.npmjs.com/package/eslint-plugin-preact-i18n) to help catch bugs early * * * - [Installation](#installation) - [Getting Started](#getting-started) - [Fallback Text](#fallback-text) - [Pluralization and Templating](#pluralization-and-templating) - [ESLint Plugin](#eslint-plugin) - [API](#api) ## Preact Version Support By default, the `master` branch of this repo supports preact 9 and below, and is published in normal patch/minor/major releases to the `latest` tag in npm. Support for preact X (versions 10+ of preact) is handled in the `preactX` branch and are always published to the `preactx` tag in npm. When preact X obtains widespread adoption, the `master` branch of this project will support preact X and a new major version under `latest` tag will be published to in npm. ## Installation ```sh npm install --save preact-i18n ``` ## Getting Started 1. Create a definition. Typically JSON files, we'll call ours `fr.json`: ```json { "news": { "title": "Nouvelles du Monde", "totalStories": { "none": "Aucun article", "one": "Un article", "many": "{{count}} articles" } } } ``` 2. Expose the definition to your whole app via ``: ```js import { IntlProvider } from 'preact-i18n'; import definition from './fr.json'; render( ); ``` 3. Use `` to translate string literals: ```js import { Text } from 'preact-i18n'; // Assume the "stories" prop is a list of news stories. const App = ({ stories=[] }) => (

{/* Default fallback text example: */} World News

{/* Pluralization example: */}
); ``` That's it! ### Fallback Text Rendering our example app with an empty definition _(or without the Provider)_ will attempt to use any text contained within `..` as fallback text. In our example, this would mean rendering without a definition for `news.title` would produce `

World News

`. If we provide a definition that has a `title` key inside a `news` object, that value will be rendered instead. ### Pluralization and Templating In our example, `