5

I want to create a web site which can be viewed with two languages, one LTR and one RTL. This means that all content should be shown in either of the two languages.

My framework is Spring, and I'm using Tiles2, but I think this question is not framework specific.

The obvious solution to supporting two languages is having everything doubled (all JSP's, fragments, etc.), and you get the part of the tree which fits the language you chose. But this causes problems when changing the web site (you might forget to update the other JSP's), and is not scalable (try doing this for 5 or 10 languages).

I know I can use properties files to host strings for the different languages, but then my web site would be a huge collection of spring:message tags and will be a lot harder to maintain (what happens if I have a paragraph of 100 lines, does this all go into a single properties line?)

Is there any kind of framework, plugin, other, which solves this problem? Has anyone come across a clever solution to this problem?

Roger
  • 10,851
  • 3
  • 26
  • 39
TheZuck
  • 3,513
  • 2
  • 29
  • 36
  • Leaving Tiles/Spring/etc outside consideration, you can find here a basic JSP/JSTL example: http://stackoverflow.com/questions/4276061/how-to-internationalize-a-java-web-application/4278571#4278571 – BalusC Dec 29 '12 at 15:11
  • I've already used these technologies to create an internationalized web site which is why I'm looking for something different. I was thinking of creating an Eclipse plugin which will magically take any JSP fragment and embed internationalization into it, was just wondering if anyone came across anything of that kind. – TheZuck Dec 30 '12 at 14:24

6 Answers6

4

I've never realized a complete project, just some tests. I think this problem is not so big as it seems if you follow some simple rules. Here is what I would try to do:

  • Specify direction with <body dir='ltr/rtl'>. This is preferred versus CSS direction attribute.

  • Avoid different left/right margins or paddings in all CSS. If you must break this rule, probably you'll need to use two different files (ltr.css and rtl.css) containing all these different elements.

  • Sometimes you'll need to move some elements from left to right or vice versa. For example, in LTR you want a menu on the left, but in RTL you want it on the right. You can achieve this using CSS, but this sometimes is complicated if you are not an expert and you must test it in all browsers. Another option is to use some IF depending on the case. This last option will fit very well if you use a grid based CSS library, like Bootstrap.

  • Choose carefully which CSS and JS libraries you'll use. Obviously, pick the ones which offer RTL/LTR support.

  • Don't worry too much about the images. If you must change one image depending on the language is probably because it has some text in it. So, you must use different images anyway. This is a problem related to i18n, not a text direction issue.

  • Don't let your customer to be too much fussy about it. I think that with these rules (and maybe some more) you can get a good result. But if your customer starts complaining about one pixel here and another one there, you'll need to complicate all this and probably is not necessary.

  • About your language properties file. Yes, use them. Always. This is a good practice even when you are only using one language: HTML structure is separated from content, is very easy to correct or translate, some words or sentences are in only one file...

sinuhepop
  • 20,010
  • 17
  • 72
  • 107
2

Usually, web frameworks are used to build web applications rather than web sites, and there are quite few long static paragraphs. Most of the content is dynamic and comes from a database. But yes, the usual way of doing is to externalize everything to resource bundles, usually in the form of properties files.

Putting a long paragraph in a properties file doesn't cause much problem, because you can break long paragraphs into multiple lines by ending each line by a backslash:

home.welcomeParagraph=This is a long \
    paragraph splitted into several lines \
    thanks to backslashes.
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
1

RTL and LTR is one of the upper and more difficult i18n problems.

Basically its a Problem of the view-scope of the MVC-Model. This may also includes pictures and emotional differences like the color of the skin of people. In this case you better abadon to the solution HTML+CSS gives you.

In example:

<style type="text/css">
    *:lang(ar) { direction:rtl }
    *:lang(de) { direction:ltr }
</style>

The best practice is to ask members of the audience-group about what effect the webpages have to them.

Grim
  • 1,938
  • 10
  • 56
  • 123
  • thanks, but I'm looking for the translation solution, LTR/RTL can be solved in many ways, perhaps not perfect but at least it works. The issue I can't figure out is how to translate dozens of pages to many different languages without having a huge duplication of view code and without making the code absolutely unreadable by having all text in it become variables – TheZuck Jan 02 '13 at 20:56
1

I agree to most of solutions provided here. Your problem is more design (architecturally) oriented rather than technical. You need to choose path whether you need to keep this logic of internationalization on server (java) side or in static files.

In case you want to go for java side (preferable solution), you need to keep two properties file and use jstl tags. This minimizes your work in case you want to add another language in future. This is maintainable solution. I have seen applications supporting more than 15 languages and time zones. In fact release process gets pretty easy.

In case you want to go for keeping multiple css and other static files, you will soon find things running out of your hands pretty soon. I dont think this is a maintainable solution.

Said all this, I will leave this choice to the architect of application. He will be able to judge which way to go based upon the nature of application and constraints given to him.

Prateek
  • 523
  • 2
  • 13
0

You don't want to use everywhere. That's a pity because it is just the way you should do it. It is a bad practice to keep hard-coded texts in a jsp if you need internationalization.

Furthermore, Most of the modern IDE allows you to go to the variable declaration by doing ctrl+left click (or hovering the key) so that having a lot of variables in your code should not be a problem for maintenance.

autra
  • 895
  • 6
  • 21
0

First, you must distinguish, for each text element, whether it is a user interface element (e.g. button label) or redactionnal content.

user interface element labels will be stored in properties file that will have to be translated for each supported language (and provide a default value as a fall back)

redactionnal content will be stored in a content management system that you will organize in order to find easily a localized version of your content

Sporniket
  • 339
  • 1
  • 4