Skip to content

[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

Closed

Conversation

kevin-verschaeve
Copy link
Contributor

@kevin-verschaeve kevin-verschaeve commented Oct 1, 2019

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 :

  • it is not really easy to find and understand it on the ICU intl documentation.
  • one can think that using ranges like ]-INF,0] my translation is no more possible with ICU if it is not documented here

I don't know if my examples are good enough or well explained, so please, don't hesitate to reword me.

Thanks

Copy link
Contributor

@Pierstoval Pierstoval left a 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 :)

@javiereguiluz javiereguiluz requested a review from wouterj October 2, 2019 06:48
@kevin-verschaeve kevin-verschaeve changed the title [Transalation] Document range translation using the ICU MessageFormat [Translation] Document range translation using the ICU MessageFormat Oct 2, 2019
@kevin-verschaeve kevin-verschaeve changed the base branch from master to 4.2 October 2, 2019 07:28
@kevin-verschaeve
Copy link
Contributor Author

I changed the target branch to 4.2 as ICU was introduced in 4.2

@wouterj
Copy link
Member

wouterj commented Nov 4, 2019

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 choice format. The reason is that it seems to be deprecated/discouraged by the main MessageFormat implementations:

Use of the old "choice" argument type is discouraged. It cannot handle plural rules for many languages, and is clumsy for simple selection.
-- http://userguide.icu-project.org/formatparse/messages

Note that choiceformat is considered deprecated and pluralformat and selectformat are favored.
-- https://help.smartling.com/hc/en-us/articles/360008030994-ICU-Message-Format

Messageformat supports and extends all parts of the standard, with the exception of the deprecated ChoiceFormat.
-- https://messageformat.github.io/messageformat/


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 choice chapter with a small .. trip:: box that describes it's discouraged to put logic in the message formats and that you should use PHP code instead for this logic?

@kevin-verschaeve
Copy link
Contributor Author

Hi @wouterj,

Thanks for your feedback !

Indeed, I did not see that the choice format was deprecated.

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 tip box as you suggered.

@wouterj wouterj changed the base branch from 4.2 to 4.3 November 23, 2019 14:38
@wouterj wouterj force-pushed the doc/translation-range branch from 86848b0 to bcc89a7 Compare November 23, 2019 14:38
wouterj added a commit that referenced this pull request Nov 23, 2019
* 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
wouterj added a commit that referenced this pull request Nov 23, 2019
* 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
@wouterj wouterj closed this in c3166bd Nov 23, 2019
@wouterj
Copy link
Member

wouterj commented Nov 23, 2019

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

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.

5 participants