Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Localization (i18n, internationalization) of components  (Read 6972 times)
bdziurdza
Newbie
*
Posts: 2


View Profile Email
« on: September 09, 2009, 07:43:49 »

Is this correct design to use instance of IResourceManager obtained from Resource.Manager.getIstance() directly inside component code?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: September 09, 2009, 07:57:01 »

You may certainly do that following Adobe's guidelines for use of the ResourceManger.

Personally, I don't like that approach, and would rather feed the label resources to the view component as a VO or XML object retrieved and passed to in via the mediator like any other data.

-=Cliff>
Logged
bdziurdza
Newbie
*
Posts: 2


View Profile Email
« Reply #2 on: September 09, 2009, 08:26:47 »

Cliff, from what I understood, you prefer to do this work (setting labels, loading icons) in mediator (so the component knows nothing about its resources - this is mediator duty).

What solution do you recommend for let say static (compiled-in) data, i.e. localization data? Static properties, or just xml string in .as file(s), or maybe a mix of ResourceManager with PureMVC Proxy?

BD
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: September 09, 2009, 12:26:31 »

No. Have the mediator deliver XML or a VO to the view component (not setting upteen properties) and have the view component internally bind it's labels to the properties of the VO or to the XML elements or attributes, the same way as you'd have the data bound into the controls. 

Take the mediators out of the picture for the moment and think about distributing a labels to controls. Consider the following working Flex app:
:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical" >


<mx:Script>
<![CDATA[
public var enUS:XML =
<labels locale="en_US">
<PanelTitle text="Blow up the universe?"/>
<PanelText>
The night sky over the planet Krikkit is the least
interesting sight in the Universe. But the people of
Krikkit are planning to do something about it -
destroy the rest of the Universe.
</PanelText>
<CancelButton text="Cancel"/>
<SubmitButton text="Submit"/>
</labels>;

public var frFR:XML =
<labels locale="en_US">
<PanelTitle text="Faites sauter l'univers?"/>
<PanelText>
Le ciel de nuit au-dessus de la planète Krikkit est
la moindre vue intéressante dans l'univers. Mais les
personnes de Krikkit prévoient de faire quelque chose
à son sujet - détruisez le reste de l'univers.
</PanelText>
<CancelButton text="Annulation"/>
<SubmitButton text="Soumettez"/>
</labels>;

[Bindable] public var labels:XML;
]]>
</mx:Script>

<mx:Panel id="pnlTest" title="{labels.PanelTitle.@text}"
horizontalAlign="center" verticalAlign="center"
width="50%" height="25%" layout="vertical">
<mx:HBox width="100%" horizontalAlign="right">
<mx:LinkButton click="labels=enUS" label="English"/>
<mx:LinkButton click="labels=frFR" label="Français"/>
</mx:HBox>

<mx:Text text="{labels.PanelText}"/>

<mx:ControlBar horizontalAlign="right">
<mx:Button id="btnCancel" label="{labels.CancelButton.@text}"/>
<mx:Button id="btnSubmit" label="{labels.SubmitButton.@text}"/>
</mx:ControlBar>

</mx:Panel>

</mx:Application>

This example uses XML and shows how easy it is to design the view component to get all it's resources from a single structure. This could also be a Value Object with bindable properties. Either way, you have one structure to deliver to the view component and binding will cause everything to update.

In the example, there are 2 XML structures enUS and frFR. There are buttons to change from one resource set to another by simply setting the labels property to one or the other of enUS or frFR. So what you can do is have the XML for the whole application in separate XML files by locale. The easiest way to make it the structure available to all your view components is to make it a top level property of the application and have your custom subcomponents have this property as well. Then you can deliver it to the app using the ApplicationMediator and have it trickle down the view hierarchy via binding.

-=Cliff>
« Last Edit: September 09, 2009, 12:36:40 by puremvc » Logged
Pages: [1]
Print