language() declares one language of the bot, from any file of src/. It takes one object, LanguageConfig, whose locale is the language.
src/messages/en-US.ts
How to write the files and which language
t speaks is in the
guide. This page lists what exists.language()
src/; locale says which language: every handler then receives t, which gives a text in the language of who will read the message, with its {placeholders} filled in. A language may be declared in several places: the texts of a feature next to it, with the same locale, add to the others.
LanguageConfig
What a file gives tolanguage().
Whether this is the language used when the one of a person or of a server is
not declared. Exactly one language says so; with one language, it goes
without saying. When another language already says it, this is refused:
only one can be the default. Once the files ran (
chapterjs dev, chapterjs build), a second language saying so is a type error on the default: true
of both (see ProjectLanguageDefaults).What the bot answers by itself in this language, when it can’t run what was
asked: the phrases of
FrameworkTexts, the ones this file wants to translate.
The others stay in English.MessageTexts
MessageText
{placeholders}, or a text with several forms, picked by count.
PluralText
A text with several forms, one per quantity:t('members', { count }) picks the form of the language for that number (one for 1 in English, other for the rest; French, Russian or Arabic have others). other is always there; the forms a language does not use are left out. {count} in a form is the number itself.
For 0, in every language; and where a language has a form of its own for other numbers too (Arabic, Latvian).
FrameworkTexts
What the bot answers by itself, when it can’t run what was asked: where a command or a component can’t be used, a button of an old message, arun that failed… Every phrase has an English version; a language file gives its own in framework, the ones it wants. {what} is the word for what was used: command, button, menu or form, given here too.
CommandsTranslations
'ping', 'mod ban'), its name, description, options and choices in that language, as the locales of a command file take them (CommandTranslation). The editor offers the commands of the project that have no description in their file (one that has owns its texts, locales included); their options and choices are checked when the files load.
ProjectCommands
The commands of the project, as the editor sees them: the name of each command,true when the language files describe it, false when the command has its own description. Filled in by the .chapterjs/ folder of the project, so that the commands of a language file offers the ones it may translate. The options and choices are checked when the files load.
ProjectLanguageDefaults
The languages that saydefault: true when more than one does, as the editor sees them: one key per language. Filled in by the .chapterjs/ folder of the project, so that each of them is underlined; empty when at most one language says it.
LanguageDeclaration
Whatlanguage() returns: a declaration the framework finds in the exports of a file.
Translator
t, as handlers receive it: gives a text of the language files in the language of who will read the message, with its placeholders filled in. M is the texts of the default language, which types the keys and the params: a text another language does not have is taken from it.
t()
in()
t.in('fr', 'welcome', { name }), or t.in(owner.locale, 'pong'). The language of the person who will read it, when it is not the one t speaks.
t for another language, to write several texts: t.in('fr')('welcome', { name }).
ProjectLocales
The languages of the project, as the editor sees them: one key per language declared. Filled in by the.chapterjs/ folder of the project, empty when the project has no language.
ProjectLocale
'en-US', 'fr'…
LocaleGiven
t.in(): the editor offers the ones of the project, and any language of Discord is accepted (the one of a person, of a server), t then taking the closest one declared. A word that is no language of Discord is underlined, with the ones of the project.
TranslationContext
TranslationContext is what every handler receives when the project has a language: t. Nothing otherwise.
ProjectMessages
The texts of the project, as the editor sees them: the keyst accepts and the placeholders of each, from every declaration of every language, the default language first. Filled in by the .chapterjs/ folder of the project when it has a language, empty otherwise.
MergedMessages
t is typed from when a project has several languages, the default one first, then the others (a text the default language does not have is taken from the language that has it).
MessagesOf
t is typed from, for a language file: its texts.
The texts of a component
DynamicText
t and the data of the component.
TextContext
What a text of a component is computed from when it is a function:t in the language of who will read the message, and the data the component carries.
Placeholders
Placeholders
'Hello {name}' has 'name'. Written between braces, a placeholder is a name made of letters, digits and _; {{ and }} are braces written as is. A plural has count, and the placeholders of its forms.
ParamsOf
t takes for a text: one value per placeholder, or nothing when the text has none. A number is written the way the language writes numbers (1,234 in English, 1 234 in French): give a text to keep it as is. The count of a plural is a number.
ParamsArgs
t after the key: the params, only when there are some.
Discord documentation