Slideshow transcript
Slide 1: w w w ...m a g h rre b s p a c e ...b llo g s p o tt...c o m w w w ...m a g h rre b s p a c e ...b llo g s p o tt...c o m w w w ...m a g h rre b s p a c e www maghrebspace blogspot com www maghrebspace blogspot com www maghrebspace www magh ebspace b ogspo com www magh ebspace b ogspo com www magh ebspace Internationalization in JAVA by Achraf SFAXI SUN Certified Professional Information Systems Architect Bank/Finance and Telecom Jobs Customers expect products to conform to their cultural preferences, especially when it comes to language and data formats. Creating a global application isn't particularly difficult, but it does require you to become familiar with the most common international problems and their solutions. Here, we give an overview of internationalization topics and concepts in a Java programming environment, and we consider the following features available in the Java Development Kit 1.1. • Locale • Resource bundles • Character sets • Layout managers Locales are used throughout the Java class libraries to customize how data is presented and formatted. They affect language choice, collation, calendar usage, date and time formats, number and currency formats, and many other culturally sensitive data representations. If you intend to create international Java applications, you'll definitely use the class. el a c o L.lit u. a v aj A is a relatively simple object. It identifies a specific language and a geographic el a c o L region. Effectively, the only significant contents of a Locale object are language and country. A Locale's language is specified by the ISO 639 standard, which describes valid language codes that can be used to construct a Locale object. The following figure lists a few language codes in the standard. The Locale's country identifier is also specified by an ISO standard, ISO 3166, which describes valid two-letter codes for all countries. ISO 3166 defines these codes in uppercase letters. ;elacoLym elacoL ;egaugnal gnirtS ;yrtnuoc gnirtS (elacoL wen = elacoLym ;)"SU" ,"ne" Pa ge 1 of 1 w w w ...m a g h rre b s p a c e ...b llo g s p o tt...c o m w w w ...m a g h rre b s p a c e ...b llo g s p o tt...c o m w w w ...m a g h rre b s p a c e www maghrebspace blogspot com www maghrebspace blogspot com www maghrebspace www magh ebspace b ogspo com www magh ebspace b ogspo com www magh ebspace
Slide 2: w w w ...m a g h rre b s p a c e ...b llo g s p o tt...c o m w w w ...m a g h rre b s p a c e ...b llo g s p o tt...c o m w w w ...m a g h rre b s p a c e www maghrebspace blogspot com www maghrebspace blogspot com www maghrebspace www magh ebspace b ogspo com www magh ebspace b ogspo com www magh ebspace ;)(egaugnaLteg.elacoLym = egaugnal ;)(yrtnuoCteg.elacoLym = yrtnuoc ;)egaugnal(nltnirp.tuo.metsyS ;)yrtnuoc(nltnirp.tuo.metsyS :TUPTUO ne SU ;)(tluafeDteg.elacoL = elacoLym elacoL (nltnirp.tuo.metsyS ;)(egaugnaLyalpsiDteg.elacoLym (nltnirp.tuo.metsyS ;)(yrtnuoCyalpsiDteg.elacoLym (nltnirp.tuo.metsyS ;))HCNERF.elacoL(egaugnaLyalpsiDteg.elacoLym (nltnirp.tuo.metsyS ;))HCNERF.elacoL(yrtnuoCyalpsiDteg.elacoLym :TUPTUO hsilgnE setatS detinU sialgna sinU-statÉ Numbers are represented differently around the globe. When an application shows a number to the user, it must represent that number in a way that is sensitive to the cultural expectations regarding decimal point symbol, group separators, number of digits after the decimal, and leading zeros. What number does 1.234 represent? Of course, the answer depends on locale. In France, this string of digits represents one thousand two hundred and thirty four. However, in the U.S this represents one and two hundred thirty four one-thousandths. Significant difference? The class performs locale-specific formatting for both general t a m r o F r e b m u N.t x et. a v aj purpose numbers. Each locale has its own preferences for currency symbols, negative amount format, leading zeros, group separators, decimal point symbol, and currency symbol position. Call to specify a specific locale. ) el a c ol el a c o L ( e c n at s nI y c n e r r u Ct e g A date helps to uniquely identify a point in time. Like other locale-sensitive structures, dates have many representation details. You must consider long and short date formats as well as date separator symbols. You have to worry about whether the year is displayed before the day and month or after. Again, the Java class libraries accommodate these needs. ( class) t a m r o F et a D.t x et. a v aj The r a d n el a C.t x et. a v aj class is closely related to Date, and lets you extract year, month, week, and day information from a . et a D The JDK uses Resource Bundles to isolate localizable elements from the rest of the application. The resource bundle contains either the resource itself or a reference to it. Pa ge 2 of 2 w w w ...m a g h rre b s p a c e ...b llo g s p o tt...c o m w w w ...m a g h rre b s p a c e ...b llo g s p o tt...c o m w w w ...m a g h rre b s p a c e www maghrebspace blogspot com www maghrebspace blogspot com www maghrebspace www magh ebspace b ogspo com www magh ebspace b ogspo com www magh ebspace
Slide 3: www magh ebspace b ogspo com www magh ebspace b ogspo com www magh ebspace www maghrebspace blogspot com www maghrebspace blogspot com www maghrebspace w w w ...m a g h rre b s p a c e ...b llo g s p o tt...c o m w w w ...m a g h rre b s p a c e ...b llo g s p o tt...c o m w w w ...m a g h rre b s p a c e Pa ge 3 of 3 characters by using Unicode to represent text. Unicode is a 16-bit character set, which The Java language has simplified the storage, manipulation, and representation of } ;} ,} ".}0{eht dniheb nam eht dragersid esaelP" ,"DRAGERSID_TXET" { ,} ".repap erom tresni esaelP" ,"REPAP_TRESNI_TXET" { ,} ".}1{elif eht ni sgninraw }0{ era erehT" ,"GNINRAW_TXET" { ,} "!dlrow ,olleH" ,"OLLEH_TXET" { ,} ".dnuof eb ton dluoc elif ehT" ,"DNUOF_TON_TXET" { { = st n et n o c ][][t c ej b O cit at s cil b u p } ; st n et n o c nr ut er { ) ( st n et n o Ct e g ][][t c ej b O cil b u p { el d n u B e c r u o s e Rt si L s d n et x e e c r u o s e R y M s s al c cil b u p ; el d n u B e c r u o s e Rt si L.lit u. a v aj t r o p mi a v aj. e c r u o s e R y M // el d n u B e c r u o s e Rt si L The following figure shows an example of .}0{ eht dniheb nam eht dragersid esaelP=DRAGERSID_TXET .repap erom tresni esaelP=REPAP_TRESNI_TXET . } 1 { elif e ht ni s g ni n r a w } 0 { e r a e r e h T = G NI N R A W _ T X E T !dlrow ,olleH=OLLEH_TXET .dnuof eb ton dluoc elif ehT=DNUOF_TON_TXET >eulav<=>yek< # s eit r e p o r p. e c r u o s e R y M # el d n u B e c r u o s e R yt r e p o r P The following figure shows an example of . el d n u B e c r u o s e Rt si L and el d n u B e c r u o s e R yt r e p o r P . The JDK provides two subclasses: el d n u B e c r u o s e R class is abstract, which means you must use a subclass of el d n u B e c r u o s e R.lit u. a v aj The www magh ebspace b ogspo com www magh ebspace b ogspo com www magh ebspace www maghrebspace blogspot com www maghrebspace blogspot com www maghrebspace w w w ...m a g h rre b s p a c e ...b llo g s p o tt...c o m w w w ...m a g h rre b s p a c e ...b llo g s p o tt...c o m w w w ...m a g h rre b s p a c e
Slide 4: w w w ...m a g h rre b s p a c e ...b llo g s p o tt...c o m w w w ...m a g h rre b s p a c e ...b llo g s p o tt...c o m w w w ...m a g h rre b s p a c e www maghrebspace blogspot com www maghrebspace blogspot com www maghrebspace www magh ebspace b ogspo com www magh ebspace b ogspo com www magh ebspace simply means that it can define 216 characters. Each character is uniquely identified within the set. if you have to maintain legacy data in a regional character set, you can use the numerous character converters that Java technology provides. Using the character converters, you can convert your Unicode text to a regional character set. You can also convert from a regional character set to Unicode. So, although the Java language uses Unicode, it also allows you to maintain your older data if necessary. Layout managers are important in an international application because they compensate for two frustrating problems associated with translated user interfaces: • Expanding and shrinking text lengths • Component positions First, translated text is often shorter or longer than the original text. Layout managers are important in an international application because they expand and shrink component size depending on the length of the text used for labels. Second, a layout manager relieves the frustration associated with trying to position components as a result of text length differences. If you usually lay out UI components on an X-Y grid, you have no doubt noticed that those positions must change after translations. However, using a layout manager, you position components relative to each other, not necessarily by hard-coded pixel positions. This means you can write your UI code once and run it anywhere. it's just as easy to access an application located at the other end of the globe, as it is to access an application in the same building. Due to these advancements, there is an increasing need to develop multilingual and multicultural applications. Developing multiple versions of the same application to cater to different locales is often cumbersome and might lead to maintenance nightmares. An easier option is to use internationalization by designing an application in such away that it adapts to the preferences of the country where it is used without any change in the source code. The term internationalization is often abbreviated as i18n because there are 18 letters between "i" and "n." Making an application adaptable to a country's local preferences is called localization, and the corresponding abbreviation is l10n. Java programming language has powerful APIs that support internationalization/localization. The APIs used for this purpose are Properties, Locale, ResourceBundle, Unicode, java.text package, InputStreamReader, and OutputStreamWriter. The Properties class is used for loading values from property files at startup or runtime. Only string objects can be stored in a property file as key-value pairs. The properties can be loaded from or saved to a stream. Generally, a property file contains data about the application characteristics or its environment. Encoding internationalized content in UTF-8 is recommended by Sun because it is compatible with the majority of existing Web content and provides access to the Unicode character set. The InputStreamReader class reads data from InputStream as bytes and converts them to characters, according to a specified character encoding. The OutputStreamWriter class converts the characters to bytes and sends them to OutputStream. JVM uses the 16-bit Unicode format, and many of the operating systems use 8-bit Unicode format. So, any data entering the JVM must be converted to 16-bit Unicode encoding format, and any data leaving the JVM must be converted to 8-bit Unicode encoding format. Pa ge 4 of 4 w w w ...m a g h rre b s p a c e ...b llo g s p o tt...c o m w w w ...m a g h rre b s p a c e ...b llo g s p o tt...c o m w w w ...m a g h rre b s p a c e www maghrebspace blogspot com www maghrebspace blogspot com www maghrebspace www magh ebspace b ogspo com www magh ebspace b ogspo com www magh ebspace
Slide 5: w w w ...m a g h rre b s p a c e ...b llo g s p o tt...c o m w w w ...m a g h rre b s p a c e ...b llo g s p o tt...c o m w w w ...m a g h rre b s p a c e www maghrebspace blogspot com www maghrebspace blogspot com www maghrebspace www magh ebspace b ogspo com www magh ebspace b ogspo com www magh ebspace • Properties: Loads values from property files at startup or runtime. • Locale: Identifies the specific locale for a particular session or user. • ResourceBundle: Holds the locale-specific object or properties. • Unicode encoding standard: Defines a standard and universal character set. • java.text package: Handles text, date, number, and messages. • InputStreamReader: Reads data from InputStream as bytes and converts them to characters, according to a specified character encoding. • OutputStreamWriter: Converts the characters to bytes and writes to OutputStream. If y ou ap p reciate this document make a donation to a worl dwide chil dren as s ociation or organiz ation. I sugges t the SOS as s ociation. This document has b een downl oaded f rom the maghrebspace.blogspot.com b l og ; y ou can us e and b roadcas t it f or non l ucrative p urp os es . Further inf ormation are avail ab l e up on reques t. Si vous ap p réciez ce document f aites un don p our l e comp te d’une as s ociation ou une organis ation qui s ’occup e des enf ants . Je recommande l ’as s ociation SOS. Ce document es t dis p onib l e s ur maghrebspace.blogspot.com ; s on util is ation ains i que s a p rop agation p our des f ins non l ucratives s ont gratuites . Pa ge 5 of 5 w w w ...m a g h rre b s p a c e ...b llo g s p o tt...c o m w w w ...m a g h rre b s p a c e ...b llo g s p o tt...c o m w w w ...m a g h rre b s p a c e www maghrebspace blogspot com www maghrebspace blogspot com www maghrebspace www magh ebspace b ogspo com www magh ebspace b ogspo com www magh ebspace



Add a comment on Slide 1
If you have a SlideShare account, login to comment; else you can comment as a guest- Favorites & Groups
Showing 1-50 of 0 (more)