-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support plural string in the translation class and JSON translator comments #34365
Conversation
doc/JSON_INFO.md
Outdated
"id" : "socks", // Unique ID. Must be one continuous word, use underscores if necessary | ||
"name" : "socks", // The name appearing in the examine box. Can be more than one word separated by spaces | ||
"name_plural" : "pairs of socks", // (Optional) | ||
```JSON |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments look better with C++.
There is one more duplicate name of "planter", one is vehicle part and the other is a plant box. |
@cainiaowu I searched for "planter" but only a furniture with that name showed up. There's only a vehicle part with the "PLANTER" flag, but there isn't a vehicle part with such a name. Edit: I found the string in the c++ code. In that case it can be fixed by specifying a context in the c++ code. |
Summary
SUMMARY: I18N "Support plural strings in the translation class"
Purpose of change
Fixes #34263. Adds plural string support to the translation class, and updates
itype
andmtype
to use it. While I was at it I also added support for translator comments in the JSON files, which were present in the JSON files but were not actually extracted.Describe the solution
Plural support is added to the translation class, and a new constructor and two factory functions are added to construct plural translation objects. Plural translation objects are translated by passing a number to the
translated()
method.Due to the fact that singular and plural names need to have the same context, the syntax to specify plural names is changed. The new syntax is as follows.
In the above code,
"str_pl"
is an optional plural string, that is supported if the corresponding translation object is constructed using the new constructor or factory functions, or converted using the newmake_plural()
method, prior to reading the translation object from JSON. This is because"str_pl"
is optional, so there needs to be a way to specify whether a plural form is needed.One can also now add comments for translators using the following syntax, to JSON strings already supporting the context/plural syntax:
To fix #34263,
itype
andmtype
now uses the updated translation class, and the ambiguous names reported in that issue are now marked with contexts respectively. The old format of specifying the plural form using"name_plural"
is still supported foritype
andmtype
. The string extraction scripts are also updated. I also fixed a missing comma in the JSON string extraction script that was preventing the correct extraction of many plural monster names.Finally, the clang-tidy checks are updated to also test for the new translation functions, and the documentations are updated to reflect the new translation class and JSON syntax.