-
-
Save tim-evans/6008689 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| The `{{l}}` helper renders a localized string using `I18n.l`. | |
| ```handlebars | |
| {{l "percentage" value=123.45}} | |
| ``` | |
| ```html | |
| 123.450% | |
| ``` | |
| To pass additional configurations, simply provide them as | |
| attributes to the helper. | |
| ```handlebars | |
| {{l "number" value=1000 delimiter='.' separator=','}} | |
| ``` | |
| ```html | |
| 1.000,00 | |
| ``` | |
| If the localization string is generated via a bound value, | |
| you may generate your string by specifying the bound values | |
| using a quasi-literal: | |
| ```handlebars | |
| {{l "date.formats.`size`" value="2009-09-18"}} | |
| ``` | |
| If `size` is `"short"`, then the resulting HTML would be: | |
| ```html | |
| "Sep 18, 2009" | |
| ``` | |
| If `size` is `"long"`, then the resulting HTML would be: | |
| ```html | |
| "September 18, 2009" | |
| ``` | |
| @method l | |
| @for Em.Handlebars.helpers | |
| @param string {String} The string to localize | |
| @param formats {Object} An object to format the string with. | |
| @return {String} HTML string | |
| */ | |
| Ember.Handlebars.registerTextHelper('l', function (scope, context) { | |
| var value = context.value, | |
| SafeString = Ember.Handlebars.SafeString; | |
| switch (scope) { | |
| case "currency": | |
| return new SafeString(I18n.toCurrency(value, context)); | |
| case "number": | |
| return new SafeString(I18n.toNumber(value, context)); | |
| case "percentage": | |
| return new SafeString(I18n.toPercentage(value, context)); | |
| default: | |
| if (scope.match(/^(date|time)/)) { | |
| // Fix for our dates which are in UTC | |
| if (scope.match(/^date/)) { | |
| value = value.toUTCString().replace(/GMT/, ''); | |
| } | |
| return new SafeString(I18n.toTime(scope, value)); | |
| } else { | |
| return value.toString(); | |
| } | |
| } | |
| }, /`(.*?)`/g); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What library to do you use for
I18n.toCurrencyandI18n.toPercent?