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

i18n and javascript quotes #300

Closed
Sshnyari opened this issue Oct 24, 2016 · 12 comments
Closed

i18n and javascript quotes #300

Sshnyari opened this issue Oct 24, 2016 · 12 comments

Comments

@Sshnyari
Copy link
Contributor

Sshnyari commented Oct 24, 2016

Currently, we have a .NET application with a front end built with angular.
We use multiple html template files with translatable tokens within.
It all works great with i18n. A single translation framework for both front and back ends. All outgoing "traffic" goes through i18n before getting out, either be it text, javascript, json, xml or html

The problem arises (or becomes more noticiable) when we want to minify everything that gets sent client side :
With gulp, we can easily "minify" html templates (with gulp-angular-templatecache for example)
What it basically does is create a js file that contains every html template used by angular.
An example of the js file :
angular.module("templates").run(["$templateCache",function(e){e.put("actions/actions.html",'<div>[[[Quotes of text]]]</div>')}]);
If the translation of "Quotes of text" is "Text's quotes", the browser gets the following js file :
angular.module("templates").run(["$templateCache",function(e){e.put("actions/actions.html",'<div>Text's quotes</div>')}]);

Which causes a syntax error.

We could correct the problem by escaping the translated string in the po file (like this : "Text's quotes"), but the token can be used in other content types where the escape character would be visible.

Is there a way to escape translated strings based on content types (or context it is used in or something else more appropriate) when tokens are being replaced ?

@turquoiseowl
Copy link
Owner

Sorry, i18n doesn't support different messages per content type.

Have you tried using HTML entities, in this case &apos; ?

@turquoiseowl
Copy link
Owner

Or even better: &rsquo;

@Sshnyari
Copy link
Contributor Author

Sshnyari commented Oct 24, 2016

Yep, but it doesn't go well with json data (using .net webapi)

@Sshnyari
Copy link
Contributor Author

@turquoiseowl
Copy link
Owner

If I understand you correctly, you are effectively encoding HTML into Javascript. If that is correct, it seems more than reasonable to me to have HTML entities in that Javascript. I'm not clear where JSON comes into it.

@Sshnyari
Copy link
Contributor Author

Well, the token can either be in a javascript file, an html file, or a json file (or json response from a web api)

@turquoiseowl
Copy link
Owner

Yes, good call. I've added some functionality -- please see the commit.

@Sshnyari
Copy link
Contributor Author

Cool, thanks man

@mesteves
Copy link

Hi, I have a similar case, but somewhere between requests and roundtrips, the javascript file misses the translation :( What could be the cause for that?

image

image
I even tried other approach placing the tokens in different lines:
var p1 = '[[[[No guidelines.]]]]'; var p2 = '[[[[Please choose guidelines to evaluate.]]]]'; var message = '<strong>' + p1 + '</strong> ' + p2;

Thanks for any help that you can provide.

@turquoiseowl
Copy link
Owner

@mesteves Sorry, I'm not clear on your problem/question.

@mesteves
Copy link

Hi @turquoiseowl thanks for your feedback, those images on my first post, it's the resulting javascript after comming from the server. The first one, if you notice, is in Czech with the parameter %0 replaced by the corresponding value. I have those string in a angularJs controller and when the first time page loads, everything is ok, I do some postback's and still ok, but after 4/5 postbacks/roudtrips to the server, the angular controller that comes from the server losses the translations and serves the file with the second format (in the default language and with no parameter substitution). Don't know if I was more clear now to expose my problem. If you need some more information, please tell me.

@turquoiseowl
Copy link
Owner

This sounds like the URL for the AJAX/$http requests isn't carrying across the language tag. Diagnosing at the HTTP level would help to see full details of the problematic request. Maybe #267 will help.

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

3 participants