-
-
Notifications
You must be signed in to change notification settings - Fork 135
feat(validation)!: add ability to specify translation keys for specific properties #1618
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
base: main
Are you sure you want to change the base?
Conversation
f078c90 to
f182b0c
Compare
|
The problem i see with this approach is when using a xliff format to store translations ( ref #1610 ), book related things won't be part of the same group. example: <?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" target-language="en" datatype="plaintext" original="file.ext">
<body>
<!-- Group: Book-related translations -->
<group id="book">
<!-- Subgroup: Create Book -->
<group id="book.create">
<!-- Form Labels -->
<group id="book.create.form">
<trans-unit id="book.create.form.title">
<source>book.create.form.title</source>
<target>Title</target>
</trans-unit>
<!-- Additional form labels can be added here -->
</group>
<!-- Error Messages -->
<group id="book.create.error">
<trans-unit id="book.create.error.title.max_length">
<source>book.create.error.title.max_length</source>
<target>The book title must not exceed {max} characters.</target>
</trans-unit>
<trans-unit id="book.create.error.title.min_length">
<source>book.create.error.title.min_length</source>
<target>The book title must be at least {min} characters long.</target>
</trans-unit>
</group>
</group>
</group>
<!-- Additional translation units can be added here -->
</body>
</file>
</xliff>Compared to the current: <?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" target-language="en" datatype="plaintext" original="file.ext">
<body>
<!-- Group: Book-related translations -->
<group id="book">
<!-- Subgroup: Create Book -->
<group id="book.create">
<!-- Form Labels -->
<group id="book.create.form">
<trans-unit id="book.create.form.title">
<source>book.create.form.title</source>
<target>Title</target>
</trans-unit>
<!-- Additional form labels can be added here -->
</group>
</group>
</group>
<!-- Group: Validation Errors -->
<group id="validation_error">
<!-- Has Length Errors -->
<group id="validation_error.has_length">
<!-- Book Management Specific Errors -->
<group id="validation_error.has_length.book_management">
<trans-unit id="validation_error.has_length.book_management.book_title">
<source>validation_error.has_length.book_management.book_title</source>
<target>The book title must be between 5 and 50 characters long.</target>
</trans-unit>
</group>
</group>
</group>
<!-- Additional translation units can be added here -->
</body>
</file>
</xliff>Grouping in xliff is useful not just for making things obvious, when using an online translation service where translators will be updating translations, this provides context to them, and makes navigating to the Also, having parameters for translation here is a MUST, for big projects, people who work on translation never touch the code, nor do they know what is the minimum or maximum value allowed, therefor, it should not be hardcoded in the message. |
|
I see that the translation units'
There's no code to touch, it's all in the translation message: The content above would be in the See: https://messageformat.unicode.org/ |
|
The problem now is that This creates fraction, as things related to book will now be in completely different groups. |
Ah cool! But this still does not the address for the need of a specific message for the min/max. If we have a field with a min, and no max, and the error message is already translated to 100 locales, when we deploy a new version that sets a max constraint, it might take time for the translation team to catch up and update the message, so users will be getting a confusing message in this duration. We would rather users see a translation message of the fallback. |
Is that really an issue? If you are migrating to Tempest, updating translations is part of the process, since we use a different format than other frameworks. MessageFormat 2.0 has clear advantages—rich, readable, context-aware translation messages. It has not been designed to work on an attribute basis, and we won't support that. Especially since this format expects fallbacks! You are not supposed to end up with translation keys being presented to end users |
format is not an issue, i can simply export translations in another format. But having specific messages for different kind of problems is important. something being too short is not the same as something being too long. The example i specified shows how adding a new limit invalidates all translation messages, that should not be the case, the |
I agree! I think you did not fully grasp what MF2 is capable of. Let's take my example: If both a
If just a
If just a
If a new variant gets added (though in the example above, it is not possible), then the fallback will be used until a proper variant is specified:
|
|
The problem is i want a different message depending on what failed validation, not depending on constraint configuration. If My assumption is the current way this works, user will always see |
|
Ah, well, that's actually rule-dependent then, and theoretically still achievable through MF2, though we don't provide the value as a translation variable currently. What is certain though, is that we don't (and won't) have more than one error message translation key by rule, since the whole point of MF2 is to achieve this level of flexibility I'm curious though, how would you implement in other frameworks what you are asking here? What would the error message be if |
Closes #1611
This pull request gives the ability to do that:
When the
HasLengthrule fails, instead of using thevalidation_error.has_lengthtranslation key to get the error message, the validator will usevalidation_error.has_length.book_management.book_title—basically, appending the specified translation key to what would have been the original translation key.Technically, it's a breaking change, since the returned failing rules are now wrapped in a
FailingRuleVO