UNPKG

@allakando/allakando-i18n

Version:

Allakando's internationalization library

10 lines (9 loc) 1.44 kB
(function(t,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(t=typeof globalThis<"u"?globalThis:t||self,a(t.Allakandoi18n={}))})(this,function(t){"use strict";/** @preserve @license @cc_on * ---------------------------------------------------------- * @allakando/allakando-i18n version 0.0.4 * Allakando's internationalization library * Copyright (c) 2023 Allakando * All Rights Reserved. MIT License * https://mit-license.org/ * ---------------------------------------------------------- */class a{constructor(e,n){this.translationsByLocale=e,this.language=n,this.defaultLanguage=n,this.isDebugMode=!1}setLanguage(e){this.language=e}translate(e){return this.isDebugMode?()=>e:this.translationsByLocale[this.language]?this.translationsByLocale[this.language][e]:this.translationsByLocale[this.defaultLanguage][e]}getTranslations(){return this.isDebugMode?Object.keys(this.translationsByLocale[this.defaultLanguage]).reduce((e,n)=>(e[n]=()=>n,e),{}):this.translationsByLocale[this.language]?this.translationsByLocale[this.language]:this.translationsByLocale[this.defaultLanguage]}enableDebugMode(){this.isDebugMode=!0}disableDebugMode(){this.isDebugMode=!1}}const s=()=>navigator.languages&&navigator.languages.length>1?navigator.languages[1]:navigator.language;t.TranslatorAPI=a,t.getUserLocale=s,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});