25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 6 ■ Using Resource Files<br />

Next, let’s create your XML file configuration and see how you are going to define and use your dictionaries.<br />

See Listing 6-18.<br />

Listing 6-18. mydocuments-i18n-context.xml<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

In Listing 6-18, note that the property to use is basename; this will accept a fully qualified name with the extension<br />

properties. In this case, it will look up the dictionary files. Remember that you have dictionary.properties,<br />

dictionary_en.properties, and dictionary_es.properties. The dictionary without the underscore character is the<br />

default dictionary. The _en means the English dictionary and the _es means the Spanish dictionary.<br />

Now let’s create your unit test as shown in Listing 6-19.<br />

Listing 6-19. MyDocumentsI18nTest.java<br />

package com.apress.isf.spring.test;<br />

import static java.lang.System.out;<br />

import java.util.Locale;<br />

import org.junit.Before;<br />

import org.junit.Test;<br />

import org.slf4j.Logger;<br />

import org.slf4j.LoggerFactory;<br />

import org.springframework.context.support.ClassPathXmlApplicationContext;<br />

public class MyDocumentsI18nTest {<br />

private static final Logger log = LoggerFactory.getLogger(MyDocumentsI18nTest.class);<br />

private ClassPathXmlApplicationContext context;<br />

@Before<br />

public void setup(){<br />

context = new ClassPathXmlApplicationContext<br />

("META-INF/spring/mydocuments-i18n-context.xml");<br />

}<br />

@Test<br />

public void testMenu() {<br />

log.debug("About to Translate...");<br />

72

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!