-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Translation] Document range translation using the ICU MessageFormat #12400
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
[Translation] Document range translation using the ICU MessageFormat #12400
Conversation
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.
Slight changes, nothing big :)
92cafc1
to
86848b0
Compare
I changed the target branch to 4.2 as ICU was introduced in 4.2 |
Hi @kevin-verschaeve! First of all, thanks for submitting these docs to help further readers! I'm however not so sure if we should recommend or document the
I've been trying and looking to find another way to do this using MessageFormat's plural and select formats, but failed to find something. I think the main idea is to not combine logic and i18n. The supported formats (select & plural) are ways to modify the same message based on variables. Logic like "You don't have money" or "You have lots of money" are logic things, things that should be encapsulated in real code instead of letting your translator decide on such domain specific decisions. So instead of: // balance_message: '{balance, choice, -∞ < Oops! I'm down | 0 < I still have money | 1000 # I have a lot of money !}';
$message = $translator->trans('balance_message', $balance); You should use: // no_money_message: Oops! I'm down
// some_money_message: I still have money
// lots_of_money_message: I have a lot of money
if ($balance < 0) {
$message = $translator->trans('no_money_message');
} elseif ($balance < 1000) {
$message = $translator->trans('some_money_message');
} else {
$message = $translator->trans('lots_of_money_message');
} As the old range format used by Symfony allowed you to put domain logic in the message strings, what do you think about replacing this |
Hi @wouterj, Thanks for your feedback ! Indeed, I did not see that the So, I agree with you, it would not be a great idea to add something deprecated into the documentation. However, I am sad that such a thing is not possible. I liked the way we used translations for this kind of logic, but that's my humble opinion. I will add the |
86848b0
to
bcc89a7
Compare
* 4.3: [#12400] Added tip about ranges in the new ICU message format Revert "[Transalation] Document range translation using the ICU MessageFormat" [Transalation] Document range translation using the ICU MessageFormat
* 4.4: [#12400] Added tip about ranges in the new ICU message format Revert "[Transalation] Document range translation using the ICU MessageFormat" [Transalation] Document range translation using the ICU MessageFormat fix typo
Thanks again @kevin-verschaeve! Now Symfony 5 is released, I've gone ahead and merged this PR. Afterwards, I reverted your changes and added the tip: 2baeb1c This way, you still get the credits you deserve! As Symfony 4.2 has reached end of maintanaince some time ago, I've merged this in 4.3 and up. #SymfonyHackathon |
The ICU MessageFormatter has a notation to do the same as
transchoice
was able to, concerning ranges.I think this would be a good idea to document it on the Symfony docs because :
]-INF,0] my translation
is no more possible with ICU if it is not documented hereI don't know if my examples are good enough or well explained, so please, don't hesitate to reword me.
Thanks