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

Add CSV plural support #41519

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SkyLucilfer
Copy link
Contributor

@SkyLucilfer SkyLucilfer commented Aug 25, 2020

Added CSV plural support, as requested by this proposal godotengine/godot-proposals#1291.

Usage:

It functions like how the proposal describes. Some key notes:

  • tr_n() now accepts arguments in the form of tr_n(n, message, plural_message = "", context = "").

  • Plural translation using CSV should leave out plural_message and context parameters as they aren't used during the translation (which explains the reordering of the parameters).

  • How it works: tr_n(n, "KEY") will fetch the correct plural translation from the CSV using adjusted key, i.e. KEY[0], KEY[1] etc. depending on the current locale and n. The system will concatenate the KEY with appropriate subscript for us.

Condition

Because of how the concatenation works, in the CSV users should append [0], [1] and so on for keys mapping plurals for it to work. This is the contract. Examples can be seen in the proposal.

Note for PO users:

Users using PO files to translate will still have to fill in the plural_message field, as PO files expect to have the plural message data (I have documented this in the class reference too). The context parameter is optional.

Test project:

test_project.zip

@dalexeev
Copy link
Member

What is the status of this PR?

@akien-mga akien-mga modified the milestones: 4.0, 4.x Jul 28, 2022
@akien-mga akien-mga removed the request for review from bojidar-bg July 28, 2022 16:03
@akien-mga akien-mga requested review from akien-mga and removed request for vnen July 28, 2022 16:03
@timothyqiu
Copy link
Member

Putting String(p_src_text) + "[" + String::num_int64(index) + "]" inside various translation classes looks like a hack to me. Since CSV translation uses OptimizedTranslation, I think it's better to implement proper plural handling for that class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants