Skip to content
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

Merged
merged 7 commits into from
Oct 3, 2019

Conversation

Qrox
Copy link
Contributor

@Qrox Qrox commented Oct 1, 2019

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 and mtype 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.

"name": { "ctxt": "foo", "str": "bar", "str_pl": "baz" }

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 new make_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:

"name": {
  "//~": "as in foobar",
  "str": "bar"
}

To fix #34263, itype and mtype 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 for itype and mtype. 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.

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
Copy link
Contributor

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++.

@ZhilkinSerg ZhilkinSerg added [C++] Changes (can be) made in C++. Previously named `Code` Translation I18n labels Oct 1, 2019
@cainiaowu
Copy link
Contributor

There is one more duplicate name of "planter", one is vehicle part and the other is a plant box.

@Qrox
Copy link
Contributor Author

Qrox commented Oct 2, 2019

@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.

@Qrox Qrox changed the title Support plural string in the translation class Support plural string in the translation class and JSON translator comments Oct 2, 2019
@ZhilkinSerg ZhilkinSerg merged commit 54ed0b4 into CleverRaven:master Oct 3, 2019
@Qrox Qrox deleted the translation-plural branch October 4, 2019 04:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Translation I18n
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"pike" is ambiguous
4 participants