UNPKG

@rr0/lang

Version:

Language and translation

27 lines (26 loc) 979 B
import { Gender, KeyValue } from "@rr0/common"; import { Grammar } from "./Grammar.js"; export interface WordMessage { [gender: string]: string; } export declare class Translator { readonly locale: string; readonly grammar: Grammar; /** * Creates a message translator to some language. * * @param locale The language to translate to. * @param grammar The grammar rules of the language. */ constructor(locale: string, grammar: Grammar); compoundKey(subKeys: string[]): string; getGender(word: WordMessage): Gender; translateKey(obj: KeyValue, key: string, values?: KeyValue): string; /** * Returns a translated message, with possible values interpolated. * * @param template The message template, which can contain placeholders such as ${key} or ${key:plural} * @param values The values to be interpolated into the placeholders. */ translate(template: string, values?: KeyValue): string; }