jeresig / i18n-node-2

Lightweight simple translation module for node.js / express.js with dynamic json storage. Uses common __('...') syntax in app and templates.
MIT License
507 stars 79 forks source link

allow for line breaks in translations #96

Open benjitastic opened 8 years ago

benjitastic commented 8 years ago

My fix to allow line breaks (\n) in the translation js files was to introduce a line of code on line 159 of i18n.js:

    __: function () {
        var msg = this.translate(this.locale, arguments[0]);

        if (arguments.length > 1) {
            msg = vsprintf(msg, Array.prototype.slice.call(arguments, 1));
        }

        msg = msg.replace(/\n/g, "<br />"); //allow line breaks

        return msg;
    },

that means that an input like this:

{
"Never miss out, you can watch a replay.": "永远不会错过,\n您可观看重播",
}

outputs like this in express.js: in template file: <%- __("Never miss out, you can watch a replay.") %> actual code printed on page: 永远不会错过,<br />您可观看重播

Is there a better way to do this? Or any plan to allow for
output in future?

gjuchault commented 8 years ago

Could you make a pull request for this ? Your fix seems interesting