translations.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. ---@meta
  2. ---Translations
  3. ---------------
  4. -- A simple wrapper around `minetest.translate`.
  5. --
  6. -- It is equivalent to `minetest.translate(textdomain, str, ...)`.
  7. --
  8. -- It is intended to be used in the following way, so that it avoids verbose
  9. -- repetitions of `minetest.translate`:
  10. --
  11. -- ```lua
  12. -- local S = minetest.get_translator(textdomain)
  13. -- S(str, ...)
  14. -- ```
  15. ---@param textdomain string
  16. ---@return mt.Translator
  17. ---@nodiscard
  18. function minetest.get_translator(textdomain) end
  19. -- Translates strings with the given `textdomain` for disambiguation.
  20. --
  21. -- Strings that need to be translated can contain several escapes,
  22. -- preceded by `@`.
  23. --
  24. -- - `@@` acts as a literal `@`.
  25. -- - `@n`, where `n` is a digit between 1 and 9, is an argument for the translated
  26. -- string that will be inlined when translated. Due to how translations are
  27. -- implemented, the original translation string **must** have its arguments in
  28. -- increasing order, without gaps or repetitions, starting from 1.
  29. -- - `@=` acts as a literal `=`. It is not required in strings given to
  30. -- `minetest.translate`, but is in translation files to avoid being confused with
  31. -- the `=` separating the original from the translation.
  32. -- - `@\n` (where the `\n` is a literal newline) acts as a literal newline. As with
  33. -- `@=`, this escape is not required in strings given to `minetest.translate`,
  34. -- but is in translation files.
  35. -- - `@n` acts as a literal newline as well.
  36. --
  37. -- The textdomain must match the
  38. -- textdomain specified in the translation file in order to get the string
  39. -- translated. This can be used so that a string is translated differently in
  40. -- different contexts. It is advised to use the name of the mod as textdomain
  41. -- whenever possible, to avoid clashes with other mods. This function must be
  42. -- given a number of arguments equal to the number of arguments the translated
  43. -- string expects. Arguments are literal strings -- they will not be translated,
  44. -- so if you want them to be, they need to come as outputs of
  45. -- `minetest.translate` as well.
  46. --
  47. -- For instance, suppose we want to translate "@1 Wool" with "@1" being replaced
  48. -- by the translation of "Red". We can do the following:
  49. --
  50. -- local S = minetest.get_translator()
  51. -- S("@1 Wool", S("Red"))
  52. --
  53. -- This will be displayed as "Red Wool" on old clients and on clients that do not
  54. -- have localization enabled. However, if we have for instance a translation file
  55. -- named `wool.fr.tr` containing the following:
  56. --
  57. -- @1 Wool=Laine @1
  58. -- Red=Rouge
  59. --
  60. -- This will be displayed as "Laine Rouge" on clients with a French locale.
  61. ---@alias mt.Translator fun(...: string): string
  62. ---@param textdomain string
  63. ---@param ... string
  64. ---@return string
  65. ---@nodiscard
  66. function minetest.translate(textdomain, ...) end
  67. ---@alias mt.LangCode
  68. ---| "be"
  69. ---| "bg"
  70. ---| "ca"
  71. ---| "cs"
  72. ---| "da"
  73. ---| "de"
  74. ---| "el"
  75. ---| "en"
  76. ---| "eo"
  77. ---| "es"
  78. ---| "et"
  79. ---| "eu"
  80. ---| "fi"
  81. ---| "fr"
  82. ---| "gd"
  83. ---| "gl"
  84. ---| "hu"
  85. ---| "id"
  86. ---| "it"
  87. ---| "ja"
  88. ---| "jbo"
  89. ---| "kk"
  90. ---| "ko"
  91. ---| "lt"
  92. ---| "lv"
  93. ---| "ms"
  94. ---| "nb"
  95. ---| "nl"
  96. ---| "nn"
  97. ---| "pl"
  98. ---| "pt"
  99. ---| "pt_BR"
  100. ---| "ro"
  101. ---| "ru"
  102. ---| "sk"
  103. ---| "sl"
  104. ---| "sr_Cyrl"
  105. ---| "sr_Latn"
  106. ---| "sv"
  107. ---| "sw"
  108. ---| "tr"
  109. ---| "uk"
  110. ---| "vi"
  111. ---| "zh_CN"
  112. ---| "zh_TW"
  113. --[[ **Server side translations**
  114. On some specific cases, server translation could be useful. For example, filter
  115. a list on labels and send results to client. A method is supplied to achieve
  116. that:
  117. `minetest.get_translated_string(lang_code, string)`: Translates `string` using
  118. translations for `lang_code` language. It gives the same result as if the string
  119. was translated by the client.
  120. The `lang_code` to use for a given player can be retrieved from the table
  121. returned by `minetest.get_player_information(name)`.
  122. IMPORTANT: This functionality should only be used for sorting, filtering or
  123. similar purposes. You do not need to use this to get translated strings to show
  124. up on the client.
  125. ]]
  126. ---@param lang_code mt.LangCode
  127. ---@param string string
  128. ---@return string
  129. ---@nodiscard
  130. function minetest.get_translated_string(lang_code, string) end