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

Javascript translator may return HTML entities when using plural rules #3685

Open
clarkwinkelmann opened this issue Nov 18, 2022 · 0 comments
Labels

Comments

@clarkwinkelmann
Copy link
Member

Current Behavior

This is a high level description of the issue. The problem has already been identified and lies in the internals of the rich-icu-message-formatter library.

Detailed issue askvortsov1/rich-icu-message-formatter#3

Calling app.translator.trans('core.lib.meta_titles.without_page_title', {forumName: 'A & B', pageNumber: 1}) returns ['A & B'] instead of the expected ['A & B']

The translation is defined as such:

without_page_title: "{pageNumber, plural, =1 {{forumName}} other {Page # - {forumName}}}"

The problem doesn't exist with translations that only have a flat message without any pluralization switch.

The problem happens whenever the {placeholder} isn't in the same place in the sentence in the plural variant. If both placeholders are at the same index, the entities are correctly decoded.

The issue is most noticeable when using the "1" or "0" rule of a pluralization message since "other" is most likely to be selected at random by the ICU library. But since this is partly based on a randomly generated value, the behavior can be different once in a while.

Steps to Reproduce

.

Expected Behavior

.

Screenshots

No response

Environment

  • Flarum version: test on dev-main, applies at least back to 1.5
  • Hosting environment: local
  • PHP version: irrelevant
  • Browser: irrelevant, can reproduce in jest unit tests

Output of php flarum info

Output of "php flarum info", run this in terminal in your Flarum directory.

Possible Solution

Described in the ICU issue. Pluralization parameters need to be isolated from other placeholders so that the entire logic runs with the same pluralization instead of using singular for part of the code and plural for the other half.

Additional Context

This is the underlying cause behind these previous issues and fixes for the page title. But the underlying issue applies to a lot more than just the title. It just happens that Flarum title uses a pluralization rule.

#3514
#3542

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant