lzo-i18n
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

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

  • [x] Redis
  • [x] 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.

/lzo-i18n/

    Package Sidebar

    Install

    npm i lzo-i18n

    Weekly Downloads

    0

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    27.7 kB

    Total Files

    15

    Last publish

    Collaborators

    • guilhermesantos001