Hi,

Here the source code with 5 example of resources (2 languages as example)
and 1 example of implementation:

Interface:

package
{
    public interface ILanguage
    {
        [Bindable] function get LoginSignIn():String;
        [Bindable] function get LoginLockScreen():String;
        [Bindable] function get LoginCallToActionToUnlock():String;
        [Bindable] function get LoginUnlock():String;
        [Bindable] function get LoginNotYou():String;
    }
}

Portuguese language:

package
{
    public class Portuguese implements ILanguage
    {
        public function get LoginSignIn():String { return "Faça Login aqui"
};
        public function get LoginLockScreen():String { return "Sessão
bloqueada" };
        public function get LoginCallToActionToUnlock():String { return
"Insira a sua password para desbloquear o ecrã!" };
        public function get LoginUnlock():String { return "Desbloquear" };
        public function get LoginNotYou():String { return "Não é voçê ?" };

    }
}

English language:

package
{
    public class English implements ILanguage
    {
        public function get LoginRecoverPasswordResult():String { return
"Password recovery requested. Check your e-mail box." };
        public function get LoginRemeberIt():String { return "Remember It
?" };
        public function get LoginSignIn():String { return "Sign In here" };
        public function get LoginLockScreen():String { return "Lock screen"
};
        public function get LoginCallToActionToUnlock():String { return
"Enter your password to unlock the screen!" };
        public function get LoginUnlock():String { return "Unlock" };
        public function get LoginNotYou():String { return "Not you ?" };
   }
}

Manager:

package
{
import org.apache.royale.events.EventDispatcher;
import goog.events.Event;
import org.apache.royale.collections.ArrayList;
import pt.solidsoft.framework.datamanager.local.LocalData;

public class LocaleManager extends EventDispatcher
{
public static const LANGUAGE_PORTUGUESE:String = "LanguagePortuguese";
public static const LANGUAGE_ENGLISH:String = "LanguageEnglish";

private var languagePortuguese:ILanguage = null;
private var languageEnglish:ILanguage = null;

private var selectedLanguage:String = null;

public var languages:ArrayList = null;

private static var localeManager:LocaleManager = null;
public static function getInstance():LocaleManager
{
if (localeManager == null)
{
localeManager = new LocaleManager();
localeManager.languagePortuguese = new Portuguese();
localeManager.languageEnglish = new English();
localeManager.setLanguage(LocalData.getString("Language",
LANGUAGE_PORTUGUESE));
}
return localeManager;
}

public function getLanguageCode():String
{
switch (selectedLanguage)
{
case LANGUAGE_PORTUGUESE:
return "pt";
break;
default:
return "en";
break;
}
}

public function getLanguage():String
{
return selectedLanguage;
}

public function setLanguage(language:String):void
{
selectedLanguage = language;
LocalData.setData("Language", language);
dispatchEvent(new Event("change"));
}

[Bindable("change")]
public function get localeStrings():ILanguage
{
switch (selectedLanguage)
{
case LANGUAGE_PORTUGUESE:
return languagePortuguese;
break;
default:
return languageEnglish;
break;
}
}
}
}

Example use case:

<fx:Script>
<![CDATA[
[Bindable]
private var localeManager:LocaleManager = LocaleManager.getInstance();
]]>
</fx:Script>

<j:Label text="{localeManager.localeStrings.LoginSignIn}"/>

Hugo Ferreira <hferreira...@gmail.com> escreveu no dia sexta, 29/04/2022
à(s) 14:10:

> Sure.
>
> Later I will commit an example of my implementation and let you know.
>
> Also, I have a macOS script that I intend to convert in a Windows/macOS
> form utility to facilitate the creation of the resources and I also can
> share that when the time comes.
>
> Maria Jose Esteve <mjest...@iest.com> escreveu no dia sexta, 29/04/2022
> à(s) 13:48:
>
>> Perhaps we could enrich the Cristallium example with Hugo's
>> implementation which is definitely interesting.
>> Hugo, were you planning to share it completely?
>>
>> Hiedra
>>
>> -----Mensaje original-----
>> De: Andrew Wetmore <cottag...@gmail.com>
>> Enviado el: viernes, 29 de abril de 2022 13:08
>> Para: Apache Royale Development <dev@royale.apache.org>
>> Asunto: Re: Opinion about adding example project for locales use
>>
>> Yeah, the key thing for my apps is to be able to switch languages while
>> working with the app, and having all the text fields display properly.
>>
>> On Fri, Apr 29, 2022 at 7:44 AM Hugo Ferreira <hferreira...@gmail.com>
>> wrote:
>>
>> > I'm also rewriting a Flex app to Royale and there are things that I
>> > just decided to forget the Flex way and embrace a Royale way.
>> >
>> > For localization (you may find a thread about it) I have an interface
>> > with all localization keys, several "as" files (each one for a
>> > specific
>> > language) that implements the interface and for last a LocaleManager
>> > that manages everything.
>> >
>> > Than I can use something like this:
>> > <TextInput text="{localeManager.localStrings.ClientName}"/>
>> >
>> > Also this way the language can be switched at runtime without
>> > application reboot or refresh.
>> >
>> > Soon I will write an operating system utility to insert/update text in
>> > the several languages and automatically update the several files in
>> > the project.
>> >
>> >
>> >
>> >
>> > Maria Jose Esteve <mjest...@iest.com> escreveu no dia sexta,
>> > 29/04/2022
>> > à(s) 11:34:
>> >
>> > > I found it useful, I would add it. Let's let other members give
>> > > their opinion...
>> > > I can't tell you for sure but I think there have been several
>> > > discussions on this topic (locale/resourceManager) on the list
>> > > (Carlos, Alex,
>> > Josh,...)
>> > >
>> > > Hiedra
>> > >
>> > > -----Mensaje original-----
>> > > De: cont...@cristallium.com <cont...@cristallium.com> Enviado el:
>> > > viernes, 29 de abril de 2022 12:01
>> > > Para: dev@royale.apache.org
>> > > Asunto: Opinion about adding example project for locales use
>> > >
>> > > Hi,
>> > >
>> > > I had some difficulty using a Flex-like system for display text
>> > > translation with Royale.
>> > > So I made this working example which might be useful for peoples
>> > > trying this.
>> > > Could it be added  in the examples ?
>> > >
>> > > What do you think ?
>> > >
>> > > https://github.com/apache/royale-asjs/pull/1191
>> > >
>> > > Could you give me feedback ? (because I'm not sure to use the right
>> > coding
>> > > way)
>> > >
>> > > Thanks
>> > >
>> > > Regards
>> > >
>> >
>>
>>
>> --
>> Andrew Wetmore
>>
>> Editor, Moose House Publications <https://moosehousepress.com/>
>> Editor-Writer, The Apache Software Foundation <https://apache.org/>
>>
>

Reply via email to