diff --git a/README.md b/README.md index 4e58d2a..9247f5d 100644 --- a/README.md +++ b/README.md @@ -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: - -
{{_i}}Tweet{{/i}}
- -By adding a pragma, we can provide the right context for a given template: - - {{%TRANSLATION-HINT mode=tweet_button}} - -
{{_i}}Tweet{{/i}}
- -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 @@ -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}}`? diff --git a/examples/i18n.html b/examples/i18n.html deleted file mode 100644 index d39bc61..0000000 --- a/examples/i18n.html +++ /dev/null @@ -1 +0,0 @@ -{{_i}}foo {{bar}}{{/i}} diff --git a/examples/i18n.js b/examples/i18n.js deleted file mode 100644 index 2053321..0000000 --- a/examples/i18n.js +++ /dev/null @@ -1,4 +0,0 @@ -var i18n = { - bar: "don't double render me... {{baz}}", - baz: "FAIL" -}; \ No newline at end of file diff --git a/examples/i18n.txt b/examples/i18n.txt deleted file mode 100644 index 5ab5fb8..0000000 --- a/examples/i18n.txt +++ /dev/null @@ -1 +0,0 @@ -foo don't double render me... {{baz}} diff --git a/mustache.js b/mustache.js index dd217df..a06d117 100644 --- a/mustache.js +++ b/mustache.js @@ -13,8 +13,7 @@ var Mustache = function() { pragmas: {}, buffer: [], pragmas_implemented: { - "IMPLICIT-ITERATOR": true, - "TRANSLATION-HINT": true + "IMPLICIT-ITERATOR": true }, context: {}, @@ -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); @@ -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 */