4:00 pm - Saturday February 25, 2017

Spring Internationalization (i18n) Example Program in Eclipse

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

Project Structure

 

 

 

 

Jar Files    How To Add Jar Files

 

spring-config.xml

  

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
	<bean id="messageSource"
		class="org.springframework.context.support.ResourceBundleMessageSource">
		<property name="basenames">
			<list>
				<value>com\\candidjava\\language</value>
			</list>
		</property>
	</bean>
</beans>


SpringProperties.java

package com.candidjava;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.Locale;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.sun.java_cup.internal.runtime.Scanner;

public class SpringProperties {

	public static void main(String[] args) throws IOException {
		ApplicationContext applicationContext = new FileSystemXmlApplicationContext(
				"config\\spring-config.xml");

		Locale english = Locale.ENGLISH;
		System.out.println("Enter ur First Name");
		DataInputStream d = new DataInputStream(System.in);
		String firstName = d.readLine();
		System.out.println("Enter ur Last Name");
		String lastName = d.readLine();

		System.out.println("English:");
		System.out.println(applicationContext.getMessage("nameMsg",
				new Object[] { firstName, lastName }, english));
		// ***English
		System.out.println("Dutch:");
		Locale dutch = new Locale("du");
		System.out.println(applicationContext.getMessage("msg", null, dutch));

		System.out.println("French:");
		Locale french = new Locale("fn");
		System.out.println(applicationContext.getMessage("msg", null, french));
	}

}

language_du.properties

msg=Welkom op de lente




language_en.properties

msg=welcome to the spring community
nameMsg=My name is {0} {1}



language_fn.properties

msg=Bienvenue au printemps

OUTPUT:

 

DOWNLOAD+SOURCECODE  + JAR FILES

 

 

 

Filed in: Z-A Spring Codes

Comments are closed.