-
-
Notifications
You must be signed in to change notification settings - Fork 20.9k
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
Reorder parameters in tr_n
and related methods
#66292
Conversation
editor/translations/extract.py
Outdated
@@ -109,10 +109,10 @@ class ExtractType(enum.IntEnum): | |||
re.compile(r'TTR\("(?P<message>([^"\\]|\\.)*)"(, "(?P<context>([^"\\]|\\.)*)")?\)'): ExtractType.TEXT, | |||
re.compile(r'TTRC\("(?P<message>([^"\\]|\\.)*)"\)'): ExtractType.TEXT, | |||
re.compile( | |||
r'TTRN\("(?P<message>([^"\\]|\\.)*)", "(?P<plural_message>([^"\\]|\\.)*)",[^,)]+?(, "(?P<context>([^"\\]|\\.)*)")?\)' | |||
r'TTRN\([^,]+?, "(?P<message>([^"\\]|\\.)*)", "(?P<plural_message>([^"\\]|\\.)*)"(, "(?P<context>([^"\\]|\\.)*)")?\)' |
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.
For TTRN()
, RTRN()
, DTRN()
I think plural_message
should be left required? (Otherwise, this regular expression also needs to be corrected.)
This PR does not break compatibility with 3.x, but breaks with 4.0 beta 3. |
I can see the original intention of reordering parameters: in order to make But what's the reason for making tr_n("%d day ago", "%d days ago", days) # As regular text.
tr_n("DAYS_AGO", "DAYS_AGO", days) # Repeat the identifier: this is also confusing when extracted to POT.
# Make a wrapper to avoid repeating yourself.
func tr_identifier(identifier: String, n: int) -> StringName:
return tr_n(identifier, identifier, n)
|
This is less convenient because GDScript does not support user-defined global functions. It will be at least
Compliance with standards is good, but is it really that important in this case? Should we follow the standard if it's less convenient? I think those who are used to the order of arguments in At the same time, those who use CSV and perhaps don't know about |
Yeah, compliance with standards is good to have but not a requirement. We already merged the context feature from My main argument is that Threre will still be problems after reordering the parameters. For example, if we were to implement context support for CSV files, users still have to write something like I think it's better to use a wrapper function for translating identifiers. |
Yes, it looks more readable with original strings than with IDs. But in my experience, a lot of people use
Context is needed to disambiguate when the same phrase in the source language is translated into several different phrases depending on the context. However, IDs must initially be unique, the context is included in the ID name. Therefore, this scenario seems impossible in practice. (It should be
The wrapper function is one of the possible solutions to the problem, but it's less convenient to use at the moment, due to the limitations of GDScript. Also, if we can make the standard function more convenient, that looks like a better solution, I think. |
38d041c
to
86979c2
Compare
This PR breaks compatibility with 4.0 beta, add the label please. |
Make `n` parameter first and `plural_message` optional in the following methods: * `Object.tr_n()`; * `Translation._get_plural_message()` (only order); * `Translation.get_plural_message()`; * `TranslationServer.translate_plural()`; * `TranslationServer::tool_translate_plural()`; * `TranslationServer::doc_translate_plural()`; * `TTRN()`, `RTRN()`, `DTRN()`.
Waiting for Godot 5. :| |
Make
n
parameter first andplural_message
optional in the following methods:Object.tr_n()
;Translation._get_plural_message()
(only order);Translation.get_plural_message()
;TranslationServer.translate_plural()
;TranslationServer::tool_translate_plural()
;TranslationServer::doc_translate_plural()
;TTRN()
,RTRN()
,DTRN()
.When using translations based on identifiers, the
plural_message
parameter is not needed, so it makes sense to make then
parameter first andplural_message
optional. In my opinion, this is logical and convenient, since then
parameter is "the most required" parameter in thetr_n
function.These changes are in PR #41519, but it's very likely that #41519 might not make it into the 4.0 release. This PR will avoid breaking compatibility if #41519 is implemented later. Also, it will be useful if someone decides to implement a custom translation format based on identifiers (it's possible, i'm going to implement my format instead of CSV).