Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an i18n manager #3

Open
wizardlink opened this issue Jun 25, 2021 · 0 comments
Open

Create an i18n manager #3

wizardlink opened this issue Jun 25, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@wizardlink
Copy link
Member

wizardlink commented Jun 25, 2021

A much requested feature for kanna was i18n, this will be implemented within our framework so any of our applications (and those who use the framework) are able to have it also out of the box.

This manager has to extend the BaseManager so it can load up all the translation files.

Configuration

A new field has to be added to the IConfig interface for configuring the i18n manager.

interface IConfig
{
  ...,
  i18n: {
    defaultLanguage?: LanguageTag,
  }
}

Features

  1. Automatically load & use i18n translation files.
  2. Ability to refresh manager (forcing a re-load of all files)
    • This can be used as reference.
  3. Accessible anywhere through AkitaNeru via <AkitaNeru>.i18n.

The class should therefore be called I18nManager and have a public property resources, of type Map<string, ITranslationFile>, as well as a method <I18nManager>.find(resource: string, tag: LanguageTag): string that returns the translated resource or the default resource if it is not yet translated, if both aren't found, silently throw an error.

Files

Translation files should be JSONs and are to follow this interface:

interface ITranslationFile
{
  language?: LanguageTag // The language this file translates, i.e. English.
  messages?: { [key: string]: string | string[] } // The translations itself.
}

Language tag references

// Reference - http://www.i18nguy.com/unicode/language-identifiers.html
enum LanguageTag
{
  ABKHAZIAN = 'zb',
  AFRIKAANS = 'af',
  AKAN = 'ak',
  ALBANIAN = 'sq',
  AMHARIC = 'am',
  ARABIC = 'ar-SA',
  ARAGONESE = 'an',
  ARMENIA = 'hy',
  ASSAMESE = 'as',
  AVARIC = 'av',
  AVESTAN = 'ae',
  AYMARA = 'ay',
  AZERBAIJANI = 'az',
  BAMBARA = 'bm',
  BASQUE = 'eu',
  BELARUSIAN = 'be',
  BIHARI = 'bh',
  BOKMAL = 'nb',
  BOSNIAN = 'bs',
  BRETON = 'br',
  BULGARIAN = 'bg',
  BURMESE = 'my',
  CATALAN = 'ca',
  CHICHEWA = 'ny',
  CHINESE = 'zh-CN',
  CHURCH_SLAVIC = 'cu',
  CORNISH = 'kw',
  CORSICAN = 'co',
  CREE = 'cr',
  CROATIAN = 'hr-HR',
  CZECH = 'cs',
  DINKA = 'din',
  DIVEHI = 'dv',
  DZONGKHA = 'dz',
  ENGLISH = 'en-US',
  ESPERANTO = 'eo',
  ESTONIAN = 'et',
  EWE = 'ee',
  FAROESE = 'fo',
  FIJIAN = 'fj',
  FRENCH = 'fr-FR',
  GAELIC = 'gd',
  GALICIAN = 'gl',
  GANDA = 'lg',
  GEORGIAN = 'ka',
  GERMANY = 'de-DE',
  GILBERTESE = 'gil',
  GREEK = 'el-GR',
  GUARANI = 'gn',
  GUJARATI = 'gu',
  HAITIAN = 'ht',
  HAKKA = 'i-hak',
  HAUSA = 'ha',
  HAWAIIAN = 'haw',
  HEBREW = 'he',
  HERERO = 'hz',
  HINDI = 'hi',
  HIRI_MOTU = 'ho',
  HUNGARIAN = 'hu-HU',
  ICELANDIC = 'is',
  IDO = 'io',
  IGBO = 'ig',
  INARI_SAMI = 'smn',
  INDONESIAN = 'id',
  INTERLINGUA = 'ia',
  INTERLINGUE = 'ie',
  INUKTITUT = 'iu',
  INUPIAQ = 'ik',
  ITALIAN = 'it-IT',
  JAPANESE = 'ja',
  JAVANESE = 'jv',
  KANNADA = 'kn',
  KANURI = 'kr',
  KASHMIRI = 'ks',
  KAZAKH = 'kk',
  KHMER = 'km',
  KIKUYU = 'ki',
  KIRGHIZ = 'ky',
  KONGO = 'kg',
  KONKANI = 'kok',
  KOREAN = 'ko-KP',
  KURDISH = 'ku',
  LAO = 'lo',
  LATIN = 'la',
  LATVIAN = 'lv',
  LITHUANIAN = 'lt',
  LUXEMBOURGISH = 'lb',
  MALAGASY = 'mg',
  MALAY = 'ms-MY',
  MALAYALAM = 'ml',
  MANX = 'gv',
  MAORI = 'mi',
  MARATHI = 'mr',
  MARSHALLESE = 'mh',
  MOLDAVIAN = 'mo',
  MONGOLIAN = 'mn',
  NAURU = 'na',
  NAVAJO = 'nv',
  NDONGA = 'ng',
  NEPALI = 'ne',
  NORWEGIAN = 'no',
  NYNORSK = 'nn',
  OCCITAN = 'oc',
  OJIBWA = 'oj',
  ORIYA = 'or',
  OSSETIAN = 'os',
  PALI = 'pi',
  PANJABI = 'pa',
  POLISH = 'pl',
  PORTUGUESE = 'pt-PT',
  PORTUGUESE_BRAZIL = 'pt-BR',
  PUSHTO = 'ps',
  QUECHUA = 'qu',
  RAETO_ROMANCE = 'rm',
  ROMANIAN = 'ro',
  RUNDI = 'rn',
  RUSSIAN = 'ru-RU',
  SAMI = 'se',
  SAMOAN = 'sm',
  SANKSRIT = 'sa',
  SARDINIAN = 'sc',
  SERBIAN = 'sr',
  SHONA = 'sn',
  SICHUAN_YI = 'ii',
  SIDAMO = 'sid',
  SINHALA = 'si',
  SLOVAK = 'sk',
  SORBIAN = 'wen',
  SOTHO = 'st',
  SUNDANESE = 'su',
  SWAHILI = 'sw-TZ',
  SWATI = 'ss-SZ',
  SWEDISH = 'sv-SE',
  SYRIAC = 'syr',
  TAGALOG = 'tl',
  TAHITIAN = 'ty',
  TAJIK = 'tg',
  TATAR = 'tt',
  TELUGU = 'te',
  THAI = 'th',
  TIBETAN = 'bo',
  TONGAN = 'to',
  TSONGA = 'ts',
  TURKISH = 'tr-TR',
  TUVALU = 'tvl',
  TWI = 'tw',
  UIGHUR = 'ug',
  UKRAINIAN = 'uk',
  UZBEK = 'uz-UZ',
  VENDA = 've',
  VOLAPUUK = 'vo',
  WALAMO = 'wal',
  WALLOON = 'wa',
  WOLOF = 'wo',
  XHOSA = 'xh',
  YIDDISH = 'yi',
  YORUBA = 'yo',
  YUE = 'zh-yue',
  ZHUANG = 'za',
  ZULU = 'zu',
  KUANYAMA = 'kj',
}
@wizardlink wizardlink added the enhancement New feature or request label Jun 25, 2021
@wizardlink wizardlink added this to the v1 milestone Jun 25, 2021
@wizardlink wizardlink self-assigned this Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant