Presentation is loading. Please wait.

Presentation is loading. Please wait.

Internationalization

Similar presentations


Presentation on theme: "Internationalization"— Presentation transcript:

1 Internationalization
Matt Wheeler

2 This is a training NOT a presentation Please ask questions
Notes This is a training NOT a presentation Please ask questions Prerequisites Introduction to Java Stack Basic Java and XML skills Installed LdsTech IDE (or other equivalent – good luck there ;) A few disclaimers to get things started

3 Internationalization in general
Overview Internationalization in general Java Internationalization (ResourceBundle) Spring Internationalization (MessageSource) MessageSource vs. ResourceBundle Spring Helpers Locale change interceptor Locale resolver JSP tags

4 Internationalization in General (I18n)
"Internationalization, in relation to computer programming, is the process of designing and writing an application so that it can be used in a global or multinational context. An internationalized program is capable of supporting different languages, as well as date, time, currency, and other values, without software modification.“

5 Internationalization (continued)
"Internationalization is the process of designing software so that it can be adapted (localized) to various languages and regions easily, cost-effectively, and in particular without engineering changes to the software. This generally involves isolating the parts of a program that are dependent on language and culture. For example, the text of error messages must be kept separate from program source code because they must be translated during localization.“

6 Localization (L10n) "Localization is the process of adapting a program for use in a specific locale. A locale is a geographic or political region that shares the same language and customs. Localization includes the translation of text such as user interface labels, error messages, and online help. It also includes the culture-specific formatting of data items such as monetary values, times, dates, and numbers."

7 Localization (continued)
"Localization is the process of designing and writing an application capable of dealing with a specific regional, country, language, cultural, business, or political context. In a sense, every application written for a specific area is localized, although most of these effectively support only one locale. Usually, though, true localization is achieved by core code that accesses locale, location, political, or other specific components and modules, along with translating text as appropriate for the audience. A properly internationalized program facilitates and provides a foundation for localization.“

8 First Step of Internationalization
Extract translatable text from code Load resources for a specific locale Inject locale specific resources into the application

9 Java Internationalization (ResourceBundle)
ResourceBundle is the basis of Java internationalization Backed by different data stores Property files Java source code Represents a collection of key/value pairs for a given location For example: ResourceBundle.getBundle("bundle").getString("abc") ResourceBundle.getBundle("bundle", Locale.ITALIAN).getString("abc")

10 DEMO Java-i18n-demo

11 Spring Internationalization (MessageSource)
MessageSource is the root of Spring internationalization MessageSource interface And abstraction to the actual text store of translated files Data store can be properties files, database, MarkLogic, … Implement the interface for the given resource store Implementation of MessageSource can use resource bundles as in native Java

12 MessageSource Example
Place resource bundles in src/main/bundles Configure the message source as follows: <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basenames"> <list> <value>classpath:messages</value> <value>classpath:otherbundle</value> </list> </property> </bean>

13 Utilize the MessageSource
Inject MessageSource Utilize the MessageSource @Inject private MessageSource messageSource; @RequestMapping(value="/", method=RequestMethod.GET) public void getAStringInCode(ModelMap model) { String message = messageSource.getMessage("abc", null, "default", Locale.US); //do something with message return; }

14 MessageSource vs. ResourceBundle
MessageSource allows all resources to be conglomerated together MessageSource does parameter replacement automatically MessageSource allows for a default (in case message is not found)

15 Spring MessageSource taglib
uri=" prefix="spring"%> <spring:message code=“messsage.key"/>

16 MessageSource Expression Resolver
Provide message resolver can be utilized in EL taglib prefix="web-spring" uri=" %> <!-- This makes the internationalized properties of the default MessageSource available as a map in the specified scope--> <web-spring:message-source var="messages" scope="request"/> <!- Referecence the messages in EL by key --> ${messages['abc.def.ghi']}

17 Spring MessageSource taglib

18 Lab 1: Internationalize a page

19 Credit where credit is due


Download ppt "Internationalization"

Similar presentations


Ads by Google