L10n module
đ Descriptionâ
The L10n
module contains functions for localization. Tripetto uses the GNU gettext system.
đŠâđģ Exampleâ
import { L10n } from "@tripetto/runner";
// Translate message
L10n.gettext("Lorem ipsum dolor sit amet");
// Translate message with shorthand
L10n._("Lorem ipsum dolor sit amet");
// Translate message with arguments
L10n.gettext("Hello %1", "there");
// Shorthand
L10n._("Hello %1", "there");
// Translate plural message
L10n.ngettext("1 user", "%1 users", 2);
// Shorthand
L10n._n("1 user", "%1 users", 2);
đ Classesâ
âļī¸ Functionsâ
đ§ _
â
Translates a message (short for gettext
).
This function uses the global translation namespace (L10n.Namespace.global
) and is a shorthand for L10n.Namespace.global._
.
Signatureâ
_(message: string, ...arguments: string[]): string
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
message | string | No | Specifies the message to translate. |
arguments | string[] | Yes | Optional string arguments which can be referenced in the message using the percent sign followed by the argument index %n . The first argument is referenced with %1 . |
Return valueâ
Returns the translated message.
đ§ _n
â
Translates a plural message (short for ngettext
).
This function uses the global translation namespace (L10n.Namespace.global
) and is a shorthand for L10n.Namespace.global._n
.
Signatureâ
_n(message: string, messagePlural: string, count: number, ...arguments: string[]): string
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
message | string | No | Specifies the message to translate. |
messagePlural | string | No | Specifies the plural message to translate. |
count | number | No | Specifies the count for the plural (can be reference in the message with %1 ). |
arguments | string[] | Yes | Optional string arguments which can be referenced in the message using the percent sign followed by the argument index %n . The count value is automatically included as the first argument (%1 ). |
Return valueâ
Returns the translated message.
Exampleâ
import { L10n } from "@tripetto/runner";
// Outputs `1 car` to the console.
console.log(L10n._n("1 car", "%1 cars", 1));
// Outputs `2 cars` to the console.
console.log(L10n._n("1 car", "%1 cars", 2));
đ§ dgettext
â
Translates a message using the specified translation domain.
This function uses the global translation namespace (L10n.Namespace.global
) and is a shorthand for L10n.Namespace.global.dgettext
.
Signatureâ
dgettext(domain: string, message: string, ...arguments: string[]): string
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
domain | string | No | Specifies the translation domain to use. |
message | string | No | Specifies the message to translate. |
arguments | string[] | Yes | Optional string arguments which can be referenced in the message using the percent sign followed by the argument index %n . The first argument is referenced with %1 . |
Return valueâ
Returns the translated message.
đ§ dngettext
â
Translates a plural message using the specified translation domain.
This function uses the global translation namespace (L10n.Namespace.global
) and is a shorthand for L10n.Namespace.global.dngettext
.
Signatureâ
dngettext(
domain: string,
message: string,
messagePlural: string,
count: number,
...arguments: string[]
): string
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
domain | string | No | Specifies the translation domain to use. |
message | string | No | Specifies the message to translate. |
messagePlural | string | No | Specifies the plural message to translate. |
count | number | No | Specifies the count for the plural (can be reference in the message with %1 ). |
arguments | string[] | Yes | Optional string arguments which can be referenced in the message using the percent sign followed by the argument index %n . The count value is automatically included as the first argument (%1 ). |
Return valueâ
Returns the translated message.
đ§ dnpgettext
â
Translates a plural message with the specified context using the specified translation domain.
This function uses the global translation namespace (L10n.Namespace.global
) and is a shorthand for L10n.Namespace.global.dnpgettext
.
Signatureâ
dnpgettext(
domain: string,
context: string,
message: string,
messagePlural: string,
count: number,
...arguments: string[]
): string
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
domain | string | No | Specifies the translation domain to use. |
context | string | No | Specifies the translation context. |
message | string | No | Specifies the message to translate. |
messagePlural | string | No | Specifies the plural message to translate. |
count | number | No | Specifies the count for the plural (can be reference in the message with %1 ). |
arguments | string[] | Yes | Optional string arguments which can be referenced in the message using the percent sign followed by the argument index %n . The count value is automatically included as the first argument (%1 ). |
Return valueâ
Returns the translated message.
đ§ dpgettext
â
Translates a message with the specified context using the specified translation domain.
This function uses the global translation namespace (L10n.Namespace.global
) and is a shorthand for L10n.Namespace.global.dpgettext
.
Signatureâ
dpgettext(domain: string, context: string, message: string, ...arguments: string[]): string
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
domain | string | No | Specifies the translation domain to use. |
context | string | No | Specifies the translation context. |
message | string | No | Specifies the message to translate. |
arguments | string[] | Yes | Optional string arguments which can be referenced in the message using the percent sign followed by the argument index %n . The first argument is referenced with %1 . |
Return valueâ
Returns the translated message.
đ§ gettext
â
Translates a message.
This function uses the global translation namespace (L10n.Namespace.global
) and is a shorthand for L10n.Namespace.global.gettext
.
Signatureâ
gettext(message: string, ...arguments: string[]): string
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
message | string | No | Specifies the message to translate. |
arguments | string[] | Yes | Optional string arguments which can be referenced in the message using the percent sign followed by the argument index %n . The first argument is referenced with %1 . |
Return valueâ
Returns the translated message.
đ§ ngettext
â
Translates a plural message.
This function uses the global translation namespace (L10n.Namespace.global
) and is a shorthand for L10n.Namespace.global.ngettext
.
Signatureâ
ngettext(
message: string,
messagePlural: string,
count: number,
...arguments: string[]
): string
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
message | string | No | Specifies the message to translate. |
messagePlural | string | No | Specifies the plural message to translate. |
count | number | No | Specifies the count for the plural (can be reference in the message with %1 ). |
arguments | string[] | Yes | Optional string arguments which can be referenced in the message using the percent sign followed by the argument index %n . The count value is automatically included as the first argument (%1 ). |
Return valueâ
Returns the translated message.
Exampleâ
import { L10n } from "@tripetto/runner";
// Outputs `1 car` to the console.
console.log(L10n.ngettext("1 car", "%1 cars", 1));
// Outputs `2 cars` to the console.
console.log(L10n.ngettext("1 car", "%1 cars", 2));
đ§ npgettext
â
Translates a plural message with the specified context.
This function uses the global translation namespace (L10n.Namespace.global
) and is a shorthand for L10n.Namespace.global.npgettext
.
Signatureâ
npgettext(
context: string,
message: string,
messagePlural: string,
count: number,
...arguments: string[]
): string
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
context | string | No | Specifies the translation context. |
message | string | No | Specifies the message to translate. |
messagePlural | string | No | Specifies the plural message to translate. |
count | number | No | Specifies the count for the plural (can be reference in the message with %1 ). |
arguments | string[] | Yes | Optional string arguments which can be referenced in the message using the percent sign followed by the argument index %n . The count value is automatically included as the first argument (%1 ). |
Return valueâ
Returns the translated message.
đ§ pgettext
â
Translates a message with the specified context.
This function uses the global translation namespace (L10n.Namespace.global
) and is a shorthand for L10n.Namespace.global.pgettext
.
Signatureâ
pgettext(context: string, message: string, ...arguments: string[]): string
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
context | string | No | Specifies the translation context. |
message | string | No | Specifies the message to translate. |
arguments | string[] | Yes | Optional string arguments which can be referenced in the message using the percent sign followed by the argument index %n . The first argument is referenced with %1 . |
Return valueâ
Returns the translated message.
âī¸ Interfacesâ
đ IDomain
â
Describes the interface for the domain object.
Type declarationâ
interface IDomain { locale: string;Readonly language: string;Readonly native: string;Readonly }
đˇī¸ locale
â
Specifies the locale (language[_territory]
).
Typeâ
string
đˇī¸ language
â
Specifies the language in english.
Typeâ
string
đˇī¸ native
â
Specifies the language in the native language.
Typeâ
string
đ ILocale
â
Describes the interface for the locale object. Locale information is stored in a JSON file per locale and are stored in the runner/locales folder of each stock runner package.
Type declarationâ
interface ILocale {
locale: string;
domain: string;
direction: "ltr" | "rtl";
countryCode: string;
country: string;
countryNative: string;
language: string;
languageNative: string;
translations: {
months: {
formatted: {
abbreviated: string[];
narrow: string[];
wide: string[];
};
nominative: {
abbreviated: string[];
narrow: string[];
wide: string[];
};
};
days: {
formatted: {
abbreviated: string[];
narrow: string[];
short: string[];
wide: string[];
};
nominative: {
abbreviated: string[];
narrow: string[];
short: string[];
wide: string[];
};
};
time: {
AM: string;
PM: string;
};
};
formats: {
date: {
full: string;
long: string;
medium: string;
short: string;
};
time: {
full: string;
long: string;
medium: string;
short: string;
};
dateTime: {
full: string;
long: string;
medium: string;
short: string;
};
numbers: {
decimals: string;
grouping: string;
minus: string;
};
};
}
đ Typesâ
đ TTranslation
â
Defines a translation.
Typeâ
{
"": {
language?: string;
"plural-forms"?: string;
"plural-family"?: string;
};
} & {
[id: string]: [null | string, ...string[]] | [null | string, [string]];
}