The UcompOS Rich Productivity Framework is designed to make it easy to serve localized Rich Portal Application implementations.
In this tutorial, we are going to explore the localization capabilities of the UcompOS RPF and look at some strategies for leveraging these capabilities.
I have created a Video that I encourage you to view that shows the implementation we are going to build in this tutorial in action, and you should also Download the source code that we build in this application so you can better follow along with it.
As is the case with most of our UcompOS tutorials, we are going to focus much less on aesthetics and presentation and more on the highlighting of core UcompOS fundamentals and mechanics.
In addition to highlighting the localization capabilities of the UcompOS RPF, we are also going to touch on a number of other useful and important topics including some advanced capabilities of UcompOS Application Manifest files as well as working with the UcompOSStyleProxy class which manages the aesthetic presentation of the UcompOS Portal.
In addition, we are going to learn more about the UcompOS Menu Bar, and also about the concept of declaring default UcompOS Background Applications.
Our Target Implementation
The implementation we want to build will involve a UcompOS application that opens some simple content in a UcompOS Window. The content will internally be configured to display some simple text that can be automatically translated on the fly to another language using Yahoo’s BabelFish free translation API.
We will set up the application such that the user can switch the operating language using a “language chooser” we’ll build into the UcompOS Menu Bar.
We will also create graphical artifacts that provide a customized experience to the end user when they switch between languages.
The languages we’ll allow users to choose from will be:
Two UcompOS Applications Involved
Our implementation will involve the construction of two UcompOS Applications. One we will consider the Controller for our implementation, and another we will consider the View.
We are going to put all assets and code related to our implementation in a single folder named Multilingual. Inside the Multilingual folder are controller and view subfolders with the pertinent assets and code in each folder.
Let’s talk a little bit more about exactly how we want our implementation to behave.
We want to place a language chooser on the UcompOS Menu Bar that lets the user switch between languages.
We want this Menu Bar to be perpetually on the UcompOS Menu Bar even when our View application is in focus.
Our Dock Manifest
Let’s take a look at our Dock Manifest and discuss some of its more important aspects:
<applications> <application background="true" default="true"> http://desktop.ucompass.com/Multilingual/controller/manifest.xml </application> <application> http://desktop.ucompass.com/Multilingual/view/manifest.xml </application> </applications>
Obviously, the first UcompOS Application listed in our Dock Manifest is our Controller application and the second is our View application.
A very important point to discuss are the two attributes set for our Controller application, specifically background=”true” and default=”true”.
When you declare a UcompOS Application as a background application, that means it is to be launched immediately upon authentication to the UcompOS Portal and it is to not be presented on the UcompOS Application Dock.
The code is simply loaded in the UcompOS run-time immediately and remains available for interaction throughout the session.
Setting an application as the default has implications on the UcompOS Menu Bar – the Menu Bar of the application declared as the default application is the Menu Bar that shows when no application is in focus.
The best analogy to this is to consider the Finder application in Mac OS X. The Finder’s Menu Bar shows up in Mac OS X when no other application is open. Also, if you click the Mac OS X desktop on the wallpaper (not on an artifact from a running application), the Menu Bar of the Finder is what is displayed.
This is paralleled in the UcompOS RPF by designating an application with the default=”true” attribute in the Dock Manifest.
If no application is configured with the default=”true” attribute, then the base, default UcompOS Menu Bar is displayed when no application is in focus.
Also, if you try to configure a Dock Manifest with more than one application specified as the default, you’ll encounter a run-time error from the UcompOS Portal.
Also, in an individual application’s Application Manifest, you can instruct the UcompOS Portal to use the default Menu Bar. We’ll look at this shortly as this will be how we configure our View application.
The Controller Application Manifest
Let’s take a look at the Application Manifest for our Controller:
<application> <source> <base>http://desktop.ucompass.com/Multilingual/controller/Controller.html</base> </source> <menu> <menuitem label="Language"> <menuitem label="English" icon="http://desktop.ucompass.com/Multilingual/view/images/icons/en_US_menubar.png" data="en_US"/> <menuitem label="Spanish" icon="http://desktop.ucompass.com/Multilingual/view/images/icons/es_ES_menubar.png" data="es_ES"/> <menuitem label="German" icon="http://desktop.ucompass.com/Multilingual/view/images/icons/de_DE_menubar.png" data="de_DE"/> <menuitem label="French" icon="http://desktop.ucompass.com/Multilingual/view/images/icons/fr_FR_menubar.png" data="fr_FR"/> <menuitem label="Italian" icon="http://desktop.ucompass.com/Multilingual/view/images/icons/it_IT_menubar.png" data="it_IT"/> </menuitem> </menu> </application>
As you can see our Controller Application Manifest is very simple but its chief critical responsibility is to furnish a Menu Bar implementation for the UcompOS Portal.
Since our Controller Application is configured as the default application in our Dock Manifest, its Menu Bar will be what displays when no other application is in focus.
The XML structure for the Menu Bar is very simple and straightforward. Notice the icon property points to the network URL of an icon image to be displayed on the Menu Bar. Also, a data property must be present in a Menu Bar node for an event to be dispatched to the applications and sub-applications the Menu Bar is associated with when the user chooses a Menu Bar option on the UcompOS Portal.
Our Menu Bar configures a Language Chooser on the UcompOS Menu Bar and lets the end-user choose between one of five different languages.
The View Application Manifest
Now let’s take a look at the View application’s Application Manifest:
<application selfLoading="true" width="500" height="500" x="100" y="100"> <source> <base>http://desktop.ucompass.com/Multilingual/view/View.html</base> </source> <titles> <title locale="en_US">A Multilingual Application</title> <title locale="es_ES">Un uso multilingue</title> <title locale="de_DE">Eine mehrsprachige Anwendung</title> <title locale="fr_FR">Une application multilingue</title> <title locale="it_IT">Un'applicazione multilingue</title> </titles> <icons> <icon locale="en_US">http://desktop.ucompass.com/Multilingual/view/images/icons/en_US_dock.png</icon> <icon locale="es_ES">http://desktop.ucompass.com/Multilingual/view/images/icons/es_ES_dock.png</icon> <icon locale="de_DE">http://desktop.ucompass.com/Multilingual/view/images/icons/de_DE_dock.png</icon> <icon locale="fr_FR">http://desktop.ucompass.com/Multilingual/view/images/icons/fr_FR_dock.png</icon> <icon locale="it_IT">http://desktop.ucompass.com/Multilingual/view/images/icons/it_IT_dock.png</icon> </icons> <toolTips> <toolTip locale="en_US">See a UcompOS Application translate text into English</toolTip> <toolTip locale="es_ES">Vea un uso de UcompOS traducir el texto a inglés</toolTip> <toolTip locale="de_DE">Sehen Sie eine UcompOS Anwendung, Text ins Englische zu übersetzen</toolTip> <toolTip locale="fr_FR">Voir l'application d'UcompOS traduire le texte en anglais</toolTip> <toolTip locale="it_IT">Vedi un'applicazione di UcompOS tradurre il testo in inglese</toolTip> </toolTips> <menu default="true"/> </application>
The first thing to notice about the Application Manifest above is the strategy employed for localizing Application titles, icons, and tool tips.
The Application Title shows up on the UcompOS Application Dock for a particular application as well as any UcompOS Windows that are spawned by the application. The same applies to Application Icons.
Tool tips show up when the user mouses over an application icon on the UcompOS Application Dock and the mouse hovers for a second.
Notice how the locale attributes in this manifest match up to the data attributes for the menu bar model in our Controller manifest.
Another important thing to take note of is the <menu default=”true”/> element in the manifest.
This tells the UcompOS Portal that when this application is in focus, still use the UcompOS Portal’s default Menu Bar which will be the Menu Bar of our Controller Application.
Also, note the selfLoading=”true” attribute as well as the width, height, x, and y attributes in our manifest’s root <application/> element.
This tells the UcompOS Portal to launch the application into a UcompOS Window instance versus simply loading it into the UcompOS run-time.
Preparing the Graphics
The next task in building our implementation will be to prepare the graphic assets we’ll use.
In this implementation, I want our application icon to automatically update on the UcompOS Dock and UcompOS Window instances spawned by our application to reflect the most recently selected language. So I’ll need five different application dock icons – one for each language.
Then on the UcompOS Menu Bar, we will add a “language chooser” utility. I want each node in the language chooser, which will represent a different language, to have an icon representative of the given language. So I’ll need five different menu bar icons – one for each language.
Finally, each time a new language is selected, I want the background wallpaper for my UcompOS Portal implementation to display an image representative of the chosen language.
I have created a folder named images in my Multilingual project’s view folder and in the images folder I’ve created two more folders: icons and backgrounds. I am placing the dock and menu bar icons in the icons folder and the background images in the backgrounds folder.
The Controller Source Code
As you can see in our Controller‘s Application Manifest, it points to the following network URL as the location for the application’s source code:
Let’s take a look at this application’s source code below and discuss it:
Our start(); method employs a class we haven’t looked at yet in any of our tutorials, UcompOSMenuBarProxy, which manages and handles events dispatched by the Menu Bar on the UcompOS Portal.
In this case, we are added an event handler to handle CHANGE events.
In addition to the UcompOSMenuBarProxy, we are also working with the UcompOSGlobalManagerProxy and UcompOSStyleProxy classes in this application.
In this application, when we receive notification that the user has selected a new option on the Menu Bar, we access the newly selected language as the data property of the menuData Object passed to the event handler by the UcompOS SDK.
We then take that value and pass it to the changeLanguage(); method of the UcompOSGlobalManagerProxy. This method configures the operating language on the UcompOS Portal with the newly chosen language string. Whenever the UcompOS Portal’s operating language changes, a UcompOS Continuum Event is dispatched meaning that every running application and sub-application in the UcompOS Continuum is notified instantly. This detail will be important to us when we look at our View application.
We also call the setBackgroundImage(); of the UcompOSStyleProxy and pass it the URL of a background image that is representative of the newly selected language. This method sets the wallpaper image for the UcompOS Portal.
The View Source Code
As we saw in our View application’s Application Manifest, the source code of our View application is reachable at a network URL of:
In the View application, we are starting with a string of text embedded in an HTML DIV element that is in the English language.
In our start(); method, we are creating an instance of the UcompOSGlobalManagerProxy class and calling its getSessionInfo(); method. We are also attaching an event listener for events of type UcompOSGlobalManagerProxy.SESSION_INFO.
The getSessionInfo(); method the UcompOS Global Manager Proxy is extremely important. It returns an Object with a number of important properties including the unique user Id that the current user is authenticated into the UcompOS Portal with.
Also, it returns the current language the UcompOS Portal is operating in in a property called language.
The exact implementation details regarding doing the actual language translation are outside the scope of the UcompOS RPF but I’ll explain them briefly.
One other UcompOS-related detail in our implementation is we are creating a UcompOSWindowProxy instance and setting its self property to true.
This lets us access the methods and properties of the UcompOS Window that the application we are operating in has been loaded into.
Once the user changes to a new language, we are then calling the UcompOSWindowProxy‘s setTitle(); method to update the title on the UcompOS Window in real-time.
Let’s take a look at the full source code of our View application below:
Big Picture Conclusions
By isolating the language chooser into its own application, we are able to take advantage of the concept of UcompOS Continuum Events. In our implementation, when the user changes their operating language, the UcompOSGlobalManagerProxy‘s changeLanguage(); method is invoked, which causes a UcompOS Continuum Event to be dispatched.
Therefore, we could have an unlimited number of UcompOS applications or sub-applications running, all of which employed their own custom logic and behavior when encountering a single language change event that originated in our Controller application.
Below is a look at our implementation in operation:
- General Education (1)
- Flex (1)
- Proxy Components (27)
- AbstractProxyComponent (2)
- UcompOSAIRProxy (2)
- UcompOSAlertProxy (2)
- UcompOSArtifactContainerProxy (4)
- UcompOSArtifactProxy (9)
- UcompOSBrowserWindowProxy (2)
- UcompOSDialogueProxy (2)
- UcompOSDockProxy (2)
- UcompOSGlobalManagerProxy (8)
- UcompOSHTMLProxy (3)
- UcompOSKeyboardProxy (1)
- UcompOSMenuBarProxy (4)
- UcompOSStyleProxy (3)
- UcompOSWindowProxy (4)
- UcompOS Applications (11)
- UcompOS Architecture (12)
- UcompOS Portal (15)
- Application Dock (3)
- UcompOS Project Site (5)
- UcompOS SDK (15)
- Uncategorized (2)
- General Education (1)