|
@@ -0,0 +1,25 @@
|
|
|
+package com.lovecoding.i18n;
|
|
|
+
|
|
|
+import org.springframework.context.support.ClassPathXmlApplicationContext;
|
|
|
+import org.springframework.context.support.ResourceBundleMessageSource;
|
|
|
+
|
|
|
+import java.util.Locale;
|
|
|
+
|
|
|
+public class SpringI18nDemo {
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+
|
|
|
+ ClassPathXmlApplicationContext context =
|
|
|
+ new ClassPathXmlApplicationContext("bean.xml");
|
|
|
+ ResourceBundleMessageSource bean = context.getBean(ResourceBundleMessageSource.class);
|
|
|
+ Object[] o = new Object[]{
|
|
|
+ "Hello", "Learing Java"
|
|
|
+ };
|
|
|
+ String i18n = bean.getMessage("username", o, Locale.CHINA);
|
|
|
+ System.out.println( i18n );
|
|
|
+ String i18n1 = bean.getMessage("username", o, Locale.US);
|
|
|
+ System.out.println( i18n1 );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|