Internationalization and the Java Stack Part 2 Matt Wheeler
Notes This is a training NOT a presentation Please ask questions Prerequisites – Introduction to Java Stack – Introduction to Spring – Basic Java and XML skills – Internationalization and the Java Stack Part 1 – Installed LdsTech IDE (or other equivalent)
Overview Stack provided internationalizaton tools Message source expression language resolver JS Message Source Require Message Source Internationalization best practices Internationalization testing Dynamic pseudo translation
Expression Language Resolver Provide message resolver can be utilized in EL sites/stack/module.html?module=web- spring/#El_Message_Source ${messages['abc.def.ghi']}
JavaScript Source JS Configuration messageSourceController
MessageSource with JS Usage in a JSP page var msgs = {"index.welcome":"Welcome","accessDenied.accessdenied":"Access Denied","def":"{0} asdfa asdfasd {1} asdfasd asdf ","index.mainpage":"Main page - {0}","dataAccessFailure.problem":"Sorry, a problem occurred while accessing the database.","accessDenied.accessdeniedinfo":"You do not have sufficient rights to access this page.","header.logout":"Logout"}; alert(msgs['index.welcome']);
Some I18n Best Practices Externalize ALL translatable text Do not concatenate translations Create duplicate / separate resources Avoid text in images
Externalize ALL Text Page label - "Name: “ "Name:" including the colon, and not just "Name" externalized – Otherwise require contatenation - the “Name”coming out of the bundle with : on the page : and associated formatting can be different in different languages – It might also be in a different order
Do NOT Concatenate Translations For example: Attempted usage key1=Someone named key2=likes hiking. ${messages['key1']} Billy ${messages['key2']}
More Correct Way Create a single string with replaceable parameters Sentence maintains context – Parameters can be moved around to accommodate language grammar For example: And then it will be used as follows: key=Someone named {0} likes hiking.
Create Separate Resources Counter intuitive to code reuse concept Same English strings should not be shared Within the same application, or even the same page Create a separate key value pair for each occurrence Words change based on context Concept of masculine and/or feminine, age classes, … Or usage Similar English words may not be similar in another language
Avoid Placing Text in Images An image that contains text will require a new image for each language It will also require a custom way to load the image Impose the text over the image, using.css or other ingenious alternative – Then the text can be stored in the resource bundles with all other strings – And it won’t require a new image for each language
I18n Testing (Dynamic Pseudo Translation) Configured to translate for specified locales Simplifies testing – Expansion – Special characters – Completeness – zz locale sites/stack/module.html?module=web- spring/#Pseudo_Translation_Message_Source_Faca de
Dynamic Pseudo Translation The trick (delegate) <bean id="delegatingMessageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> classpath:messages
Lab
Other Considerations Avoid cultural references Avoid sports analogies Avoid colloquialisms Non-translatable names Avoid animal / hand gesture icons Understand color connotations by culture – Blue is safest color generally
asdf
Lab 1: Internationalize a page ab_2_Dependency_Injection
Credit where credit is due ials/j-i18n/section2.html