You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Dirk Rudolph (Jira)" <ji...@apache.org> on 2021/07/23 11:30:00 UTC

[jira] [Updated] (SLING-10654) HTL optionally support ICU4j MessageFormat for string formatting

     [ https://issues.apache.org/jira/browse/SLING-10654?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dirk Rudolph updated SLING-10654:
---------------------------------
    Description: 
The [ICU MessageFormat|https://unicode-org.github.io/icu-docs/apidoc/dev/icu4j/com/ibm/icu/text/MessageFormat.html] provides a rich set of features compared to the currently implemented, simple placeholder replacement. In particular I am referring to the support for plural rules. Plural forms for words in combination with numbers are not as simple in all language as they are in English (or German), for example consider the following format {{{0} result(s)}}
||Language||One||Few||Many||
|English|1 result|3 results|15 results|
|German|1 Ergebnis|3 Ergebnisse|15 Ergebnisse|
|Czech|1 výsledek|3 výsledky|15 výsledků|

With the ICU Message Format the above format could be modified according to a locale to support this
||Locale||Format||
|en|{{{0,plural, one \{# result} other {# results}}}}|
|de|{{{0,plural, one \{# Ergebnis} other {# Ergebnisse}}}}|
|vs|{{{0,plural, one \{# výsledek} few \{# výsledky} other {# výsledků}}}}|

According to the HTL specification the format option allows [to replace placeholders|https://github.com/adobe/htl-spec/blob/1.4/SPECIFICATION.md#122-format] in {{Strings}}.
{quote}placeholders (eg: \{0}) in the pattern, triggers string formatting
{quote}
It does not define a specific definition of a placeholder and simply refers to {{{0}}} as an example. The support of complex placeholders as described above should be a valid implementation detail.

However, with only regular placeholders the overhead of parsing the format as ICU MessageFormat comes with a performance penalty. So it must only be used if the format contains at least one complex placeholder, for example identified by {{{\d+,[^}]+}}}. The support can be implemented completely optional, depending on the existing of icu4j at runtime.

  was:
The [ICU MessageFormat|https://unicode-org.github.io/icu-docs/apidoc/dev/icu4j/com/ibm/icu/text/MessageFormat.html] provides a rich set of features compared to the currently implemented, simple placeholder replacement. In particular I am referring to the support for plural rules. Plural forms for words in combination with numbers are not as simple in all language as they are in English (or German), for example consider the following format {{\{0} results}}

||Language||One||Few||Many||
|English|1 result|3 results|15 results|
|German|1 Ergebnis|3 Ergebnisse|15 Ergebnisse|
|Czech|1 výsledek|3 výsledky|15 výsledků|

With the ICU Message Format the above format could be modified according to a locale to support this
||Locale||Format||
|en|{{\{0,plural, one \{# result} other \{# results}}}}|
|de|{{\{0,plural, one \{# Ergebnis} other \{# Ergebnisse}}}}|
|vs|{{\{0,plural, one \{# výsledek} few \{# výsledky} other \{# výsledků}}}}|

According to the HTL specification the format option allows [to replace placeholders|https://github.com/adobe/htl-spec/blob/1.4/SPECIFICATION.md#122-format] in {{Strings}}.
{quote}
placeholders (eg: \{0}) in the pattern, triggers string formatting
{quote}
It does not define a specific definition of a placeholder and simply refers to {{\{0\}}} as an example. The support of complex placeholders as described above should be a valid implementation detail. 

However, with only regular placeholders the overhead of parsing the format as ICU MessageFormat comes with a performance penalty. So it must only be used if the format contains at least one complex placeholder, for example identified by {{\{\d+,[^}]+}}}. The support can be implemented completely optional, depending on the existing of icu4j at runtime. 


> HTL optionally support ICU4j MessageFormat for string formatting
> ----------------------------------------------------------------
>
>                 Key: SLING-10654
>                 URL: https://issues.apache.org/jira/browse/SLING-10654
>             Project: Sling
>          Issue Type: New Feature
>          Components: Scripting
>            Reporter: Dirk Rudolph
>            Priority: Major
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> The [ICU MessageFormat|https://unicode-org.github.io/icu-docs/apidoc/dev/icu4j/com/ibm/icu/text/MessageFormat.html] provides a rich set of features compared to the currently implemented, simple placeholder replacement. In particular I am referring to the support for plural rules. Plural forms for words in combination with numbers are not as simple in all language as they are in English (or German), for example consider the following format {{{0} result(s)}}
> ||Language||One||Few||Many||
> |English|1 result|3 results|15 results|
> |German|1 Ergebnis|3 Ergebnisse|15 Ergebnisse|
> |Czech|1 výsledek|3 výsledky|15 výsledků|
> With the ICU Message Format the above format could be modified according to a locale to support this
> ||Locale||Format||
> |en|{{{0,plural, one \{# result} other {# results}}}}|
> |de|{{{0,plural, one \{# Ergebnis} other {# Ergebnisse}}}}|
> |vs|{{{0,plural, one \{# výsledek} few \{# výsledky} other {# výsledků}}}}|
> According to the HTL specification the format option allows [to replace placeholders|https://github.com/adobe/htl-spec/blob/1.4/SPECIFICATION.md#122-format] in {{Strings}}.
> {quote}placeholders (eg: \{0}) in the pattern, triggers string formatting
> {quote}
> It does not define a specific definition of a placeholder and simply refers to {{{0}}} as an example. The support of complex placeholders as described above should be a valid implementation detail.
> However, with only regular placeholders the overhead of parsing the format as ICU MessageFormat comes with a performance penalty. So it must only be used if the format contains at least one complex placeholder, for example identified by {{{\d+,[^}]+}}}. The support can be implemented completely optional, depending on the existing of icu4j at runtime.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)