Разделы презентаций


Lesson 14 Localization

ObjectivesAfter completing this lesson, you should be able to:Describe the advantages of localizing an applicationDefine what a locale representsRead and set the locale by using the Locale objectBuild a resource bundle

Слайды и текст этой презентации

Слайд 1Lesson 14 Localization

Lesson 14 Localization

Слайд 2Objectives
After completing this lesson, you should be able to:
Describe the

advantages of localizing an application
Define what a locale represents
Read and

set the locale by using the Locale object
Build a resource bundle for each locale
Call a resource bundle from an application
Change the locale for a resource bundle
Format text for localization by using NumberFormat and DateFormat
ObjectivesAfter completing this lesson, you should be able to:Describe the advantages of localizing an applicationDefine what a

Слайд 3Why Localize?
The decision to create a version of an application

for international use often happens at the start of a

development project.
Region- and language-aware software
Dates, numbers, and currencies formatted for specific countries
Ability to plug in country-specific data without changing code
Why Localize?The decision to create a version of an application for international use often happens at the

Слайд 4A Sample Application
Localize a sample application:
Text-based user interface
Localize menus
Display currency

and date localizations

=== Localization App ===
1. Set to English
2. Set

to French
3. Set to Chinese
4. Set to Russian
5. Show me the date
6. Show me the money!
q. Enter q to quit
Enter a command:
A Sample ApplicationLocalize a sample application:Text-based user interfaceLocalize menusDisplay currency and date localizations=== Localization App ===1. Set

Слайд 5Locale
A Locale specifies a particular language and country:
Language
An alpha-2

or alpha-3 ISO 639 code
“en” for English, “es” for Spanish
Always

uses lowercase
Country
Uses the ISO 3166 alpha-2 country code or UN M.49 numeric area code
"US" for United States, "ES" for Spain
Always uses uppercase
See The Java Tutorials for details of all standards used

LocaleA Locale specifies a particular language and country:Language An alpha-2 or alpha-3 ISO 639 code“en” for English,

Слайд 6Resource Bundle
The ResourceBundle class isolates locale-specific data:
Returns key/value pairs stored

separately
Can be a class or a .properties file
Steps to

use:
Create bundle files for each locale.
Call a specific locale from your application.

Resource BundleThe ResourceBundle class isolates locale-specific data:Returns key/value pairs stored separately Can be a class or a

Слайд 7Resource Bundle File
Properties file contains a set of key/value pairs.
Each

key identifies a specific application component.
Special file names use language

and country codes.
Default for sample application:
Menu converted into resource bundle

MessageBundle.properties
menu1 = Set to English
menu2 = Set to French
menu3 = Set to Chinese
menu4 = Set to Russian
menu5 = Show the Date
menu6 = Show me the money!
menuq = Enter q to quit
Resource Bundle FileProperties file contains a set of key/value pairs.Each key identifies a specific application component.Special file

Слайд 8Sample Resource Bundle Files
Samples for French and Chinese

MessagesBundle_fr_FR.properties
menu1 = Régler

à l'anglais
menu2 = Régler au français
menu3 = Réglez chinoise
menu4 =

Définir pour la Russie
menu5 = Afficher la date
menu6 = Montrez-moi l'argent!
menuq = Saisissez q pour quitter


MessagesBundle_zh_CN.properties
menu1 = 设置为英语
menu2 = 设置为法语
menu3 = 设置为中文
menu4 = 设置到俄罗斯
menu5 = 显示日期
menu6 = 显示我的钱!
menuq = 输入q退出
Sample Resource Bundle FilesSamples for French and ChineseMessagesBundle_fr_FR.propertiesmenu1 = Régler à l'anglaismenu2 = Régler au françaismenu3 =

Слайд 9Quiz
Which bundle file represents a language of Spanish and a

country code of US?
MessagesBundle_ES_US.properties
MessagesBundle_es_es.properties
MessagesBundle_es_US.properties
MessagesBundle_ES_us.properties

QuizWhich bundle file represents a language of Spanish and a country code of US?MessagesBundle_ES_US.propertiesMessagesBundle_es_es.propertiesMessagesBundle_es_US.propertiesMessagesBundle_ES_us.properties

Слайд 10Initializing the Sample Application
PrintWriter pw = new PrintWriter(System.out, true);

// More init code here

Locale usLocale

= Locale.US;
Locale frLocale = Locale.FRANCE;
Locale zhLocale = new Locale("zh", "CN");
Locale ruLocale = new Locale("ru", "RU");
Locale currentLocale = Locale.getDefault();

ResourceBundle messages = ResourceBundle.getBundle("MessagesBundle", currentLocale);

// more init code here

public static void main(String[] args){
SampleApp ui = new SampleApp();
ui.run();
}

Initializing the Sample ApplicationPrintWriter pw = new PrintWriter(System.out, true);  // More init code here

Слайд 11Sample Application: Main Loop
public void run(){

String line = "";
while (!(line.equals("q"))){

this.printMenu();
try { line = this.br.readLine(); }
catch (Exception e){ e.printStackTrace(); }

switch (line){
case "1": setEnglish(); break;
case "2": setFrench(); break;
case "3": setChinese(); break;
case "4": setRussian(); break;
case "5": showDate(); break;
case "6": showMoney(); break;
}
}
}
Sample Application: Main Loop  public void run(){    String line =

Слайд 12The printMenu Method
Instead of text, resource bundle is used.
messages is

a resource bundle.
A key is used to retrieve each menu

item.
Language is selected based on the Locale setting.

public void printMenu(){
pw.println("=== Localization App ===");
pw.println("1. " + messages.getString("menu1"));
pw.println("2. " + messages.getString("menu2"));
pw.println("3. " + messages.getString("menu3"));
pw.println("4. " + messages.getString("menu4"));
pw.println("5. " + messages.getString("menu5"));
pw.println("6. " + messages.getString("menu6"));
pw.println("q. " + messages.getString("menuq"));
System.out.print(messages.getString("menucommand")+" ");
}
The printMenu MethodInstead of text, resource bundle is used.messages is a resource bundle.A key is used to

Слайд 13Changing the Locale
To change the Locale:
Set currentLocale to the desired

language.
Reload the bundle by using the current locale.

public void setFrench(){

currentLocale = frLocale;
messages = ResourceBundle.getBundle("MessagesBundle", currentLocale);
}
Changing the LocaleTo change the Locale:Set currentLocale to the desired language.Reload the bundle by using the current

Слайд 14Sample Interface with French
After the French option is selected, the

updated user interface looks like the following:

=== Localization App ===
1.

Régler à l'anglais
2. Régler au français
3. Réglez chinoise
4. Définir pour la Russie
5. Afficher la date
6. Montrez-moi l'argent!
q. Saisissez q pour quitter
Entrez une commande:
Sample Interface with FrenchAfter the French option is selected, the updated user interface looks like the following:===

Слайд 15Format Date and Currency
Numbers can be localized and displayed in

their local format.
Special format classes include:
DateFormat
NumberFormat
Create objects using Locale.

Format Date and CurrencyNumbers can be localized and displayed in their local format.Special format classes include:DateFormatNumberFormatCreate objects

Слайд 16Initialize Date and Currency
The application can show a local formatted

date and currency. The variables are initialized as follows:


// More init code precedes
NumberFormat currency;
Double money = new Double(1000000.00);

Date today = new Date();
DateFormat df;
Initialize Date and CurrencyThe application can show a local formatted date and currency. The variables are initialized

Слайд 17Displaying a Date
Format a date:
Get a DateFormat object based on

the Locale.
Call the format method passing the date to

format.

public void showDate(){

df = DateFormat.getDateInstance(DateFormat.DEFAULT, currentLocale);
pw.println(df.format(today) + " " + currentLocale.toString());
}

Sample dates:

20 juil. 2011 fr_FR
20.07.2011 ru_RU
Displaying a DateFormat a date:Get a DateFormat object based on the Locale. 	Call the format method passing

Слайд 18Customizing a Date
DateFormat constants include:
SHORT: Is completely numeric, such as

12.13.52 or 3:30pm
MEDIUM: Is longer, such as Jan 12, 1952
LONG:

Is longer, such as January 12, 1952 or 3:30:32pm
FULL: Is completely specified, such as Tuesday, April 12, 1952 AD or 3:30:42pm PST
SimpleDateFormat:
A subclass of a DateFormat class

Customizing a DateDateFormat constants include:SHORT: Is completely numeric, such as 12.13.52 or 3:30pmMEDIUM: Is longer, such as

Слайд 19Displaying Currency
Format currency:
Get a currency instance from NumberFormat.
Pass the Double

to the format method.

public void showMoney(){
currency =

NumberFormat.getCurrencyInstance(currentLocale);
pw.println(currency.format(money) + " " + currentLocale.toString());
}

Sample currency output:
1 000 000 руб. ru_RU
1 000 000,00 € fr_FR
¥1,000,000.00 zh_CN
Displaying CurrencyFormat currency:Get a currency instance from NumberFormat.Pass the Double to the format method. public void showMoney(){

Слайд 20Quiz
Which date format constant provides the most detailed information?
LONG
FULL
MAX
COMPLETE

QuizWhich date format constant provides the most detailed information?LONGFULLMAXCOMPLETE

Слайд 21Summary
In this lesson, you should have learned how to:
Describe the

advantages of localizing an application
Define what a locale represents
Read and

set the locale by using the Locale object
Build a resource bundle for each locale
Call a resource bundle from an application
Change the locale for a resource bundle
Format text for localization by using NumberFormat and DateFormat
SummaryIn this lesson, you should have learned how to:Describe the advantages of localizing an applicationDefine what a

Обратная связь

Если не удалось найти и скачать доклад-презентацию, Вы можете заказать его на нашем сайте. Мы постараемся найти нужный Вам материал и отправим по электронной почте. Не стесняйтесь обращаться к нам, если у вас возникли вопросы или пожелания:

Email: Нажмите что бы посмотреть 

Что такое TheSlide.ru?

Это сайт презентации, докладов, проектов в PowerPoint. Здесь удобно  хранить и делиться своими презентациями с другими пользователями.


Для правообладателей

Яндекс.Метрика