Download presentation
Presentation is loading. Please wait.
Published byCorey Woods Modified over 9 years ago
1
Internationalization and the Java Stack Part 2 Matt Wheeler
2
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)
3
Overview Stack provided internationalization tools Message source expression language resolver JS Message Source RequireJS Message Source Internationalization best practices Internationalization testing Dynamic pseudo translation
4
Expression Language Resolver Provided message resolver can be utilized in EL http://code.lds.org/maven- sites/stack/module.html?module=web- spring/#El_Message_Source ${messages['abc.def.ghi']}
5
JavaScript MessageSource Configuration classpath:messages messageSourceController
6
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}“ }; alert(msgs['index.welcome']);
7
RequireJS MessageSource Configuration classpath:messages
8
MessageSource with RequireJS Usage define([ 'tmpl!example/templates/list', 'i18n!nls/messages' ], function (listTemplate, messages) { alert(messages['createExample_loading']); }; define({"root": { "createExample_loading":"Carga…", "createExample_form_label_data":"Datos:", "createExample_form_label_name":"Nombre:", "createExample_form_message_success":"Ejemplo \" \" se ha …" "createExample_form_button_save":"Cree Ejemplo“ } });
9
DEMO
10
Some I18n Best Practices Externalize ALL translatable text Do not concatenate translations Create duplicate / separate resources Avoid text in images Introduce pseudo-translation tool
11
Externalize ALL Text Example – Name: – Notice that we have concatenated the : with the translated name label "Name:" including the colon should be externalized – Concatenation itself is a best practice violation – : and associated formatting can be different – It might also be in a different order #messages.properties name.label=Name #JSP page ${messages['name.label']}: #messages.properties name.label=Name: #JSP page ${messages['name.label']}
12
Do NOT Concatenate Translations For example: Attempted usage: #messages.properties key1=Someone named key2=likes hiking. #JSP Page ${messages['key1']} Billy ${messages['key2']}
13
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.
14
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
15
DEMO
16
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
17
DEMO
18
I18n Testing (Dynamic Pseudo Translation) Configured to translate for specified locales Simplifies testing – Expansion – Special characters – Completeness – zz locale http://code.lds.org/maven- sites/stack/module.html?module=web- spring/#Pseudo_Translation_Message_Source_Faca de
19
Dynamic Pseudo Translation The trick (delegate) <bean id="delegatingMessageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> classpath:messages
20
Example
21
DEMO
22
Credit where credit is due http://wiki.answers.com/Q/5_words_that_have_mult iple_meanings http://en.wikipedia.org/wiki/Homonym
23
Lab 1: Internationalize a page https://tech.lds.org/wiki/Internationalization_and_ the_Java_Stack_- _Part_2#Lab_1_Pseudo_Translator
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.