Locale is a basic localization package that takes the location of your locales and loads them into a map for easy looking up.
Let us say you have a localization for English, it would look something like this:
{
"WELCOME:MAIN_MESSAGE": "Welcome to x Server",
"WELCOME:FOOTER_MESSAGE": "Enjoy your stay x user!"
}
Now time for the coding. Here we are just going to load up the locales and fetch a translation.
import { Localization } from 'locale';
(async () => {
/**
* When using Locale, you wanna make sure you make an instance of the Localization class.
* The class takes in only a single paramater which are the options.
*
* As of right now there is only one option with is lng. lng is what you set as the default
* language, the package will use lng if you don't supply anything else in the 't' translate
* method as shown below.
*
* Locale uses the standard formatting of i18n localizations of "KEY:NAME": "VALUE" so you
* have to look up those translations following the same pattern.
*/
const locale = new Localization({ lng: 'en' })
await locale.addMultipleIn("locales")
console.log(locale.t('WELCOME:MAIN_MESSAGE')) // Welcome to x Server
console.log(locale.t('WELCOME:MAIN_MESSAGE', 'es')) // Bienvenido al servidor x
})()
- Make a fork of this repo
- Code up all your changes
- Open a PR so I can review your changes and possibly merge.