@giancosta86/hermes v3.1.0
hermes
Minimalist i18n in TypeScript
hermes is a TypeScript library tackling the issues of internationalization (i18n) with minimalist and elegant tools.
Installation
The package on NPM is:
@giancosta86/hermes
The public API entirely resides in the root package index, so one shouldn't reference specific modules.
Usage
IsoDateFormat: formatsIsoDateobjects - as defined in time-utils. It can be constructed with the same options asDateTimeFormat- also supporting reasonable defaults in itsdefaultOptionsstatic propertyNoun: defines a noun - which can have a singular and a plural form. Case-based declension is not supported at present, but one can use case-keyed maps ofNounvaluesMeasureUnittakes aNounand provides adeclineFor()method, which returns:the
singularform if the value is +1 or -1the
pluralform otherwise
Languageis a semantically useful type alias forstringLocaleLike- can be either a BCP47 language tag string or anÌntl.Localeobject; its namespace provides:languageFacets: an array containing the i18n-related attribute names of anIntl.Localeinstance except thelanguageattributetoLocale()takes aLocaleLikeand always returns anIntl.LocaletoLanguageTag()takes aLocaleLikeand returns its BCP47 language taggetDistance()takes twoLocaleLike, converts them toIntl.Localeand returns:Number.POSITIVE_INFINITYif the twolanguageattributes are different0if all the other i18n-related attributes (languageFacets) are equal, otherwise+1is added for every non-matching attribute
createProximityContext(): creates a context for aProximityMapbased
The
Dictionaryclass provides:translate(<phrase string>): to return the translation registered for the given phrase; if a translation is not registered, the original phrase itself is returnedtoRawTranslations(): returns an object whose keys are the registered phrases, with the related translations as values; the returned type isRawTranslations
A dictionary can be built via:
the constructor, expecting a Rimbu
RMapthe static
fromRawTranslationsmethod, expecting a plain object whose entries are the translations
DictionaryLibraryis a container of virtually illimitedDictionaryinstances - and can only be built via static methods.Each dictionary can be retrieved from a library via
getDictionary(LocaleLike)- not necessarily via an exact match, but by proximity: the dictionary registered with the most matching locale (shorter or longer) is returned; proximity is computed withLocaleLike.getDistance(), as described above.The registered locales are returned by the
streamLocales()method; if a library is requested an unregistered locale, an empty dictionary is returned - so translations will always return the requested phrase itself.
Further references
IETF BCP 47 - Standardized codes that are used to identify human languages
time-utils - Time-related utilities
Rimbu - Immutable collections and tools for TypeScript
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago