Skip to content

Commit

Permalink
remove i18n stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
bcherry committed Feb 21, 2011
1 parent 59bbd35 commit 3ebd5ef
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 89 deletions.
42 changes: 0 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,44 +199,6 @@ will tell mustache.js to look for a object in the context's property
`winnings`. It will then use that object as the context for the template found
in `partials` for `winnings`.

## Internationalization

mustache.js supports i18n using the `{{_i}}{{/i}}` tags. When mustache.js encounters
an internationalized section, it will call out to the standard global gettext function `_()` with the tag contents for a
translation _before_ any rendering is done. For example:

var template = "{{_i}}{{name}} is using mustache.js!{{/i}}"

var view = {
name: "Matt"
};

var translationTable = {
// Welsh, according to Google Translate
"{{name}} is using mustache.js!": "Mae {{name}} yn defnyddio mustache.js!"
};

function _(text) {
return translationTable[text] || text;
}

alert(Mustache.to_html(template, view));
// alerts "Mae Matt yn defnyddio mustache.js!"

### The TRANSLATION-HINT Pragma

Some single words in English have different translations based on usage context. Mustache.js supports this with the TRANSLATION-HINT pragma. For example, the word "Tweet" can be used as a noun, or a verb. The following template is ambiguous:

<div class="tweet-button">{{_i}}Tweet{{/i}}</div>

By adding a pragma, we can provide the right context for a given template:

{{%TRANSLATION-HINT mode=tweet_button}}

<div class="tweet-button">{{_i}}Tweet{{/i}}</div>

This will lookup every translation in that template with the mode, e.g. `_('Tweet', {mode: "tweet_button"})`, which your gettext implementation can handle as appropriate.

## Escaping

mustache.js does escape all values when using the standard double mustache
Expand Down Expand Up @@ -293,10 +255,6 @@ own iteration marker:
{{bob}}
{{/foo}}

### TRANSLATION-HINT

See the "Internationalization" section above for info on this pragma.

## F.A.Q.

### Why doesn’t Mustache allow dot notation like `{{variable.member}}`?
Expand Down
1 change: 0 additions & 1 deletion examples/i18n.html

This file was deleted.

4 changes: 0 additions & 4 deletions examples/i18n.js

This file was deleted.

1 change: 0 additions & 1 deletion examples/i18n.txt

This file was deleted.

42 changes: 1 addition & 41 deletions mustache.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ var Mustache = function() {
pragmas: {},
buffer: [],
pragmas_implemented: {
"IMPLICIT-ITERATOR": true,
"TRANSLATION-HINT": true
"IMPLICIT-ITERATOR": true
},
context: {},

Expand All @@ -35,17 +34,9 @@ var Mustache = function() {
}
}

// Branching or moving down the partial stack, save any translation mode info.
if (this.pragmas['TRANSLATION-HINT']) {
context['_TRANSLATION-HINT_mode'] = this.pragmas['TRANSLATION-HINT'].mode;
}

// get the pragmas together
template = this.render_pragmas(template);

// handle all translations
template = this.render_i18n(template, context, partials);

// render the template
var html = this.render_section(template, context, partials);

Expand Down Expand Up @@ -121,37 +112,6 @@ var Mustache = function() {
return this.render(partials[name], context[name], partials, true);
},

render_i18n: function(html, context, partials) {
if (html.indexOf(this.otag + "_i") == -1) {
return html;
}
var that = this;
var regex = new RegExp(this.otag + "\\_i" + this.ctag +
"\\s*([\\s\\S]+?)" + this.otag + "\\/i" + this.ctag, "mg");

// for each {{_i}}{{/i}} section do...
return html.replace(regex, function(match, content) {
var translationMode;

if (that.pragmas && that.pragmas["TRANSLATION-HINT"] && that.pragmas["TRANSLATION-HINT"].mode) {
translationMode = that.pragmas["TRANSLATION-HINT"].mode;
} else if (context['_TRANSLATION-HINT_mode']) {
translationMode = context['_TRANSLATION-HINT_mode'];
}

var params = content;

if (translationMode) {
params = {
text: content,
mode: translationMode
};
}

return _(params);
});
},

/*
Renders inverted (^) and normal (#) sections
*/
Expand Down

0 comments on commit 3ebd5ef

Please sign in to comment.