My organisation is about to embark on the long process of internationalizing (i16g?) its corporate website. The website is a mix of Java EE (JSP/Servlets, no EJB) and static content pushed from the (Documentum) WCM.
While I have experience using the "built-in" mechanism of using ResourceBundle's along with the associated properties files for each language/locale (containing the "KEY=Translated value" approach), where we simply reference the KEY value where we want the translated text to appear.
My director has mentioned that he has used a different approach at a previous organisation whereby they used a 3rd-party library (he does not recall the actual name) which included the actual [english] text in the webpage (to aid developers) which was replaced at run time with the translated content from the config xml file. (anyone know which library this would be?)
I am interested in what other approaches/libraries/frameworks there might be out there to facilitate this.
Thanks
Your boss probably meant gettext, just like #Pawel Dyda mentioned, but cosmopolitan may also be of interest to you.
My company also maintains a GNU gettext-related library for Java (and very soon with extensions aimed at Scala).
Not only does it support all of the goodness of GNU gettext, it also simplifies output AND input of date/timestamps and currency, include facilities for using "wiki" formatting in translations (so you can output HTML bold on a word, for example), java message formatting, generalized "escape" support (so the output can be auto-escaped for inclusion, say, in HTML), and currency rounding.
It is open-source, and currently on github at https://github.com/awkay/easy-i18n/
When I hear you are using ResourceBundles, I see something like this:
ResourceBundle rb = ResourceBundle.getBundle("messages", locale);
String someString = rb.getString("some.key");
If this is your approach for Java Server Pages (using such snippets in scriplets), this is wrong. Instead, you should use JSTL or Spring message tags.
As for your inquiry, I believe they used Gettext (sorry no link, as I am running out of time).
This is not necessary the best approach. JSTL approach is the most common for JSP and you should stick to it, unless you have very good reasons not to.
It worth looking at http://alexsexton.com/blog/2012/03/the-ux-of-language/ it has a good explanation of the idea behind gettext and the limitations of the gettext design a better approach to gettext is the ICU message format this is what the JDK MessageFormat class is based, on http://site.icu-project.org/home there is also a javascript library based on the ICU message format https://github.com/SlexAxton/messageformat.js
I hope, it's not too late to suggest one more solution: https://github.com/resource4j/resource4j
This library has integration with Thymeleaf web page renderer, which solves the problem you've mentioned: you include in page template the English text and then substitute it with localized version in runtime.
Related
I need to parse a String from HTML to Textile.
I've been looking at Textile4J, Textile-J, JTextile, PLextile.
But so far, none of them provide the functionality I'm looking for.
They do provide the reverse functionality (Textile to HTML).
Worst case scenario, I can use another programming language, but I have not really looked into that.
For now, I don't believe the functionality I want is available in any java Textile library.
I'll try and update this post if and when that changes.
Based on the libraries mentioned above, I have created my own (limited) functionality.
There are also several solutions available in python / ruby.
i'm working on a project which needs to support internationalization.
the solution we thought of is:
create HTML templates with placeholders for language (i.e. home.html).
create an i18n directory with files such as: "language_en_GB.json".
on the build process have them merged together to create an output HTML. the output file will sit on a language based directory (such as "views/en_GB/home.html" or "views/fr_CA/home.html").
so basically this:
<h1>{{i18n_welcome}}</h1>
<h2>{{userName}}</h2>
merged with this:
{
welcome:"Welcome!"
}
will become this during a build proccess:
<h1>Welcome!</h1>
<h1>{{userName}}</h1>
i have a few question and appriciate your input.
is this a good approach for i18n?
do you know of a templating engine that does that i18n process well?
is there a solution for client side "baking". i would like a UI developer to be able to bake localy as well.
There are several frameworks that support i18n out of the box depending on your needs and what you are currently using in your code. As a pure templating engine, you can take a look at Velocity or Freemarker. For a more complete framework, you can look at Spring and Spring example and Struts and Struts2 example.
There are, of course, numerous other options as well. I'm just listing four of the most popular that I've seen people use.
Basically, for any of the frameworks, you create resource bundles for each language (named using the language for the specific bundle. Ex: language_en_GB.properties). So your thought process is pretty much in line. Basically you start with your html file and include your placeholder. In your resource bundle for each language, you specify what the string is supposed to be. After that, the framework does the merging on the fly for you, using the appropriate resource bundle for the language in question.
So you're pretty much on the right track - it all becomes a question of integrating properly with your framework and leveraging it to do the merging instead of doing it during your build pipeline.
You failed to provide the necessary details, so I can't really answer your question. I can only say that what you plan seems to be another wheel re-invention (but not as round as original one).
There are certain i18n best practices. In Java world it usually mean using Resource Bundles (in form of properties files) and some mechanism like JSTL to translate them when the page is being rendered. This is the best approach, as you won't need to re-compile anything to introduce the support for another language.
If you care about providing support for client-side scripts, it is usually done by writing out some array from the web page and accessing it on the client side. I think this is the most common solution. Another would be having some web service to provide you with translations and read it via XHR (i.e. AJAX), but that may be problematic. Anyway, you need to push the translations from the server side to the client side somehow.
And of course you need to read them from resource bundles.
From what you wrote it seems that you want to build some kind of static web page, backed by the application server (thus static web pages compilation). If I guessed correctly, honestly using Java for it is a bit overkill. You'd better go with some CMS software like Joomla, Drupal or jEase.
I need to parse a simple HTML page with a simple form in it. The answers to similar questions on StackOverflow suggest using one of a large variety of non-standard Java libraries such as TagSoup, JSoup, HTMLParser and many others.
However, a web search revealed that there exists some standard functionality in Java SE via this class: http://docs.oracle.com/javase/7/docs/api/javax/swing/text/html/parser/ParserDelegator.html
My sub-questions are:
Is it really true that the standard ParserDelegator class can parse a use case like mine?
What are the limitations of the standard library that create the need for so many non-standard libraries?
Does the fact that ParserDelegator is within swing preclude using it in a regular EC2 cloud server for a web application? Would I have to jump through a lot of hoops to get around the headless aspect or would it be just a small tweak to the configuration?
If the standard one is not recommended, which non-standard one should I use, given: (a) my desire to not stray far from the standard; (b) my simple use case; (c) desire for a mature reliable implementation; and (d) no size or weight limitations since this is a server application as opposed to an embedded client. API is a far lower priority so while I do appreciate JSoup's CSS selector like API, the other concerns (a) through (d) override it.
Thank you.
JDK has built-in HTML parser that supports HTML 1.0 or so. It should support parsing of base text formatting tags and forms.
The reason to use other, third party parsers is requirement to support "real" HTML pages DHTML, JavaScript etc.
JSoup is one of popular parsers that can do the job. For more information about other implementations please take a look on the following discussion:
Pure Java HTML viewer/renderer for use in a Scrollable pane
Does anybody know of GUIs for generating XMLs? This means the user will not be presented with an IDE with support for XML for him to type XML codes. This would be helpful for non-technical people using the system.
I know this sounds easy, given many libraries that can help in generating XMLs. The issue here is that the schema is really that flexible rather than being straightforward like representing books in a library with their properties.
Imagine HTML, where we can create font tags inside a body, a table, a div, or nested even within itself. The solution is a WYSIWYG application that allows user to generate html codes (XML). However, that is good for XML applied in webpages since they involve visual aspect and design. My application of XML would focus on representing some conceptual and computational definitions, much like sql-like syntax, but more than that.
I'm actually after the approach or previous works done or tried, although having a library/working framework for that would be better. Btw, I'm using Java for this project. Currently, I'm just thinking of presenting element tags where user will be able to drag and drop them and nest them with each other. And perhaps, assist them through forms in inputing values for XML attributes. I'm still hoping if there are better ideas from the community.
Thank you.
I think you need to separate the eventual representation (XML) from the abstraction presented to your users. Is your information presented to the user in tree form? If not, do what is convenient for the users and sweat the XML conversion yourself.
There are many tree-based editors that use "meaningful tiles and icons" instead of XML. For example, look at how Eclipse's plug-in editor does the extension of existing points. You get a tree view and can add properties (typically in a separate group box). But you could write a smarter editor that has everything in the tree.
On the other hand, sometimes the XML representation should really be hidden despite its flexibility. A good example is the plugin.xml for Eclipse-plugins. Look at how the editor for that file looks nothing like XML. It is structured logically for the needs of the user, and the code in the background generates the XML.
I looked for this exact thing a couple of months ago. The only one I found was at http://www.jaxfront.org/pages/. It is Java based.
Note that I ended up going with Actipro Software's SyntaxEditor for .NET WinForms which, although does not give me a GUI, gives the app good IntelliSense-like prompting (derived from an underlying XSD) when editing XML.
The W3C answer to your question is XForms. Unfortunately XForms is not directly supported by browsers, although there is a Mozilla plug-in (show and edit even local files, but only in Mozilla). Many XForms solutions are available, an interesting and free one is XSLTForms (http://sourceforge.net/projects/xsltforms/) which translates XForms into HTML Forms (works with every major browser, but local files can only be shown, not edited due to the limitations of Javascript).
Also take a look on Altova Authentic.
I know it is sometimes hard for non technical people to get familiar with a tool like eclipse, but it comes with very good and easy to use XML editors. Supporting auto-completion, validation, verification. I am not sure if there is a pre configured eclipse derivate which is focused on xml editing, but you could configure such a thing quite easily.
I am staying India(has more than 20 languages) I am trying to implement java-internationalization in the website.
But in Locale.getAvailableLocales() the local languages are not available. is it possible to implement internationalization in my case?
If possible what will happen to the fonts? How am i going to load the proper fonts in the client browser?
Which framework to implement Struts or Spring?
I can't claim to be an expert in Java internationalization - all of my work which cared about localization dates back to when we had to do all that by hand.
If you don't want to do that (which is no harder now than it was back then), it appears that you can still make use of Java's automated I18N services.
It appears that in order to support languages, number formats, etc, which are for locales not yet supported, you'll have to create a Locale-sensitive service provider, which got much easier in 6
There's what looks like a good tutorial here.
I think you are asking multiple questions here, and they are orthogonal to each other.
For the Locale.getAvailableLocales() question. If the built-in locales are not enough, you can simply create more. The locale object just represent the locales that your program knows, it has nothing to do with you the system performs --- more specifically, no corresponding locale object does not mean you cannot support the locale.
For the font, typically you will use UTF-8 for a i18n site, so as long as your content type and charset is set properly it should render correctly in the client browser.
The framework question really depends on what you are trying to accomplish, and what do you want to gain from it.
I believe there are more locales available when using a JDK than a JRE.
Locale.getAvailableLocales() returns a list of locales whose LocalData is installed in sun.text.resources package of JRE.
This list may not matter to you. Currently, the LocalData only contains local number and date formatting information. If you don't have any special format, you can just pick a locale whose format is the same as yours, like "en_IN".
Charset is another issue. If you localized resources are in Unicode, you are all set. Otherwise, you need to make sure the charset/encoding is supported by Java so it can convert it correctly.
Don't worry about font. It has nothing to do with server. It's either specified in HTML or CSS. As long as the browser supports the fonts, you will be fine.
Java itself is I18N ready so it doesn't matter which framework you use. Struts provides taglib for I18N (bean:message) but you can also use JSTL (fmt:message).