Skip to main content

L10n module

๐Ÿ“– Descriptionโ€‹

The L10n module contains functions for localization. Tripetto uses the GNU gettext system.

๐Ÿ‘ฉโ€๐Ÿ’ป Exampleโ€‹

import { L10n } from "@tripetto/builder";

// 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);

๐Ÿ—ƒ๏ธ Propertiesโ€‹


๐Ÿท๏ธ currentโ€‹

Retrieves the current translation domain (this is the ISO 639-1 language code of the domain).

Typeโ€‹

string


๐Ÿท๏ธ domainsโ€‹

Retrieves a list of all available translation domains.

Typeโ€‹

string[]


๐Ÿท๏ธ localeโ€‹

Retrieves a reference to the Locales instance that holds the locale information.

Typeโ€‹

Locales

โ–ถ๏ธ Functionsโ€‹


๐Ÿ”ง _โ€‹

Translates a message (short for gettext).

Signatureโ€‹

_(message: string, ...arguments: string[]): string

Parametersโ€‹

NameTypeOptionalDescription
messagestringNoSpecifies the message to translate.
argumentsstring[]YesOptional 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).

Signatureโ€‹

_n(message: string, messagePlural: string, count: number, ...arguments: string[]): string

Parametersโ€‹

NameTypeOptionalDescription
messagestringNoSpecifies the message to translate.
messagePluralstringNoSpecifies the plural message to translate.
countnumberNoSpecifies the count for the plural (can be reference in the message with %1).
argumentsstring[]YesOptional 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.


๐Ÿ”ง dgettextโ€‹

Translates a message using the specified translation domain.

Signatureโ€‹

dgettext(domain: string, message: string, ...arguments: string[]): string

Parametersโ€‹

NameTypeOptionalDescription
domainstringNoSpecifies the translation domain to use.
messagestringNoSpecifies the message to translate.
argumentsstring[]YesOptional 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.

Signatureโ€‹

dngettext(
domain: string,
message: string,
messagePlural: string,
count: number,
...arguments: string[]
): string

Parametersโ€‹

NameTypeOptionalDescription
domainstringNoSpecifies the translation domain to use.
messagestringNoSpecifies the message to translate.
messagePluralstringNoSpecifies the plural message to translate.
countnumberNoSpecifies the count for the plural (can be reference in the message with %1).
argumentsstring[]YesOptional 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.

Signatureโ€‹

dnpgettext(
domain: string,
context: string,
message: string,
messagePlural: string,
count: number,
...arguments: string[]
): string

Parametersโ€‹

NameTypeOptionalDescription
domainstringNoSpecifies the translation domain to use.
contextstringNoSpecifies the translation context.
messagestringNoSpecifies the message to translate.
messagePluralstringNoSpecifies the plural message to translate.
countnumberNoSpecifies the count for the plural (can be reference in the message with %1).
argumentsstring[]YesOptional 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.

Signatureโ€‹

dpgettext(domain: string, context: string, message: string, ...arguments: string[]): string

Parametersโ€‹

NameTypeOptionalDescription
domainstringNoSpecifies the translation domain to use.
contextstringNoSpecifies the translation context.
messagestringNoSpecifies the message to translate.
argumentsstring[]YesOptional 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.

Signatureโ€‹

gettext(message: string, ...arguments: string[]): string

Parametersโ€‹

NameTypeOptionalDescription
messagestringNoSpecifies the message to translate.
argumentsstring[]YesOptional 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.

Signatureโ€‹

ngettext(
message: string,
messagePlural: string,
count: number,
...arguments: string[]
): string

Parametersโ€‹

NameTypeOptionalDescription
messagestringNoSpecifies the message to translate.
messagePluralstringNoSpecifies the plural message to translate.
countnumberNoSpecifies the count for the plural (can be reference in the message with %1).
argumentsstring[]YesOptional 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.


๐Ÿ”ง npgettextโ€‹

Translates a plural message with the specified context.

Signatureโ€‹

npgettext(
context: string,
message: string,
messagePlural: string,
count: number,
...arguments: string[]
): string

Parametersโ€‹

NameTypeOptionalDescription
contextstringNoSpecifies the translation context.
messagestringNoSpecifies the message to translate.
messagePluralstringNoSpecifies the plural message to translate.
countnumberNoSpecifies the count for the plural (can be reference in the message with %1).
argumentsstring[]YesOptional 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.

Signatureโ€‹

pgettext(context: string, message: string, ...arguments: string[]): string

Parametersโ€‹

NameTypeOptionalDescription
contextstringNoSpecifies the translation context.
messagestringNoSpecifies the message to translate.
argumentsstring[]YesOptional 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โ€‹


๐Ÿ”— ILocaleโ€‹

Describes the interface for the locale object. Locale information is stored in a JSON file per locale and are stored in the locales folder of the Tripetto Builder 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]];
}