Open pySilver opened 9 years ago
@pySilver How exactly is translation not working? Are you using the translate
directive, filter, or the JS API? If possible, can you post some code?
@gabegorelick I'm using translate
directive
This p
would work (both extraction and translation)
<p translate>
Configure your website by navigating to <br> <strong>Ad Tools → Configure Contextual Ads</strong>.
</p>
this p
translation woul be extracted but translation won't be applied even if it exists
<p translate>
Configure your website by navigating to <br> <strong>Ad Tools → Configure Contextual Ads</strong>.
</p>
the only difference here is html entity →
vs →
Yup, known problem. I strongly recommend using UTF-8 instead of escaped entities for now. Every computer on the planet supports it nowadays.
@rubenv What's the source of this bug? It seems very strange to me.
I have no idea. There's an easy way to work around it (which is also much nicer to translators), so we never bothered looking into it. Just use UTF-8 :-).
I found out that some angular template compilers convert '&', '>', '<', etc. in '&', '>', '<' ant this converted string will be passed to angular-gettext, which will be failed to match, since strings are collected on original file. In my case there was gulp html2js
plugin.
So there are 3 possible solutions to workaround this problem:
I think this is a bug and should work: <h1 translate>me & you</h1>
. It get's extracted but not translated.
But... if I add <h1 translate>me & you</h1>
and also extract and translate then they both work. :)
The "use UTF-8 character instead" workaround is unhandy if the character is not visible or not distinguishable from another character. For instance, U+00AD
(soft hyphen) has no visual representation, but permits hyphenation in HTML.
I used the following workaround:
<span ng-init="shy = '\u00ad'">
<span translate>foo{{shy}}bar</span>
</span>
Special characters like &
inside a label cannot be translated in IE/Edge because here, the DOM is used to return the label key, which will return it encoded as &
. Is there any workaround for this?
Ran across this caveat myself today. The problem, as I noticed it, is that when compiling strings, the text as it was written is passed to the template.pot
html entities and all.
The resulting .po
file also has those entities as originally authored.
In use, the translate directive uses javascript to get the html of the element it was applied to, and sends it to the compile function for processing. At this time, the html entities have been converted into their plain text counter part. Then the lookup for a translation string fails as the msgid is different in the compiled translations and what is being used at that time.
I prayed to google for possible answers on how, with javascript, to get raw contents of an element without interpreting special characters, and it seems this is a limitation of how javascript is able to access this information.
I think a possible workaround may be to manually call the gettextCatalog.getString()
method with your string in code in your controller. But that sounds truly awful.
A possible resolution this package could do is interpret these html entities when compiling strings to prepare the msgid to have the literal character in it, which sounds moderately better, but still not ideal as it limits compatibility of the characters you can use.
Extraction & futher translation of the string like this one, works fine:
But for string like the following one extraction would work, but translation would not:
Workaround for now would be using special symbols directly in a source code:
So clearly there is a problem with
&xxx;
symbols.