4

What is the best practice, when it comes to views' translation in MVC design pattern, in multilingual website:

  1. Always have only one view file and translate its particular strings with a framework translation function.

  2. Always have as many views as website supports, directly translated, one for each language, and let framework internals load particular language-specific view file for language currently selected by user.

Which of these two options should I use (if there isn't any third one) and why?

trejder
  • 2,386
  • 3
  • 19
  • 39
  • the people responsible with translations will find it easier to work with a list of strings rather than sifting through the view markup for strings to translate – devnull Jun 28 '14 at 19:21

1 Answers1

8

The proper choice is using the single view with the strings stored in the appropriate localization framework for the view.

There are two main reasons for this:

  1. It's DRY. There is one view that is used for all the languages. Consider the joys you will have when you need to change the layout on the view if you have one for each language... you've likely got English and then the FIGS set... and possibly CJK too... That's eight copies of the same view. You're going to miss one and you're going to make a mistake in another one. One view.

  2. The industry behind localization is based on taking a file of strings and translating that file. You might have this person in house instead... either way, they aren't programers. The markup for the view itself - be it php, jsp, erb, or a chunk of javascript. You don't want to be sending them your code, and you don't want them making mistakes in translating your variables, styles, and structures (<font color="black">test</font> becomes <fuente colorido="negro">prueba</fuente>). You, the programmer understand what needs to be translated and what does and giving just this to the person doing the translation makes it less likely to introduce errors.

Use the localization framework. It will make it easier for you, it will make it easier for the person doing the translations.

gnat
  • 21,442
  • 29
  • 112
  • 288
  • I don't know, if I can expect better, more professional and straight-to-the-point answer. Thank you. – trejder Jun 28 '14 at 19:50
  • 3
    @trejder true story, company that we had translate some documentation also translated the xml schema that was in the documentation. The client had difficulty getting it to validate. –  Jun 28 '14 at 19:53
  • FYI `` is fully supported in HTML Cinco, so its not the best example. – Graham Sep 03 '14 at 16:32
  • @Graham, are you sure about that? plus translation always targets content rather than structure, markup... – joe Sep 03 '14 at 16:38
  • @Graham I don't see that working on [jsfiddle](http://jsfiddle.net/ptL3ekou/) - do you have an example page where that *does* work? It was an issue for me when I dealt with translations back in '08. Also, it would be trivial to modify it to `test` and `prueba` where the class attribute shouldn't get translated... or put an `onclick` handler in there with the function name getting translated. The demonstration of the issue remains. –  Sep 03 '14 at 16:50
  • Alas, my attempt at sarcasm has sailed over yet another set of heads. Clearly my career choice as a programmer instead of a comedian was the correct one. I would have thought "HTML Cinco" (Spanish for "HTML5") would have been a dead giveaway for the joke. – Graham Sep 03 '14 at 16:56
  • @Graham the stuff that people have stuffed in html5 still surprises me at times... While I haven't seen it, I wouldn't be at all astounded if [FIGS](http://en.wikipedia.org/wiki/FIGS) language alternatives for tags were part of some proposal to update the tags and attributes. Well, maybe not French - [L'Académie française](http://en.wikipedia.org/wiki/Académie_française) might have some issue with some of the French words being created or misused. ;-) –  Sep 03 '14 at 17:00