In my HTML page I'm loading my translation with Thymeleaf like that:
<button type="button" ng-click="$ctrl.resetData()" th:text="#{general.reset}">Reset</button>
Is it possible to translate text wich is hard coded in my JavaScript code?
'Loading Data...' should be translated with th:text="#{general.loadingData}" <- but this is the way I would translate it im my HTML page, this doesn't work for JavaScript Code. All the translations are in a messeges_en.properties file.
How can I translate the text in JavaScript?
function(request: any) {
asLoading.show('Loading Data...');
return request || $q.when(request);
}
You should use javascript Intl API.
FormatJs is a modular collection of JavaScript libraries for internationalization that are focused on formatting numbers, dates, and strings for displaying to people.
It has support for ICU message format (International Components for Unicode) which is also well supported in java as well.
So you can expose your translations in ICU message format and consume them from both java and javascript.
In general, it is better to treat javascript and java code as separate applications as opposed to treating javascript as something that is tacked on top of a java template language like thymeleaf.
Related
I am contributing to an open-source project and it seems that all of the website's pages have .ejs.html format.
what is the difference between these two formats ?
ejs is used to embed javascript inside html code.why use .ejs.html instead of just html.
I'm developing web script for Alfresco 5.0d CE and encountered an issue: I cannot interpolate datetime value of type org.mozilla.javascript.NativeDate in my FreeMarker template directly (or with embedded FreeMarker methods ?date, ?time or ?datetime).
${var.startDate}
interpolates into
org.mozilla.javascript.NativeDate#<some_hash>
Please, advise me, how can I do that?
Can you introduce your own FreeMarker utility methods in Alfresco? Because then there you can call the static org.mozilla.javascript.Context.toType(valueFromRhyno, Date.class) method to convert the Rhyno JavaScript date to a Java java.util.Date. So let's say you implement that in Java, then expose that utility to FreeMarker. I don't know how to do that in Alfresco, but FreeMarker itself supports that. Then you can do something like ${myJsUtils.toJava(var.startDate)}.
Actually, FreeMarker's ObjectWrapper facility is designed to deal with these kind of mismatches. If you can use a custom ObjectWrapper, then it could just work magically, as then FreeMarker will know how to convert the Rhyno objects automatically. But I guess changing such a core setting under Alfrescho can be tricky. Too bad they themselves didn't do that.
Is there an implementation for RFC3987 (Internationalized Resource Identifiers ) done in JavaScript so that I can use it to check if a string is a valid IRI? I need it for a script done with NodeJS.
I know that HTML doesn't support IRI links but I am not using to check HTML documents.
IRI: A utility for converting and parsing URIs and IRIs can be helpful
My translation mechanism works serverside with the jinja2 template engine, webapp2's i18n function with the magic _ function and now I need it for Javascript to localize just a few strings but I couldn't find a good implementation. Is there one?
I'd like a solution for localizing my web app. The javascript strings are just a few but I need a translation mechanism and the dictionary is .po and .mo files. Ideally I'd like javascript to take the same dictionaries as python does (the .po files)
I don't need extractions, what I need is the _ function plus some way of determining user language and loading the translations, not just for a single language but for all my languages. I looked at some solutions but they only handla one translation at a time and I need to handle many.
For instance, http://www.zomeoff.com/jsin/jsin.1.2.unit.test.html does a successful job but this is only one localization. I need to harmonize the translations so that the same language is used by both the python jinja2 templates and javascript.
Do you have s suggestion or can comment my situation?
Thank yo
Javascript Gettext
You could probably use polib and json to generate the JSON on the fly though.
I'm building a Javascript preview function for a blog back-end (much like the one used on this website), and I'd like to be able to parse some custom tags that normally get parsed by PHP. I am wondering if it's possible to use the JS XML parser to parse content from a textarea that would look like:
<img=1>
Use for
<url=http://apwit.com>testing</url>
purposes only!
I read on another question here once that using regex to parse things like this is a bad idea because of the many many exceptions there could be. What do you think?
Use this: http://www.w3schools.com/Xml/tryit.asp?filename=tryxml_parsertest2
It parses xml from a string and uses the fast native XML parsing engine from the browser.
Explanation and discussion:
http://www.w3schools.com/Xml/xml_parser.asp