Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

How to language

Elias Schaut edited this page Nov 28, 2021 · 3 revisions

Add a language

  1. Create a JSON file in folder lang and name it text_<lang>.json
  2. Copy json from another language file and translate it
  3. Edit lang_paths in config file

Use a language

Access language manager with one of this options:

  1. await require("../../lang/lang_helper").get_text(message, <key>)
  2. await message.client.lang_helper.get_text(message, <key>)
  3. await client.lang_helper.get_text(message, <key>)

The <key> stands for the key in a language file.
The function returns the string from the correct language file from the user. If the database has no language information about the user, it will take the default language (which is set in the conifg file).
(The message object must be submitted because its important for choosing the correct language and access important funtions)

Special symbols

If you want to insert something into a text that is not known until runtime, you can do this using special characters used in this project:

  • Write %<index> in lang-element for the gap on the i-th positions
  • Call the function get_text with the needed inserts, but be careful, the order is important

Example

Lang-File:

"text": "Here is the number %1 and also the number %0"

Method-Call:

await msg.client.lang.get_text(msg, text, 42, 420)
// returns "Here is the number 420 and also the number 42"
Clone this wiki locally