Class I18n

Class representing an I18n (Internationalization) Brick. It extends from the Brick class.

Example

const brick = new I18nBrick({ resources: { es: { translation: { 'Hello': 'Hola' } } } })
brick.language = 'es'
console.log(brick.t('Hello')) // 'Hola'

Hierarchy

Constructors

Properties

#keepAliveInterval?: Timer

The interval of the keep alive function of the Brick instance. This is a private property used to store the interval of the keep alive function.

#programs: {
    [key: string]: Program;
}

The programs of the Brick instance. This is a private property used to store the programs that the Brick can run.

Type declaration

#tasks: Task[] = []

The scheduled tasks of the Brick instance. This is a private property used to store the scheduled tasks that the Brick can run.

The intelligence of the Brick instance. This is used to manage the AI capabilities of the Brick.

The database of the Brick instance. This is used to manage the data storage and retrieval for the Brick.

events: EventEmitter

The event emitter of the Brick instance. This is used to emit events that occur in the Brick, such as the running of a program.

i18next: any

The i18next instance.

id: string

The unique identifier of the Brick instance.

log: Logger<LoggerOptions>

The logger used by the Brick instance. This is used to log information about the operation of the Brick.

name: string

The name of the Brick instance.

structure?: Structure

The parent Structure of the Brick instance, if any.

t: ((key, options?) => void)

Type declaration

    • (key, options?): void
    • The translation function.

      Parameters

      • key: string
      • Optional options: any

      Returns void

Accessors

  • get language(): string
  • Gets the current language of the I18n Brick.

    Returns string

  • set language(language): void
  • Sets the current language of the I18n Brick.

    Parameters

    • language: string

    Returns void

  • get languages(): readonly string[]
  • Gets the languages supported by the I18n Brick.

    Returns readonly string[]

  • get programs(): {
        [key: string]: Program;
    }
  • Returns the private map of programs.

    Returns {
        [key: string]: Program;
    }

Methods

  • Removes a program from the private map of programs by its name.

    Parameters

    • name: string

      The name of the program to remove.

    Returns void

  • Translates text using the current language.

    Parameters

    • text: string

      The text to translate.

    Returns string

  • Toggles the keep alive flag of the Brick instance, which will prevent the Node process from exiting

    Parameters

    • on: boolean

      A boolean indicating whether to turn the keep alive flag on or off.

    Returns void

    Remarks

    This is useful if you don't have a server or something else keeping the Node process alive.

  • Adds a program to the private map of programs.

    Parameters

    • program: Program

      The program to add.

    Returns void

  • Runs a program by its name with a given payload.

    Parameters

    • name: string

      The name of the program to run.

    • payload: any

      The payload to pass to the program.

    Returns Promise<any>

    The result of the program.

  • Schedules a Task to run on a given schedule. This is a wrapper around the node-cron package.

    Parameters

    Returns Task

    The scheduled task.

    Remarks

    The task will run on the schedule provided, and will run the method provided with the Brick instance as the first argument.

    Throws

    An error if the task already exists.

  • Unschedules a task by its name.

    Parameters

    • name: string

      The name of the task to unschedule.

    Returns void

    Throws

    An error if the task does not exist.