Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow for line breaks in translations #96

Open
benjitastic opened this issue May 15, 2016 · 1 comment
Open

allow for line breaks in translations #96

benjitastic opened this issue May 15, 2016 · 1 comment

Comments

@benjitastic
Copy link

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants