How to make localization in a web application?

There are several ways to do this, I can define the entire text element and load the json jiscript string from javascript and use some javascript to replace the text to do this ... In addition, I check that there are other ways to do this too. For example, some of them use the platform to do this. For example, J2EE has its own way to implement it. In addition, I can create a separate page for each language.

But is there a way to make localization flexible or proposed? Thanks.

+7
web-applications localization
source share
3 answers

It seems to me that you are really asking: how to implement Localizability correctly? Or how to program to simplify application localization.

This is an issue related to internationalization. You need to have a few things to make your application localized easily:

  • Do not print lines (this is obvious)
  • Do not print style information (do not use formatting tags such as <b>, <i>, <strong>, etc., do not use this: <p style="font-weight: bold;color: green;">Success!</p> ). This will prevent them from changing in localization (i.e., removing selected bold text from CJKV translations).
  • Avoid using complex messages (for example, "Function [A, B, C] executes [a, b, c]"). They are quite difficult to translate correctly. If you do not have a large number of variables, this will not hurt to add a few more lines to the resources.
  • Do not concatenate compound messages either with the concatenate operator or simply placing the lines next to each other (i.e. do not do this: String message = "Function " + function + " does " + whatItDoes; or this: #{['something']}<a href="whatever">#{['some_link']}</a>#{['something_else']} ), use formatting instead (i.e. MessageFormat.format("Hello, {0}. You have {1} new messages.", name, mailCount); ). This will not allow the translator to reorder the sentence, and this may be required due to the grammar rules of the target language.
  • Do not use raw placeholders (for example,% s% i% u) if the sentence has more than one of this type (instead, it is better to use a numbered placeholder, for example {0}, {1}). Again, sometimes translators have to reorder a sentence ...
  • Do not use language constructs specific to the English language (for example, “Paweł toolbar”, where Paweł is the name that I provided during registration). It is not possible to correctly translate it into several languages.

In addition, there are things to do:

  • Provide a style sheet override mechanism (so locator guys can change the style of an element)
  • Assign a unique identifier for each element of the displayed HTML page (this will allow them to target precise control with their overridden style)
  • Use UTF-8 encoding, wherever you are (explicitly HTML pages, emails, if any, but possibly resource files (i.e. properties))

There are many more things not related to localizability, such as the workflow of determining the language, formatting and checking numbers, currencies, dates (including setting the correct time zones) that you will need to take care of in a properly globalized application, but this is actually a different story .

+15
source share

Almost all decent web development frameworks have the concept of localized “resource packs”. You just make sure that you have a resource package for each supported language by your application, and each of them uses the same "key" to refer to a localized string. Just use the tool provided by the framework / language to load the text from the package based on the "key", and you should be good to go.

Regarding locale detection, again there are two ways to do this; automatic discovery, which is a fairly common mechanism used by web applications and a selection-based mechanism that uses a combination of automatic detection along with a drop-down list of languages ​​provided to the user.

The specific steps will be specific to the language / structure, so you can specify the structure that you use for specific answers.

+2
source share

On the other hand, if you are really asking how to extract translatable resources, I have to come up with a completely different answer.

I would not use a page for every idea of ​​the language. This can be good if you have few and far from static web pages. When you create a dynamic web application, especially if there is a chance of rapid growth in terms of the size of the content, this will kill you. And you cannot easily add new languages.

Localization on the client side will lead to a terribly slow application, do not do this. People will hate this.

And last, but not least, a typical implementation method (this is not the best word here because it has many other meanings). Localizability is just to extract strings for some resource files (i.e. ResourceBundle in the Java world) and save them in a separate jar (I would suggest one jar in the language named according to the locale identifier, i.e. ja.jar, de.jar, fr-CA.jar). The jar file must also contain an additional CSS file (the contents of which will be used to override certain styles). Everything else you find in my previous answer ...

0
source share

All Articles