-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Possibility to extend formatters? #1636
Comments
@metallium we are implementing the specified formatters from ICU Messages: http://userguide.icu-project.org/formatparse/messages. I believe lowercase, and capitalization should be baked into the translation rather than a runtime cost. It might require some duplications in the messages you send to the client side, but I think it is worthy to keep that separation. |
These injected words are dynamic and are used in lots of messages. Thought about that, but it seems more natural to polish it in concrete translation. |
formatter customization is available by default in c# implementation |
@caridy you can still implement the specified formatters from ICU Messages, but make the set of formatters customizable. |
ah, thanks for the link @metallium. I will talk to the other folks about this, give us some time to review it. /cc @ericf |
@metallium can you write an example message in the message syntax to demonstrate what you're suggesting? I think it would help be better understand what you're running into and how you're proposing to solve it. |
example that is unsolveable now:
data remains the same for all languages, but specific language can force lowercasing of words inside string (I still keep using English here)
as for me, formatters seem to be good extensibility point, allowing to define
|
@metallium I see, so you want to define |
yep, to make it possible to provide custom formatters, e.g.
in general it would be great if default formatters (plural, select, selectordinal, ...) would use the same API as custom ones |
Another potential use-case for this I've had in the past (#99) is to turn lists into sentences, it would be great to be able to define a format('Selected {items, sentence}', {items: ['one', 'two', 'three'})
// => "Selected one, two and three" |
@rlivsey that's a different feature request, and it is an ongoing effort: tc39/ecma402#33 |
@caridy awesome, thanks for pointing me towards that, I've added a comment to the original issue pointing others over there too. |
Pretty sure it's the same feature request - in my case, I have a requirement for adding a new "style" option for the number formatter. I need to insert the following function as a custom style: function (val) {
var v = "";
var negative = false;
if (val < 0) {
negative = true;
val = Math.abs(val);
}
if (val >= 1e12) {
v = String(Math.round(val / 1e11) / 10) + "T";
} else if (val >= 1e9) {
v = String(Math.round(val / 1e8) / 10) + "G";
} else if (val >= 1e6) {
v = String(Math.round(val / 1e5) / 10) + "M";
} else if (val >= 1e3) {
v = String(Math.round(val / 1e2) / 10) + "K";
} else {
v = String(Math.round(val * 10) / 10);
}
if (v == "undefined") {
v = "";
} else {
if (negative) {
v = "-" + v;
}
}
return v;
} |
Improve browser bundling with Browserify/Webpack
Improve browser bundling with Browserify/Webpack
This use case should be handled by our skeleton support + numberformat es2020 polyfill |
@longlho how can I specify currency dynamically using skeleton formatting? No problem (from documentation):
Problem: I don't know the currency at this point, it must be dynamic. This format doesn't work:
|
You cannot. You'll have to format it as a passed in values |
Words passed as parameters should be capitalized/lowercased depending on translation.
We're using message formats as the only source of translations.
It would be great to extend built-in formatters
select
,plural
with own ones, likelowercased
,capitalized
.I see this change would also involve
intl-messageformat-parser
package.Do you think it's a good idea?
The text was updated successfully, but these errors were encountered: