Internationalization Slide 1©SoftMoore Consulting.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

The Web Warrior Guide to Web Design Technologies
 2005 Pearson Education, Inc. All rights reserved Introduction.
Java Programming, 3e Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Chapter 3 - Java Programming With Supplied Classes1 Chapter 3 Java Programming With Supplied Classes.
Introduction to Java Programming, 4E
Alice in Action with Java Chapter 7 From Alice to Java.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Internationalization of Java Platform Presenter: Ataru Nakazawa Advisor: Xiaoping Jia Date: January 23, 2004.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Copyright © 2012 Pearson Education, Inc. Chapter 2 Introduction to Visual C#
Object-oriented Programming in Java. © Aptech Ltd. Internationalization and Localization/Session 12 2  Describe internationalization  Describe localization.
Copyright, 1998 © Alexander Schonfeld TIP Try and stay awake… kick sleeping neighbors. Don’t blink!
1 Exception and Event Handling (Based on:Concepts of Programming Languages, 8 th edition, by Robert W. Sebesta, 2007)
Developing User Interfaces (DUI) Chris North cs3724: HCI.
Introducing JavaBeans Lesson 2A / Slide 1 of 30 JDBC and JavaBeans Pre-assessment Questions 1.Which of the given symbols is used as a placeholder for PreparedStatement.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
A First Program Using C#
AITI Tutorial: Internationalization Coding for the world MIT AITI July NNth, 2005.
Java and C++, The Difference An introduction Unit - 00.
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
Internationalization and the Java Stack Part 1 Matt Wheeler.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
L10n and I18n in the Real World Dan Moore Moore Consulting June 9, 2005.
Internationalization and the Java Stack Matt Wheeler.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
 2003 Joel C. Adams. All Rights Reserved. Calvin CollegeDept of Computer Science(1/16) Internationalization and Locales Joel Adams and Jeremy Frens Calvin.
Java Server Pages A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format,
Internationalization in the Java Stack Matt Wheeler.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
OOP (Java): Simple/ OOP (Java) Objectives – –give some simple examples of Java applications and one applet 2. Simple Java Programs Semester.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
POS 406 Java Technology And Beginning Java Code
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Introduction to Java Programming with Forte Y. Daniel Liang.
Chapter 14 Internationalization F Processing Date and Time –Locale –Date –TimeZone –Calendar and GregorianCalendar –DateFormat and SimpleDateFormat F Formatting.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 26 Internationalization.
Chapter 12: Internationalization Processing Date and Time Processing Date and Time  Locale  Date  TimeZone  Calendar and GregorianCalendar  DateFormat.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Canvas and Graphics CS 21a. 9/26/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L17: Canvas.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Introduction to programming in the Java programming language.
Programming Fundamentals 2: Simple/ F II Objectives – –give some simple examples of Java applications and one applet 2. Simple Java.
1 CSE1340 Class 4. 2 Objectives Write a simple computer program in Java Use Swing components to build the GUI Use proper naming conventions for classes.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
Chapter 14 Internationalization F Processing Date and Time –Locale –Date –TimeZone –Calendar and GregorianCalendar –DateFormat and SimpleDateFormat F Formatting.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
RMI , Naming Service, Serialization and Internationalization Chapter 4
Java Programming, 2E Introductory Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
1 Chapter 20 Internationalization. 2 Objectives F To describe Java's internationalization features (§ 20.1). F To construct a locale with language, country,
Creating a Java Application and Applet
Packages. The main feature of OOP is its ability to support the reuse of code: –Extending the classes –Extending interfaces The features in basic form.
Chapter 6 - More About Problem Domain Classes1 Chapter 6 More About Problem Domain Classes.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Chapter 14 Internationalization
Internationalization
Chapter 35 Internationalization
F II 2. Simple Java Programs Objectives
How to Run a Java Program
Presentation transcript:

Internationalization Slide 1©SoftMoore Consulting

Internationalization Internationalization – the process of designing an application so that it can be adapted to various languages and regions without engineering changes. Often abbreviated “i18n”, because there are 18 letters between the first “i” and the last “n” Localization – the process of adapting software for a specific region or language by adding locale-specific components and translating text. Often abbreviated as “l10n” for similar reasons The primary task of localization is translating the user interface elements and documentation. (language, numbers, dates, currency, etc.) ©SoftMoore ConsultingSlide 2

Characteristics of an Internationalized Program With the addition of localized data, the same executable can run worldwide. Textual elements, such as status messages and the GUI component labels, are not hardcoded in the program. Instead they are stored outside the source code and retrieved dynamically. Support for new languages does not require recompilation. Culturally-dependent data, such as dates and currencies, appear in formats that conform to the end user's region and language. It can be localized quickly. Slide 3©SoftMoore Consulting

Example: Before Internationalization public class NotI18N { static public void main(String[] args) { System.out.println("Hello."); System.out.println("How are you?"); System.out.println("Goodbye."); } ©SoftMoore ConsultingSlide 4

Example: After Internationalization public class I18NSample { static public void main(String[] args) { String language = new String(args[0]); String country = new String(args[1]); Locale loc = new Locale(language, country); ResourceBundle messages = ResourceBundle.getBundle("MessagesBundle", loc); System.out.println(messages.getString("greeting")); System.out.println(messages.getString("inquiry")); System.out.println(messages.getString("farewell")); } ©SoftMoore ConsultingSlide 5

Running the Example java I18NSample fr FR Bonjour. Comment allez-vous? Au revoir. java I18NSample en US Hello. How are you? Goodbye. ©SoftMoore ConsultingSlide 6

Property Files for the Example File MessagesBundle_fr_FR.properties greeting = Bonjour. farewell = Au revoir. inquiry = Comment allez-vous? File MessagesBundle_en_US.properties greeting = Hello. farewell = Goodbye. inquiry = How are you? File names are significant! ©SoftMoore ConsultingSlide 7

Topics Locales Using resource bundles Date formatting Message formatting ©SoftMoore ConsultingSlide 8

Locale A locale defines local area configuration data –specific language –specific country –specific territory / variant (optional) Class Locale resides in the java.util package Several Java classes provide methods that return instances of Locale ©SoftMoore ConsultingSlide 9

Sample Language Codes Language CodeDescription deGerman enEnglish frFrench jaJapanese koKorean zhChinese ©SoftMoore ConsultingSlide 10

Sample Country Codes Country CodeDescription CNChina DEGermany FRFrance INIndia USUnited States ©SoftMoore ConsultingSlide 11

Getting the Locale Constructing a locale manually: Locale l = new Locale(String lang, String country); Locale l = new Locale(String lang, String country, String variant); Getting the default locale: Locale l = Locale.getDefault(); Setting locale-related properties (dangerous): Properties p = System.getProperties(); p.put("user.language", "fr"); p.put("user.region", "CA"); System.setProperties(p); ©SoftMoore ConsultingSlide 12

Method getLocale() Returns the current locale Defined for –Applet –Component –MessageFormat –Window If no locale is set, method getLocale() returns the default locale. ©SoftMoore ConsultingSlide 13

Available Locales To retrieve the available locales Locale locales[] = Locale.getAvailableLocales(); Method locale.toString() returns concatenated values –“_fr_FR” (French/France) –“_fr_CA” (French/Canada) –“_en_US” (English/United States) To retrieve locale properties as strings use locale.getLanguage() locale.getCountry() locale.getVariant() ©SoftMoore ConsultingSlide 14

Resource Bundles Isolate grouping for specific locales Class ListResourceBundle defines a bundle within the source code Class PropertyResourceBundle defines a bundle via a property file Access is identical – names for multiple locales: MyResourceBundle MyResourceBundle_en MyResourceBundle_fr_CA MyResourceBundle_fr_FR ©SoftMoore ConsultingSlide 15

Creating a Bundle as Compiled Code Simply extend class ListResourceBundle public class Training extends ListResourceBundle { static final Object[][] contents = { { "Date", "Date: " }, { "Cost", "Cost: " }, { "Location", "Location: " }, { "Title", "Training" } }; public Object[][] getContents() { return contents; } Array contents provides key-value pairs ©SoftMoore ConsultingSlide 16

Working with a Resource Bundle Getting a bundle Locale l = getLocale(); ResourceBundle labels = ResourceBundle.getBundle("Training", l); Using a bundle p.add(new Label(labels.getString("Date"))); p.add(new Label(labels.getString("Cost"))); p.add(new Label(labels.getString("Location"))); add(new Label(labels.getString("Title"), Label.CENTER), BorderLayout.NORTH); ©SoftMoore ConsultingSlide 17

Supporting a Different Locale Example: Define a Finnish bundle public class Training_fi extends ListResourceBundle { static final Object[][] contents = { { "Date", "Päivämäärä: " }, { "Cost", "Hinta: " }, { "Location", "Sijainti: " }, { "Title", "Koulutus" } }; public Object[][] getContents() {...} } Simply append "_fi" to base bundle name. ©SoftMoore ConsultingSlide 18

Class PropertyResourceBundle Initialized from property file key=value format File naming convention Bundlename_localization-string.properties –TrainingSettingsBundle.properties –TrainingSettingsBundle_fi.properties Example file contents Date=June 3, 1998 Cost= Map=SMarea.gif ©SoftMoore ConsultingSlide 19

Locale-Specific Formats Manipulating data for different locales –NumberFormat handles number formatting and manipulation –DateFormat handles reading and displaying of dates –MessageFormat supports error and informational messages Example: For “June 3, 1998” –US: 6/3/98 –Italy: 3/6/98 –Finland: See the java.text package for details ©SoftMoore ConsultingSlide 20

Example: Reading Date-Related Data Local aLocale = getLocale(); ResourceBundle settings = ResourceBundle.getBundle("Training", aLocale); String date = settings.getString("Date"); DateFormat dfInput = DateFormat.getDateInstance(DateFormat.LONG, Locale.US); Date inputDate; try { inputDate = dfInput.parse(dateString)); } catch (ParseException e) { inputDate = null; } ©SoftMoore ConsultingSlide 21

Example: Writing Date-Related Data Local aLocale = getLocale(); DateFormat dfOutput = DateFormat.getDateInstance(DateFormat.SHORT, aLocale); String dateLabelString; try { dateLabelString = dfOutput.format(dfInput.parse(dateString)); } catch (ParseException e) { dateLabelString = dateString; } ©SoftMoore ConsultingSlide 22

Class NumberFormat Deals with reading and display of numbers, currency, and percentage Supports numeric output in locale-appropriate format Example: For “ ” –US: $1, –Italy: L ,00 –Finland: 1 200,00 mk ©SoftMoore ConsultingSlide 23

Example: Manipulating Currency Values String costString = settings.getString("Cost"); NumberFormat nfInput = NumberFormat.getNumberInstance(Locale.US); NumberFormat nfOutput = NumberFormat.getCurrencyInstance(aLocale)); String costLabelString; try { Number n = nfInput.parse(costString); costLabelString = nfOutput.format(n.longValue()); } catch (ParseException e) { costLabelString = costString; } ©SoftMoore ConsultingSlide 24

Class MessageFormat Supports fill-in-the-blank (error) messages Example MessageFormat format1 = new MessageFormat ("File {1} overflowing filesystem {0}."); The {n} syntax designates string substitution area ©SoftMoore ConsultingSlide 25

Localized Messages Class MessageFormat also assists with localization of messages –can specify format of message with place holders for runtime context – can reorder placeholders based on locale Example output –I/O Exception while loading: Foobar.java –Foobar.java loaded unsuccessfully: I/O Exception or –The disk G contains 3 files. (English) –Il y a 3 fichiers sur le disque G. (French) ©SoftMoore ConsultingSlide 26

Using Class MessageFormat Define format styles: –"{0} while loading: {1}" –"{1} loaded unsuccessfully: {0}" Define contents –syntax {n} represents a placeholder –values start with 0 Place parameter values in an Object array Object[] args = {exceptionName, filename}; Use MessageFormat.format() to fill in placeholders ©SoftMoore ConsultingSlide 27

Example: Displaying Messages with MessageFormat public class FormatIt { public static void main(String args[]) { String fmt1 = "{0} while loading: {1}"; String fmt2 = "{1} loaded unsuccessfully: {0}"; String filename = "Foobar.java"; String exceptionName = "I/O Exception"; Object[] fmtargs = {exceptionName, filename}; System.out.println( MessageFormat.format(fmt1, fmtargs)); System.out.println( MessageFormat.format(fmt2, fmtargs)); } ©SoftMoore ConsultingSlide 28

Example: Displaying Messages with MessageFormat (continued) Output after substitutions –I/O Exception while loading: Foobar.java –Foobar.java loaded unsuccessfully: I/O Exception ©SoftMoore ConsultingSlide 29

Starting an Application For default locale, just run it For different locale –Set Properties from inside your program –Set Properties from command line java -Duser.language=it -Duser.region=IT ClassSchedule ©SoftMoore ConsultingSlide 30

International Training ©SoftMoore ConsultingSlide 31

Displaying Unicode Fonts If your fonts are installed correctly, it works Basic functionality only works for displaying text, not editing it Works for Label or Choice, for example, but not TextField ©SoftMoore ConsultingSlide 32

Example: Displaying Unicode Fonts public class MyDisplay extends Frame { public static class MyCanvas extends Canvas { public MyCanvas() { setFont (new Font ("Serif", Font.PLAIN, 36)); } public void paint (Graphics g) { String s = "\u3041\u3042\u3043\u3044\u3045"; g.drawString(s, 20, 50); } ©SoftMoore ConsultingSlide 33

Example: Displaying Unicode Fonts (continued) public MyDisplay() { super("Unicode Tester"); add(new MyCanvas(), BorderLayout.CENTER); Choice c = new Choice(); c.addItem ("\u3041\u3042\u3043\u3044\u3045"); c.addItem ("\u3041\u3042\u3043\u3044\u3046"); add (c, BorderLayout.SOUTH); } ©SoftMoore ConsultingSlide 34

Internationalization Checklist Identify culturally dependent data –messages– labels on GUI components –dates/times– numbers –currencies– etc Isolate translatable text in resource bundles Handle compound messages Format numbers, currencies, dates, times, etc. Use unicode character properties Compare strings properly (e.g., with a Collator object) Convert non-unicode text ©SoftMoore ConsultingSlide 35

Online Resources Java Tutorial Trail on Internationalization ISO (language codes) ISO (country codes) ©SoftMoore ConsultingSlide 36