2.0.1 • Published 2 years ago

@shopify/i18n v2.0.1

Weekly downloads
28,077
License
MIT
Repository
github
Last release
2 years ago

@shopify/i18n

Build Status Build Status License: MIT npm version npm bundle size (minified + gzip)

Generic i18n-related utilities.

Installation

$ 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).

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.
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, if it exists. The country code will be normalized to fully uppercase when present.

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.

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

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

2 years ago

2.0.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.2.7

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.12

4 years ago

0.1.11

4 years ago

0.1.10

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.1

6 years ago

0.1.0

6 years ago