Skip to content

Commit 8f2b9a5

Browse files
committed
Updated index, build
1 parent c5b151f commit 8f2b9a5

3 files changed

Lines changed: 25 additions & 57 deletions

File tree

_includes/sidebar.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ <h1>
2626
{% endif %}
2727
{% endfor %}
2828

29-
<a class="sidebar-nav-item" href="{{ site.github.repo }}/archive/v{{ site.version }}.zip">Download</a>
3029
<a class="sidebar-nav-item" href="{{ site.github.repo }}">GitHub project</a>
3130
<span class="sidebar-nav-item">Currently v{{ site.version }}</span>
3231
</nav>

build.md

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,22 @@ For a significant decrease in filesize and execution time, you should precompile
1515
ordinal: 'The {N, selectordinal, one{1st} two{2nd} few{3rd} other{#th}} message.' };
1616

1717
> var mfunc = mf.compile(messages);
18-
> mfunc().ordinal({N:3})
19-
'The 3rd message.'
20-
21-
> console.log(mfunc.toString())
22-
function anonymous() {
23-
var number = function (value, offset) {
24-
if (isNaN(value)) throw new Error("'" + value + "' isn't a number.");
25-
return value - (offset || 0);
26-
};
27-
var plural = function (value, offset, lcfunc, data, isOrdinal) {
28-
if ({}.hasOwnProperty.call(data, value)) return data[value]();
29-
if (offset) value -= offset;
30-
var key = lcfunc(value, isOrdinal);
31-
if (key in data) return data[key]();
32-
return data.other();
33-
};
34-
var select = function (value, data) {
35-
if ({}.hasOwnProperty.call(data, value)) return data[value]();
36-
return data.other()
37-
};
38-
var pluralFuncs = {
39-
en: function (n, ord) {
40-
var s = String(n).split('.'), v0 = !s[1], t0 = Number(s[0]) == n,
41-
n10 = t0 && s[0].slice(-1), n100 = t0 && s[0].slice(-2);
42-
if (ord) return (n10 == 1 && n100 != 11) ? 'one'
43-
: (n10 == 2 && n100 != 12) ? 'two'
44-
: (n10 == 3 && n100 != 13) ? 'few'
45-
: 'other';
46-
return (n == 1 && v0) ? 'one' : 'other';
47-
}
48-
};
49-
var fmt = {};
50-
51-
return {
52-
simple: function(d) { return "A simple message."; },
53-
var: function(d) { return "Message with " + d.X + "."; },
54-
plural: function(d) { return "You have " + plural(d.N, 0, pluralFuncs.en, { 0: function() { return "no messages";}, one: function() { return "1 message";}, other: function() { return number(d.N) + " messages";} }) + "."; },
55-
select: function(d) { return select(d.GENDER, { male: function() { return "He has";}, female: function() { return "She has";}, other: function() { return "They have";} }) + " sent you a message."; },
56-
ordinal: function(d) { return "The " + plural(d.N, 0, pluralFuncs.en, { one: function() { return "1st";}, two: function() { return "2nd";}, few: function() { return "3rd";}, other: function() { return number(d.N) + "th";} }, 1) + " message."; }
57-
}
58-
}
18+
> mfunc().ordinal({N:1})
19+
'The 1st message.'
20+
21+
> var efunc = new Function('return (' + mfunc.toString() + ')()');
22+
> efunc()
23+
{ simple: [Function],
24+
var: [Function],
25+
plural: [Function],
26+
select: [Function],
27+
ordinal: [Function] }
28+
> efunc().ordinal({N:2})
29+
'The 2nd message.'
5930
```
6031

32+
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.
33+
6134

6235
## CLI Compiler
6336

index.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
layout: page
3-
title: messageformat.js
43
---
54

65
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:/
1211

1312
## What problems does it solve?
1413

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:
1615

1716
> There are 1 results.
1817
> There are 1 result(s).
1918
> Number of results: 5.
2019
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-
2320

2421
## What does it look like?
2522

26-
With this message (shown with extra lines for simplicity):
23+
With this message:
2724

2825
```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} }
33-
in the
34-
{CATEGORY, selectordinal, one{#st} two{#nd} few{#rd} other{#th} }
35-
category.
26+
> var msg =
27+
'{GENDER, select, male {He} female {She} other {They} }' +
28+
' found ' +
29+
'{RESULTS, plural, =0 {no results} one {1 result} other {# results} }' +
30+
' in the ' +
31+
'{CATEGORY, selectordinal, one{#st} two{#nd} few{#rd} other{#th} }' +
32+
' category.';
3633
```
3734

3835
You'll get these results:
@@ -59,11 +56,10 @@ You'll get these results:
5956
* Handles arbitrary nesting of pluralization and select rules
6057
* Supports all ~466 languages included in the Unicode CLDR
6158
* Works on the server and the client
62-
* No i18n necessary &ndash; you can use it for just well-formed english sentences `UX++;`
59+
* Remarkably useful even for single-language use
6360
* Speed & efficiency: Can pre-compile messages to JavaScript code
6461
* Great for speed: message formatting is just string concatenation
65-
* Run a precompiler at build time and include just `filesize--;`
66-
* Compatible with other languages that support MessageFormat
62+
* Compatible with other MessageFormat implementations
6763
* Extendable with custom formatting functions
6864
* Very whitespace tolerant
6965
* Supports Unicode

0 commit comments

Comments
 (0)