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

New translation format system (extendible with sjson built-in) #1470

Draft
wants to merge 7 commits into
base: 1.21.x
Choose a base branch
from

Conversation

HenryLoenwind
Copy link
Contributor

@HenryLoenwind HenryLoenwind commented Aug 18, 2024

Supersedes #1419, #1408 and #1269, extends #1134.

#1134 has the issue that its translations are not editable on Crowdin and will even be trashed unless a translator knows exactly what they are dealing with. (Note that "not editable" means that basic tasks like changing the word order of a translation are impossible. The text of each single segment can still be changed.)

#1408 presented a new format that is Crowdin-compatible and translator-friendly but could not achieve community agreement.

#1419 presented a solution that packed #1134's json structure into as String as suggested by maintainers, which was Crowdin-compatible but very translator-unfriendly and also did not achieve community agreement.


This solution is a compromise. It retains the #1419 "json as a string" functionality and as such is a minimum viable solution to the issue of Crowdin-compatibility. In addition, it allows mods to register additional formatters, which allows the translator-friendly solution of #1408---or any other formatter; bbcode, RTF, markdown, ICU MessageFormat, etc.---to be shipped as a mod.

This is achieved by adding an optional ResourceLocation parameter to the marker string in the translation. Example:

"neoforge.configuration.uitext.filenametooltip": "%n[{\"text\": \"File: \\\"\",\"color\": \"gray\"},{\"index\": 0,\"color\": \"gray\"},{\"text\": \"\\\"\",\"color\": \"gray\"}]",
"neoforge.configuration.uitext.filenametooltip2": "%n(neoforge:sjson) [{\"text\": \"File: \\\"\",\"color\": \"gray\"},{\"index\": 0,\"color\": \"gray\"},{\"text\": \"\\\"\",\"color\": \"gray\"}]",
"another:": "%n(somemod:someformat) anything",

Note that the formatter is specific to the translation, not the consumer of the translation. This allows mods that add translations to other mods (or even vanilla) to use this without needing any cooperation by the consuming mod.

Unit tests are included for both the "string json" formatter and the custom formatter API.

I do intend to repackage and publish #1408 as a standalone mod using this PR's API should it be merged.


And if someone wonders how a new formatter is registered:

            TemplateParser.register(ResourceLocation.parse("neotest:test"), (template, arg, consumer) -> {
                consumer.accept(Component.literal(template.replace('X', 'n')));
                return "";
            }, template -> template.replace('X', 'n'));

ResourceLocation as the name (with the expectation that mods keep to their own namespace), then a TriFunction for the "raw string -> Components" and a Function for the "raw string to raw string in vanilla format" conversions. The former gets the parameters the containing Component has (as it is supposed to decompose the template and insert those) and a consumer (as this is what vanilla code provides here; the latter is just String to String.

The former also can return a String that will then be processed by the vanilla parser in addition to the Components it generates. This means that in the above example, the TriFunction should also have been written as return template.replace('X', 'n'). The difference is that that would then also process %s in the remaining string, the same way the text-only Function works. But as that example is the unit test and doesn't make any sense anyway...

@neoforged-pr-publishing
Copy link

  • Publish PR to GitHub Packages

@sciwhiz12 sciwhiz12 added enhancement New (or improvement to existing) feature or request 1.21.1 Targeted at Minecraft 1.21.1 labels Aug 26, 2024
@neoforged-automation
Copy link

@HenryLoenwind, this pull request has conflicts, please resolve them for this PR to move forward.

@HenryLoenwind HenryLoenwind marked this pull request as draft September 3, 2024 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.21.1 Targeted at Minecraft 1.21.1 enhancement New (or improvement to existing) feature or request needs rebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants