# @shopify/i18n

> Generic i18n-related utilities

Latest version **2.1.0** (published 2024-06-10) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @shopify/i18n
pnpm add @shopify/i18n
yarn add @shopify/i18n
bun add @shopify/i18n
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2024-06-10 |
| First published | 2018-09-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.12.0 |
| Dependencies | 0 |
| Unpacked size | 18.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1681 |
| Author | Shopify Inc. |
| Maintainers | jaimie.rockburn, blittle, shopify-admin, maryharte, crisfmb, pmoloney89, netlohan, st999999, justin-irl, megswim, wcandillon, nathanpjf, shopify-dep, goodforonefare, lemonmade, vsumner, wizardlyhel, antoine.grant, tsov, andyw8-shopify, henrytao, hannachen, vividviolet, bpscott |

## Links

- npm: https://www.npmjs.com/package/@shopify/i18n
- Repository: https://github.com/Shopify/quilt
- Homepage: https://github.com/Shopify/quilt/blob/main/packages/i18n/README.md
- Issues: https://github.com/Shopify/quilt/issues
- npm.io page: https://npm.io/package/@shopify/i18n

## Recent versions

- 2.1.0 (latest) — 2024-06-10
- 1.0.7-export-beta.0 (next) — 2022-02-22
- 1.0.1-address-mocks-minified-beta.0 (beta) — 2021-06-02
- 2.0.1 — 2022-08-24
- 2.0.0 — 2022-05-19
- 1.0.9 — 2022-03-09
- 1.0.8 — 2022-02-25
- 1.0.7 — 2022-02-01
- 1.0.6 — 2022-02-01
- 1.0.5 — 2021-09-24
- 1.0.4 — 2021-08-24
- 1.0.3 — 2021-08-04
- 1.0.2 — 2021-08-04
- 1.0.1 — 2021-06-03
- 1.0.0 — 2021-05-22
- … 29 more at https://npm.io/package/@shopify/i18n/versions

## README

# `@shopify/i18n`

[![Build Status](https://github.com/Shopify/quilt/workflows/Node-CI/badge.svg?branch=main)](https://github.com/Shopify/quilt/actions?query=workflow%3ANode-CI)
[![Build Status](https://github.com/Shopify/quilt/workflows/Ruby-CI/badge.svg?branch=main)](https://github.com/Shopify/quilt/actions?query=workflow%3ARuby-CI)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE.md) [![npm version](https://badge.fury.io/js/%40shopify%2Fi18n.svg)](https://badge.fury.io/js/%40shopify%2Fi18n.svg) [![npm bundle size (minified + gzip)](https://img.shields.io/bundlephobia/minzip/@shopify/i18n.svg)](https://img.shields.io/bundlephobia/minzip/@shopify/i18n.svg)

Generic i18n-related utilities.

## Installation

```bash
yarn add @shopify/i18n
```

## Usage

### `pseudotranslate()`

Takes a string and returns a version of it that appears as if it were translated (learn more about [pseudotranslation](https://help.smartling.com/hc/en-us/articles/360000307573-Testing-with-Pseudo-Translation)).

This function accepts a number of arguments to customize the translation:

- `toLocale`: a locale to simulate translation for. This is used primarily to adjust the change in size relative to the original string. When not provided, or when a locale is provided for which no custom size ratio exists, this function slightly increases the string size.
- `delimiter`, `startDelimiter`, `endDelimiter`: strings used to mark parts of the source string that should not be translated. This can be used, for example, to prevent translation of replacements within a string.
- `prepend` and `append`: strings to put at the start and end of the resulting string, respectively. This can be used to provide a common set of text around pseudotranslated code that can identify translated strings that are incorrectly joined together.

```ts
import {pseudotranslate} from '@shopify/react-i18n';

const pseudoOne = pseudoTranslate('cat'); // something like 'ͼααṭ'
const pseudoTwo = pseudoTranslate('cats: {names}', {
  toLocale: 'de',
  startDelimiter: '{',
  endDelimiter: '}',
  prepend: '[[!',
  append: '!]]',
}); // something like '[[!ͼααṭṡṡ: {names}]]!'
```

### `regionFromLocale()`

Accepts a locale and extracts the country code as defined in [BCP 47](https://tools.ietf.org/html/rfc5646#section-2.2.4), if it exists. The country code will be normalized to fully uppercase when present.

```ts
import {regionFromLocale} from '@shopify/i18n';

const regionEn = regionFromLocale('en'); // undefined
const regionEnCa = regionFromLocale('en-ca'); // 'CA'
```

### `languageFromLocale()`

Accepts a locale and extracts the language subtag as defined in [BCP 47](https://tools.ietf.org/html/rfc5646#section-2.2.1).

```ts
import {languageFromLocale} from '@shopify/i18n';

const languageFrCa = languageFromLocale('fr-CA'); // 'fr'
```

---
_Source: https://npm.io/package/@shopify/i18n · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
