Learn to Internationalize your Applications - Sun Tech Days 2009

  • 9,642 views
Uploaded on

Hands on Lab Session on How to internationalize your applications using java, JavaFX, AJAX, Portlets.

Hands on Lab Session on How to internationalize your applications using java, JavaFX, AJAX, Portlets.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
9,642
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
116
Comments
0
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Learn to Internationalize your Java, JavaFX, AJAX and Portlet Applications Shankar Gowda & Shrinath Hedge Globalization Engineering Sun Microsystems, Inc.
  • 2. Agenda Globalization Overview > What's with acronyms and definitions ? > How do they differ and relate ? > Introducing Internationalization(i18n) in various technologies > Language Exercises (100 mins) > – Exercise 0: Setup Lab Environments – Exercise 1: Internationalize your Java application – Exercise 3: Internationalize AJAX Web application – Exercise 4: Internationalize Portlet application – Exercise 2: Internationalize JavaFX application > Tools, Summary and References 2
  • 3. Globalization acronyms Globalization [G1 1 n] “Globalization addresses the business issues associated with taking a product global. In the globalization of high-tech products this involves integrating localization throughout a company, after proper internationalization and product design, as well as marketing, sales, and support in the world market.” Internationalization [i1 8n] “Internationalization is the process of generalizing a product so that it can handle multiple languages and cultural conventions without the need for re-design. Internationalization takes place at the level of program design and document development.” Localization [L1 0n] “Localization involves taking a product and making it linguistically and culturally appropriate to the target locale ( country/ region and language) where it will be used and sold.” Translation ===> T9n 3
  • 4. How do they differ and relate ? • Globalization at the architecture level • Internationalization ( 8n)enables Localization i1 • An expert in i1 8n may not be an expert in l1 0n • I18n (code) + l10n(linguistic) + T9n (translation) = G11n (process) 4
  • 5. Internationalization support in Java Java Platform is Internationalized ➢ Extensive library of classes and functions ● I18n support comes for free or at very little cost ● Built-in I18n support for over 70 languages ● All text in a running Java program is Unicode ➢ 5
  • 6. Concept of Resource Bundle 6
  • 7. Example Code: Before Internationalization System.out.println(“Hello”); System.out.println(“Sun Tech Days”); System.out.println(“Hyderabad”); 7
  • 8. Example Code: After Internationalization Locale myLocale = new Locale(myLanguage, myCountry); ResourceBundle messages = ResourceBundle.getBundle(“messageBundle, myLocale); System.out.println(messages.getString(“greeting”)); System.out.println(messages.getString(“event”)); System.out.println(messages.getString(“place”)); Your Resource Bundle property catalog file will have, greeting=Hello event=Sun Tech Days place=Hyderabad 8
  • 9. Introduction to AJAX > AJAX = acronym for Asynchronous JavaScript and XML – Browser client uses JavaScript to Asynchronously – get XML data from a server and update page – dynamically without refreshing the whole page > Why is AJAX so popular ? – Increase Usability of Web Application – Save Bandwidth – Download only data you need – End user Sequence and Faster interfaces > Side effects of AJAX ? – Breaks back button support – URL's don't change as state changes – Cross Browser Issues can be a pain 9
  • 10. User Interface: Traditional Web Vs AJAX 10
  • 11. Traditional Web AJAX within a browser, there is AJAX engine 11
  • 12. AJAX Internationalization • Server Side: By setting the appropriate Request and Response Object to a right encoding in Servlet controller > In doGet method – request.setCharacterEncoding(“UTF-8”); > In sendResonse method – response.setContentType(“text/xml; charset=utf-8”); > Using Resource Bundle for externalizing messages to property files and naming them to appropriate locale variant. • Client Side: By setting your browser to UTF-8 encoding. 12
  • 13. Introducing Portlet Application > Specialized Web application that provides value-added services like, – Personalization, Single Sign-On, Content Aggregation, Dynamic Drag and Drop, Work From Desktop, Search& Tagging. > Portlet is a piece of markup called as 'Fragment' > A Portal Application can have multiple portlets. – Window functionalities like, minimize, maximize, configure, close..etc > Portal Administration for Role, Look & Feel, Permissions, SOA, JAI > Includes Wikis, Message Boards, Blogs, Email, IM, Activity Tracking, Calendar, etc.. 13
  • 14. Hindi Portal Application 14
  • 15. Internationalizing your Portlet > Server Side: By setting the appropriate Resquest and Response Objects to right encoding in Servlet/JSP controller. – Adding locale support in your portlet.xml <supported-locale>hi</supported-locale> – JSP Page Directive <%page contentType=”text/html; charset=UTF-8”%> <%page pageEncoding=”UTF-8” %> – Using JSTL FMT library <% taglib uri=”http://java.sun.com/jsp/jstl/fmt” prefix=”fmt” %> – Setting Resource Bundle <fmt.setBundle basename=”PackageName.BundleName” /> – Calling the tag lib in your JSP page <fmt:message key=”name”/> > Client Side: Set your browser encoding to UTF-8. 15
  • 16. Let us start the LAB with Exercise 0 > Install Java SE 6 update 10 or above > Install NetBeans 6.5 with GlassFish V2/V3 > Copy i18nHOL.zip and unzip – Will create i18nHOL directory = <lab_root> – It contains the following: – Start with index.html – Exercises directory like 16
  • 17. Excrcise 1: Learn to Internationalize your Java Application 17
  • 18. Exercise 3: Learn to Internationalize your AJAX enabled Web Application 18
  • 19. Exercise 4: Learn to Internationalize your Portlet Application 19
  • 20. Lastly, let us take to JavaFX Lab Session 20
  • 21. JavaFX Overview JavaFX platform FX ● JavaFX Desktop ● ● JavaFX Mobile and JavaFX TV ● Other devices and screens to follow Tools Suite ● JavaFX Developer (Plug-ins for IDEs, Media ● converters, RAD tools) ● JavaFX Designer (Authoring, Video Encoding) Suite of Applications build on JavaFX ● ● JavaFX Content, Applications & Services 21
  • 22. Single Virtual Machine/ byte code 22
  • 23. JavaFX Script Programming Language Declarative, statically-typed scripting language > Facilitates rapid GUI development > Many cool, interesting language features > Runs on Virtual Machine for the Java™ platform > Deployment options same as Java programs > Fully utilizes Java class libraries behind the scenes > For content designers and Media engineers > Supports primitive types like, String, Boolean, Number, > Integer, Duration. > Supports Objects, Multiple Inheritance and any Java Objects can be used in JavaFX. 23
  • 24. Comparision of Java, Swing and JavaFX 24
  • 25. Introducing Internationalization in JavaFX > Creating a Locale Object > Setting the default locale > Create Resource Bundle property file as “Main_hi_IN.fxproperties” > Resource bundle messages are called just by prefixing with '##' > Reduces complexity! Compared to Java Resource Bundle 25
  • 26. Internationalizing Dates in JavaFX > Supports Java printf-style formats > Uses same Formatter as Java > POSIX standard strftime spec. 26
  • 27. Internationalizing of Dates in JavaFX • Formats – %tx – Locale's appropriate date representation – %tX – Locale's appropriate time representation – %tg – The last two digits of the week-based year (ISO 8601) – %tG – Week-based year (ISO 8601) – %tu – Day of week ( Monday is 1) [ 1,7 ] – %tV – ISO 8601 Week number of the Year. 27
  • 28. Looking at locale based sorting for JavaFX > Create a List of words > Create the Instance of Collator by specifying the Locale. > Define the function for Sorting and displaying the List of words. 28
  • 29. Locale based Sorting using Collator > In sort function we will call Collections.sort, that sorts the list of words in ascending order by giving the words list and strength of the collator as arguments. > Append the output to a variable. > Display as, 29
  • 30. Exercise 2: Learn to i18n JavaFXSphere • Install, Configure Lab environment • Creating a FirstJavaFXSphere Application • Internationalizing the code of FirstJavaFXSphere application • Externalizing the messages to Main_hi_IN.fxproperties • Localizing in Hindi 30
  • 31. Internationalization References Sun Software Globalization • – http://developers.sun.com/techtopics/global/ Software Globalization - Architecture, Design,Testing • – http://developers.sun.com/techtopics/global/technology/arch/ Software Globaliation- Sun Java Enterprise System • – http://developers.sun.com/techtopics/global/products_platforms/jes/ Sun Software Product Internationalization Taxonomy • – http://developers.sun.com/dev/gadc/des_dev/i18ntaxonomy Java Internationalization • – http://java.sun.com/javase/technologies/core/basic/intl/ Subscribe to Software globalization NewsLetter • – http://developers.sun.com/dev/gadc/subscribe/index.html Technical articles on Java Internationalization • – http://java.sun.com/developer/technicalArticles/Intl/ Java Internationalization Tutorial • – http://java.sun.com/docs/books/tutorial/i18n/index.html 31
  • 32. JavaFX References http://javafx.com/ • https://openjfx.dev.java.net/ • http://openjfx-compiler.dev.java.net • http://scenegraph.dev.java.net • http://java.sun.com/javafx/ • http://java.sun.com/javafx/tutorials/project_nile_integrating_graphics/ • http://openjfx.java.sun.com/current-build/doc/index.html • 32
  • 33. AJAX References The BluePrints Solutions catalog on AJAX • – https://bpcatalog.dev.java.net/nonav/solutions.html AJAX Q & A • – https://blueprints.dev.java.net/ajax-faq.html Asynchronous JavaScript Technology and XML (AJAX) with Java 2 Platform, • Enterprise Edition – http://java.sun.com/developer/technicalArticles/J2EE/AJAX/Intro_Ajax _PageAuthors.pdf AJAX Frameworks • – http://ajaxpatterns.org/wiki/index.php?title=AJAXFrameworks AJAX Library and Frameworks Comparison • – http://wiki.osafoundation.org/bin/view/Projects/AjaxLibraries AJAX Developer Resource Center • – http://developers.sun.com/ajax/ JavaScript Developer Site • – http://java.sun.com/javascript 33
  • 34. Portlet References http://javafx.com/ • https://openjfx.dev.java.net/ • http://openjfx-compiler.dev.java.net • http://scenegraph.dev.java.net • http://java.sun.com/javafx/ • http://java.sun.com/javafx/tutorials/project_nile_integrating_graphics/ • http://openjfx.java.sun.com/current-build/doc/index.html • 34
  • 35. Q&A 35
  • 36. Shankar Gowda MBN ● ● Shrinath Hedge ● 36
  • 37. Backup of JavaFX 37
  • 38. JavaFX: Command Line Development include <javafx-sdk>/bin in PATH • javafxc to compile • javafx to run • Relevant library files in <javafx-sdk>/lib are • automatically included in classpath as necessary. Rest can be included with the -classpath option > With packages ● javafxc -d . firstjavafxsphere/Main.fx ● javafx firstjavafxsphere.Main > Without packages ● javafxc Main.fx ● javafx Main 38
  • 39. JavaFX: FirstJavaFXSphere.jnlp (applet) <jnlp href=quot;test.jnlpquot;> <information>... </information> <resources> <j2se version=quot;1.6+quot; href= quot;http://java.sun.com/products/autodl/j2sequot; /> <jar href=quot;FirstJavaFXSphereApplet.jarquot; main=quot;truequot; /> <jar href=quot;javafxrt.jarquot; /> <jar href=quot;javafxgui.jarquot; /> <jar href=quot;javafx-swing.jarquot; /> <jar href=quot;Scenario.jarquot; /> </resources> <applet-desc name=test main-class=quot;javafx.application.Appletquot; width=500 height=500> </applet-desc> </jnlp> 39
  • 40. JavaFX: FirstJavaFXSphere.html (Applet call) <html> <head> <title>FX Script Applet Test</title> </head> <body bgcolor=quot;#000000quot;> <h1>FX Script Applet Test</h1> <center> <applet width=quot;640quot; height=quot;480quot;> <param name=quot;jnlp_hrefquot; value=quot;FirstJavaFXSphere.jnlpquot;> <param name=quot;ApplicationClassquot; value=quot;FirstJavaFXSphereAppletquot;> </applet> </center> </body> </html> 40