Skip to content

Conversation

lunny
Copy link
Member

@lunny lunny commented Sep 14, 2025

  • Migrate from the current INI format to JSON for translations. JSON is widely supported, including by platforms such as Crowdin and Weblate.
  • Added a check for the json format and duplicate keys

As a next step, we can consider converting to the i18next JSON format, which allows using placeholders like {name} instead of the current %[1]s syntax.

All original ini files have been converted with go run ./tools/convert_locale_ini_json.go

@lunny lunny added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Sep 14, 2025
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Sep 14, 2025
@GiteaBot

This comment was marked as outdated.

@github-actions github-actions bot added modifies/translation modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files labels Sep 14, 2025
@silverwind
Copy link
Member

Very good choice.

@wxiaoguang
Copy link
Contributor

TBH I won't say it is a good choice. Full screen of \"

image

@wxiaoguang
Copy link
Contributor

Such change is ugly and fragile.

image

@wxiaoguang
Copy link
Contributor

By the way, you also need to fix

@silverwind
Copy link
Member

Full screen of "

We should eventually remove all HTML from translations which will solve this. There are always ways to interpolate translation into templates without having HTML in the translation itself.

@wxiaoguang
Copy link
Contributor

Full screen of "

We should eventually remove all HTML from translations which will solve this. There are always ways to interpolate translation into templates without having HTML in the translation itself.

The "eventually has been years, many "eventually" things have been years.

@hiifong
Copy link
Member

hiifong commented Sep 15, 2025

I believe switching to TOML would be preferable, as existing translations can be easily converted to the TOML format, Nor will you see a screen full of \"

@silverwind
Copy link
Member

silverwind commented Sep 15, 2025

Still I think JSON is a big step forward over INI. It has clear and well-known escaping rules, and any mistake will be found by any JSON parser (which should run on the CI, and this is trivial to add).

@wxiaoguang
Copy link
Contributor

Still I think JSON is a big step forward over INI. It has clear and well-known escaping rules, and any mistake will be found by any JSON parser (which should run on the CI, and this is trivial to add).

Yes, any well-defined format is a big step.

Still think it should clean up the legacy HTML quotes before migrating, to make the code base clean and avoid low-level mistakes.

@hiifong
Copy link
Member

hiifong commented Sep 15, 2025

Still I think JSON is a big step forward over INI. It has clear and well-known escaping rules, and any mistake will be found by any JSON parser (which should run on the CI, and this is trivial to add).

One drawback of JSON format is that it does not support adding comments.

@wxiaoguang
Copy link
Contributor

Still I think JSON is a big step forward over INI. It has clear and well-known escaping rules, and any mistake will be found by any JSON parser (which should run on the CI, and this is trivial to add).

One drawback of JSON format is that it does not support adding comments.

Agree, that's also a problem.

@silverwind
Copy link
Member

silverwind commented Sep 15, 2025

YAML has comments. Does crowdin support it? Thought I see no pressing need to comment translations.

@hiifong
Copy link
Member

hiifong commented Sep 15, 2025

YAML has comments. Does crowdin support it? Thought I see no pressing need to comment translations.

Support, and also support TOML format.
ref: https://store.crowdin.com/categories/file-formats

@hiifong
Copy link
Member

hiifong commented Sep 15, 2025

ref: #32937
I believe we should add comments in this situation.

@lunny
Copy link
Member Author

lunny commented Sep 15, 2025

Still I think JSON is a big step forward over INI. It has clear and well-known escaping rules, and any mistake will be found by any JSON parser (which should run on the CI, and this is trivial to add).

One drawback of JSON format is that it does not support adding comments.

Why do we need comments for translation keys? Currently, almost none of the existing translations include comments. Although JSON has it's drawback, but the format is parsed well by all kinds of languages and platforms like crowdin, weblate and others.

I have a plan to replace all %s to {user} in the translation strings, I think it's also a suitable time to replace all the HTML tags at the same PR. Otherwise, we have to replace to %s at this PR and replace it again next time.

@hiifong
Copy link
Member

hiifong commented Sep 15, 2025

Still I think JSON is a big step forward over INI. It has clear and well-known escaping rules, and any mistake will be found by any JSON parser (which should run on the CI, and this is trivial to add).

One drawback of JSON format is that it does not support adding comments.

Why do we need comments for translation keys? Currently, almost none of the existing translations include comments. Although JSON has it's drawback, but the format is parsed well by all kinds of languages and platforms like crowdin, weblate and others.

I have a plan to replace all %s to {user} in the translation strings, I think it's also a suitable time to replace all the HTML tags at the same PR. Otherwise, we have to replace to %s at this PR and replace it again next time.

So how do you plan to replace the HTML tags?

@lunny
Copy link
Member Author

lunny commented Sep 15, 2025

I believe switching to TOML would be preferable, as existing translations can be easily converted to the TOML format, Nor will you see a screen full of \"

TOML is also a possible choice but it seems weblate haven't support it.
Replace the html tags one by one manually. There are many examples in the template files.

A drawback of the YAML format is that incorrect indentation can easily lead to invalid or unintended keys. i.e.
error: a
vs

form:
     error: a

@hiifong
Copy link
Member

hiifong commented Sep 15, 2025

I believe switching to TOML would be preferable, as existing translations can be easily converted to the TOML format, Nor will you see a screen full of \"

TOML is also a possible choice but it seems weblate haven't support it. Replace the html tags one by one manually. There are many examples in the template files.

A drawback of the YAML format is that incorrect indentation can easily lead to invalid or unintended keys. i.e. error: a vs

form:
     error: a

If we need to switch to another translation platform in the future, we should consider using a more widely compatible file format. If this requirement does not exist, I currently recommend using the TOML format.

@lunny
Copy link
Member Author

lunny commented Sep 15, 2025

I believe switching to TOML would be preferable, as existing translations can be easily converted to the TOML format, Nor will you see a screen full of \"

TOML is also a possible choice but it seems weblate haven't support it. Replace the html tags one by one manually. There are many examples in the template files.
A drawback of the YAML format is that incorrect indentation can easily lead to invalid or unintended keys. i.e. error: a vs

form:
     error: a

If we need to switch to another translation platform in the future, we should consider using a more widely compatible file format. If this requirement does not exist, I currently recommend using the TOML format.

JSON is widely supported, ensuring we are not locked into any specific platform. JSON i18next is a standalone standard. ref: https://www.i18next.com/

@lunny lunny marked this pull request as ready for review September 15, 2025 14:33
@silverwind
Copy link
Member

I think JSON is a good choice. TOML and YAML are both more much complex specs. I think the downside of having to escape " is acceptable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/go Pull requests that update Go code modifies/internal modifies/templates This PR modifies the template files modifies/translation type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants