You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note that as `efunc` is defined as a `new Function()`, it has no access to the surrounding scope; the output of `mfunc().toString()` can be saved as a file and later included with `require()` or `<script src=...>`, providing access to the compiled functions that is completely independent of messageformat.js, or any other dependencies.
Copy file name to clipboardExpand all lines: index.md
+11-15Lines changed: 11 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,5 @@
1
1
---
2
2
layout: page
3
-
title: messageformat.js
4
3
---
5
4
6
5
The experience and subtlety of your program's text can be important. MessageFormat is a mechanism for handling both **pluralization** and **gender** in your applications. It can also lead to much better translations, as it's designed to support [all the languages](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html) included in the [Unicode CLDR](http://cldr.unicode.org/).
@@ -12,27 +11,25 @@ There is a good slide-deck on [Plural and Gender in Translated Messages](https:/
12
11
13
12
## What problems does it solve?
14
13
15
-
Using messageformat.js, you can separate your code from your text formatting, while enabling much more humane expressions. In other words, you won't see this anymore:
14
+
Using messageformat.js, you can separate your code from your text formatting, while enabling much more humane expressions. In other words, you won't need to see this anymore in your output:
16
15
17
16
> There are 1 results.
18
17
> There are 1 result(s).
19
18
> Number of results: 5.
20
19
21
-
These are generally unacceptable in this day and age. Not to mention the problem expands when you consider languages with 6 different pluralization rules. You may be using something like Gettext to solve this across multiple languages, but even Gettext falls flat.
22
-
23
20
24
21
## What does it look like?
25
22
26
-
With this message (shown with extra lines for simplicity):
23
+
With this message:
27
24
28
25
```js
29
-
>console.log(msg)
30
-
{GENDER, select, male {He} female {She} other {They} }
31
-
found
32
-
{RESULTS, plural, =0 {no results} one {1 result} other {# results} }
0 commit comments