Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is separated into 3 commits for easier review.
1. Add hints for
TranslationThere are two problems.
First, whether a message in
Translationshould be translated usingget_message()orget_plural_message()depends on whether it was added usingadd_message()oradd_plural_message(). But there is currently no way to know that information in code.Second, even if we record the source of the message when adding it, we still cannot properly call
get_plural_message(): The plural form of the source text remains unknown. This also means that we can't reliably restore aTranslationloaded from PO files back to a PO file. For example, #106573 attempts to convert PO files to MO files on export, but it has to write?for themsgid_pluralfield, which is technically wrong.Considering godotengine/godot-proposals#7334, it'll also be better if metadata like comments and locations can be stored along with the message. The long-term goal is to make PO, CSV, and
Translationinterchangeable.This PR added
{get,set}_hint()for storing hints like untranslated plural, comments, and locations (references to the program's source code).How a
Translationis serialized to a dictionary (_{get,set}_messages()) is also updated:For messages, keys can be either:
&"msgid"[&"&msgctxt", &"msgid"]Their values can be either:
&"msgstr[0]"[&"msgstr[0], &"msgstr[1]", ...]The optional hints are stored using an integer key. The value is another dictionary, mapping message keys to a hints dictionary which maps
HINT_*to the hint value. Empty values are not stored for hints.This makes the format compact. And it's still compatible with older versions as long as new features (context, plural forms, and hints) are not used.
2. Use plural hint when importing/exporting
TranslationsWhen importing CSV files and loading PO files,
HINT_PLURALis now set. For exisitng projects,.csvfiles have to be reimported to get this hint.When generating the translation template, the parse result is now a
Translationinstead of a vector of custom structs. This lays the foundation to adding template generation related APIs in the future (for problems like #111074).When implementing, I also fixed some problems about the
TranslationAPIs:has_message()get_message_list()to yieldMessageKeys instead ofStringNames. The scripting API version concatsmsgidandmsgctxtfor compatibility.Usages of other hints (comments and locations) are not added in this PR. I think that should be done in separate ones.
3. Add translation viewer
Currently, the inspector only shows
LocaleandPlural Rules OverrideforTranslations. This commit adds a View Messages button for inspecting contents in the resource.This makes it easier to debug translation related problems and dogfoods the new API.
Peek.2025-11-13.17-05.mp4
*The screencast is using the Classic style theme.
Trees don't have frames when using the modern style theme, which makes many editor UI look broken :(When implementing, I also added
get_plural_forms()toTranslationfor getting all possible plural forms for a given message.Test project: translation-hints.zip