1.1.0 • Published 1 year ago

lzo-i18n v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

LZO: i18n

Support for i18n in Node.js

Sponsor Commitizen friendly TypeScript version Node.js version MIT Build Status - GitHub Actions

Installation

npm install lzo-i18n OR yarn add lzo-i18n

Support for drivers

  • Redis
  • File System (FS)

Configuration

Please input the credentials of your Redis server in the .env file.

See the example in the .env.example file.

REDIS_URL="redis://IP:PORT"
REDIS_PORT=6379
REDIS_PASSWORD="PASSWORD"

Usage

import { I18n } from 'lzo-i18n';

const locale = I18n({
  locale: {
    main: 'en',
    languages: ['en', 'pt'],
    driver: 'fs'
  }
});

await locale.defineProperty('en', {
    say: {
      hi: 'Hi $1, how are you?',
    }
}); // Define a property in the language.

console.log(await locale.translate('say.hi', 'GuilhermeSantos001')); // Hi GuilhermeSantos001, how are you?

API

I18n.setLocale(locale: string): Promise<void>

Set the current locale

I18n.getLocale(): string

Get the current locale

I18n.getLocales(): string[]

Get all locales

I18n.resetLocales(): Promise<void>

Reset all locales

I18n.removeLocale(locale: string): Promise<number | void>

Remove a locale

I18n.defineProperty<T>(locale: string, prop: T): Promise<false | void | "OK">

Define a property in a locale

I18n.removeProperty(locale: string, ...props: string[]): Promise<false | void | "OK">

Remove a property in a locale

I18n.translate(phrase: string, ...params: string[]): Promise<string>

Translate a phrase in the current locale

Backers & Sponsors

Support this project by becoming a sponsor.

License

Licensed under the MIT. See the LICENSE file for details.