:github_url: hide .. _class_Translation: Translation =========== **Успадковує:** :ref:`Resource` **<** :ref:`RefCounted` **<** :ref:`Object` **Успадковано від:** :ref:`OptimizedTranslation` Переклад мови, що відображає збір рядків до окремих перекладів. .. rst-class:: classref-introduction-group Опис -------- **Translation** maps a collection of strings to their individual translations, and also provides convenience methods for pluralization. A **Translation** consists of messages. A message is identified by its context and untranslated string. Unlike `gettext `__, using an empty context string in Godot means not using any context. .. rst-class:: classref-introduction-group Посібники ------------------ - :doc:`Інтернаціоналізація ігор <../tutorials/i18n/internationalizing_games>` - :doc:`Локалізація за допомогою gettext <../tutorials/i18n/localization_using_gettext>` - :doc:`Локальні <../tutorials/i18n/locales>` .. rst-class:: classref-reftable-group Властивості ---------------------- .. table:: :widths: auto +-----------------------------+--------------------------------------------------------------------------------+----------+ | :ref:`String` | :ref:`locale` | ``"en"`` | +-----------------------------+--------------------------------------------------------------------------------+----------+ | :ref:`String` | :ref:`plural_rules_override` | ``""`` | +-----------------------------+--------------------------------------------------------------------------------+----------+ .. rst-class:: classref-reftable-group Методи ------------ .. table:: :widths: auto +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`StringName` | :ref:`_get_message`\ (\ src_message\: :ref:`StringName`, context\: :ref:`StringName`\ ) |virtual| |const| | +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`StringName` | :ref:`_get_plural_message`\ (\ src_message\: :ref:`StringName`, src_plural_message\: :ref:`StringName`, n\: :ref:`int`, context\: :ref:`StringName`\ ) |virtual| |const| | +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`add_message`\ (\ src_message\: :ref:`StringName`, xlated_message\: :ref:`StringName`, context\: :ref:`StringName` = &""\ ) | +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`add_plural_message`\ (\ src_message\: :ref:`StringName`, xlated_messages\: :ref:`PackedStringArray`, context\: :ref:`StringName` = &""\ ) | +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`erase_message`\ (\ src_message\: :ref:`StringName`, context\: :ref:`StringName` = &""\ ) | +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`StringName` | :ref:`get_message`\ (\ src_message\: :ref:`StringName`, context\: :ref:`StringName` = &""\ ) |const| | +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_message_count`\ (\ ) |const| | +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PackedStringArray` | :ref:`get_message_list`\ (\ ) |const| | +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`StringName` | :ref:`get_plural_message`\ (\ src_message\: :ref:`StringName`, src_plural_message\: :ref:`StringName`, n\: :ref:`int`, context\: :ref:`StringName` = &""\ ) |const| | +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PackedStringArray` | :ref:`get_translated_message_list`\ (\ ) |const| | +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Описи властивостей ------------------------------------ .. _class_Translation_property_locale: .. rst-class:: classref-property :ref:`String` **locale** = ``"en"`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_locale**\ (\ value\: :ref:`String`\ ) - :ref:`String` **get_locale**\ (\ ) Місце перекладу. .. rst-class:: classref-item-separator ---- .. _class_Translation_property_plural_rules_override: .. rst-class:: classref-property :ref:`String` **plural_rules_override** = ``""`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_plural_rules_override**\ (\ value\: :ref:`String`\ ) - :ref:`String` **get_plural_rules_override**\ (\ ) The plural rules string to enforce. See `GNU gettext `__ for examples and more info. If empty or invalid, default plural rules from :ref:`TranslationServer.get_plural_rules()` are used. The English plural rules are used as a fallback. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Описи методів -------------------------- .. _class_Translation_private_method__get_message: .. rst-class:: classref-method :ref:`StringName` **_get_message**\ (\ src_message\: :ref:`StringName`, context\: :ref:`StringName`\ ) |virtual| |const| :ref:`🔗` Віртуальний метод для перевизначення :ref:`get_message()`. .. rst-class:: classref-item-separator ---- .. _class_Translation_private_method__get_plural_message: .. rst-class:: classref-method :ref:`StringName` **_get_plural_message**\ (\ src_message\: :ref:`StringName`, src_plural_message\: :ref:`StringName`, n\: :ref:`int`, context\: :ref:`StringName`\ ) |virtual| |const| :ref:`🔗` Віртуальний метод перевизначення :ref:`get_plural_message()`. .. rst-class:: classref-item-separator ---- .. _class_Translation_method_add_message: .. rst-class:: classref-method |void| **add_message**\ (\ src_message\: :ref:`StringName`, xlated_message\: :ref:`StringName`, context\: :ref:`StringName` = &""\ ) :ref:`🔗` Додає повідомлення, якщо не існує, слідуючи його перекладом. Додатковий контекст може бути використаний для визначення контексту перекладу або диференціації полісемічних слів. .. rst-class:: classref-item-separator ---- .. _class_Translation_method_add_plural_message: .. rst-class:: classref-method |void| **add_plural_message**\ (\ src_message\: :ref:`StringName`, xlated_messages\: :ref:`PackedStringArray`, context\: :ref:`StringName` = &""\ ) :ref:`🔗` Adds a message involving plural translation if nonexistent, followed by its translation. An additional context could be used to specify the translation context or differentiate polysemic words. .. rst-class:: classref-item-separator ---- .. _class_Translation_method_erase_message: .. rst-class:: classref-method |void| **erase_message**\ (\ src_message\: :ref:`StringName`, context\: :ref:`StringName` = &""\ ) :ref:`🔗` Здає повідомлення. .. rst-class:: classref-item-separator ---- .. _class_Translation_method_get_message: .. rst-class:: classref-method :ref:`StringName` **get_message**\ (\ src_message\: :ref:`StringName`, context\: :ref:`StringName` = &""\ ) |const| :ref:`🔗` Повернення перекладу повідомлення. .. rst-class:: classref-item-separator ---- .. _class_Translation_method_get_message_count: .. rst-class:: classref-method :ref:`int` **get_message_count**\ (\ ) |const| :ref:`🔗` Повертає кількість наявних повідомлень. .. rst-class:: classref-item-separator ---- .. _class_Translation_method_get_message_list: .. rst-class:: classref-method :ref:`PackedStringArray` **get_message_list**\ (\ ) |const| :ref:`🔗` Returns the keys of all messages, that is, the context and untranslated strings of each message. \ **Note:** If a message does not use a context, the corresponding element is the untranslated string. Otherwise, the corresponding element is the context and untranslated string separated by the EOT character (``U+0004``). This is done for compatibility purposes. :: for key in translation.get_message_list(): var p = key.find("\u0004") if p == -1: var untranslated = key print("Message %s" % untranslated) else: var context = key.substr(0, p) var untranslated = key.substr(p + 1) print("Message %s with context %s" % [untranslated, context]) .. rst-class:: classref-item-separator ---- .. _class_Translation_method_get_plural_message: .. rst-class:: classref-method :ref:`StringName` **get_plural_message**\ (\ src_message\: :ref:`StringName`, src_plural_message\: :ref:`StringName`, n\: :ref:`int`, context\: :ref:`StringName` = &""\ ) |const| :ref:`🔗` Повертає переклад повідомлення, що містить форми множини. Число ``n`` – це номер або кількість об'єкта множини. Воно використовуватиметься для того, щоб система перекладу знайшла правильну форму множини для вибраної мови. \ **Примітка:** Форми множини підтримуються лише в :doc:`перекладах на основі gettext (PO) <../tutorials/i18n/localization_using_gettext>`, а не в CSV. .. rst-class:: classref-item-separator ---- .. _class_Translation_method_get_translated_message_list: .. rst-class:: classref-method :ref:`PackedStringArray` **get_translated_message_list**\ (\ ) |const| :ref:`🔗` Returns all the translated strings. .. |virtual| replace:: :abbr:`virtual (Зазвичай, цей метод перевизначається користувачем, щоб він мав вплив.)` .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)` .. |const| replace:: :abbr:`const (Цей метод не має побічних ефектів. Не змінює ніяку змінну екземпляра об'єкта.)` .. |vararg| replace:: :abbr:`vararg (Цей метод приймає будь-яке число аргументів після описаних тут.)` .. |constructor| replace:: :abbr:`constructor (Цей метод використовується для побудови типів.)` .. |static| replace:: :abbr:`static (Цей метод не потребує екземпляра для виклику, його можна викликати безпосередньо за допомогою назви класу.)` .. |operator| replace:: :abbr:`operator (Цей метод описує дійсний оператор для взаємодії з цим типом як з лівим операндом.)` .. |bitfield| replace:: :abbr:`BitField (Це значення є цілим числом, складеним у вигляді бітової маски з наступних прапорів.)` .. |void| replace:: :abbr:`void (Значення не повертається.)`