Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dotupnet/dotup-ts-internationalization
Library for typed translation and internationalization
https://github.com/dotupnet/dotup-ts-internationalization
cldr i18n intl numberformat plural-rules pluralization translation typed typescript
Last synced: 5 days ago
JSON representation
Library for typed translation and internationalization
- Host: GitHub
- URL: https://github.com/dotupnet/dotup-ts-internationalization
- Owner: dotupNET
- License: mit
- Created: 2019-02-28T15:30:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-03T00:21:55.000Z (almost 2 years ago)
- Last Synced: 2024-10-02T18:10:44.562Z (about 1 month ago)
- Topics: cldr, i18n, intl, numberformat, plural-rules, pluralization, translation, typed, typescript
- Language: TypeScript
- Homepage:
- Size: 482 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/dotupNET/dotup-ts-internationalization.svg?branch=skill-template)](https://travis-ci.org/dotupNET/dotup-ts-internationalization)
# dotup-ts-internationalization
Library for typed translation and internationalization## USAGE
```typescript
enum TextKeys {
'Hello' = 'Hello', 'WithTextLink' = 'WithTextLink', 'Slang' = 'Slang',
PluralizedWithGender = 'PluralizedWithGender',
DirectText = 'DirectText',
Pluralized = 'Pluralized',
TextArray = 'TextArray',
PlaceHolderText = 'PlaceHolderText',
Gendered = 'Gendered',
NamedPlaceHolderText = 'NamedPlaceHolderText'
}const translations: Translations = {
'de-DE': {
PlaceHolderText: 'Text with {0}',
NamedPlaceHolderText: 'Text two with {MyVariable}',
DirectText: 'DirectText',
TextArray: ['TextArray1', 'TextArray2'],
WithTextLink: ['$(DirectText) with $(Slang)'],
Gendered: {
male: 'is male',
female: 'is female'
},
Pluralized: {
plural: {
zero: 'zero',
one: 'one',
few: 'few',
many: 'many',
other: 'other',
two: 'two'
}
},
PluralizedWithGender: {plural: {
few: {
female: [''],
male: 'he has #'
},
one: {
female: ['plural-one-female # $(DirectText)'],
male: 'plural-one-male $(DirectText)'
},
other: 'plural-other $(DirectText)',
many: ''
},
ordinal: {
one: ['erstes $(Hello)'],
other: 'zweites $(Hello)'
}
},
Hello: ['Hallo', 'Hi', 'Servus'],
Slang: ['nasen', 'eumel', 'vögel']
}
};// Initialize required languages
InitializeIntl(LanguageEnum.deDE, LanguageEnum.enGB);// Initialize text library with text
const tlib = new TextLibrary(translations);
// Get a translator for a specific language
const t = tlib.getTranslator(LanguageEnum.deDE);// Translate
const result = t.format({
key: TextKeys.PluralizedWithGender,
gender: GenderGroups.male,
plural: {
group: PluralGroups.plural,
value: 1
}
});
console.log(`format 1: ${result}`);```
## Docs:
https://dotupnet.github.io/dotup-ts-internationalization/index.html## repository:
https://github.com/dotupNET/dotup-ts-internationalization/tree/skill-template