| View previous topic :: View next topic |
| Author |
Message |
trispo
Joined: 03 Jul 2008 Posts: 63 Location: Ettlingen, Germany
|
Posted: Sat Nov 29, 2008 12:04 pm Post subject: Parsley: Localization question |
|
|
Hey jens,
we use Parsley and Spicelib for our current project and we love it! The project will be available (most likely) in many languages and so it is nice to have your localization framework! But we encountered a problem during development:
We have many modules (with their own ApplicationContext) which we load at runtime when the user wants to use them. But as we discovered so far we have to load all localization xml files within the "main.xml" (the root context). Why can't every context have its own localization files loaded with its context? Or do we misunderstand something? If we try to load them in the module's context we get an error.
Thanks in advance!
trispo |
|
| Back to top |
|
 |
Jens Halm Site Admin
Joined: 21 Sep 2007 Posts: 1488 Location: Cologne Germany
|
Posted: Sat Nov 29, 2008 2:26 pm Post subject: |
|
|
Could you provide more details on how you split the configuration between modules and what type of error you are getting (message, stacktrace, etc.)? _________________ Jens Halm
Spicefactory |
|
| Back to top |
|
 |
ricobeck
Joined: 30 Nov 2008 Posts: 7 Location: karlsruhe, germany
|
Posted: Sun Nov 30, 2008 4:57 pm Post subject: |
|
|
hi jens!
i am in the same team as trispo - so don't be surprised why i provide an example.
http://ricobeck.de/dev/examples/parsley/PMessageBundle.zip
you can see that it only works if you access keys loaded in the first context.
changing
| Code: | | <property name="localizedSubTitle"><message bundle="subtitles" key="subtitles.subTitle" /></property> |
to
| Code: | | <property name="localizedSubTitle"><message bundle="subtitles" key="titles.subTitle" /></property> |
in inc/xml/config/sub_context.xml will let the example play.
is it impossible to load localized content later or did we do something wrong?
thanks for your help.
rico |
|
| Back to top |
|
 |
Jens Halm Site Admin
Joined: 21 Sep 2007 Posts: 1488 Location: Cologne Germany
|
Posted: Sun Nov 30, 2008 5:07 pm Post subject: |
|
|
From just skimming over the code it looks like it should work. One more question before I actually try to run the example: Are you using the latest version (1.0.2)? There were some bugs with messages in 1.0.1. _________________ Jens Halm
Spicefactory |
|
| Back to top |
|
 |
ricobeck
Joined: 30 Nov 2008 Posts: 7 Location: karlsruhe, germany
|
Posted: Sun Nov 30, 2008 5:19 pm Post subject: |
|
|
yes:
 |
|
| Back to top |
|
 |
Jens Halm Site Admin
Joined: 21 Sep 2007 Posts: 1488 Location: Cologne Germany
|
Posted: Sun Nov 30, 2008 5:25 pm Post subject: |
|
|
Ok, guess it's time for a little debugging session then...
I'll post again in a few minutes if I find something quickly or later this evening or tomorrow if it turns out to be difficult. _________________ Jens Halm
Spicefactory |
|
| Back to top |
|
 |
Jens Halm Site Admin
Joined: 21 Sep 2007 Posts: 1488 Location: Cologne Germany
|
Posted: Sun Nov 30, 2008 6:09 pm Post subject: |
|
|
Looks like a bug, unfortunately. Apparently the bundle in the sub-context does not get initialized after it was loaded. I created a ticket in Jira:
http://opensource.powerflasher.com/jira/browse/PSL-94
Will definitely be fixed soon, but I cannot promise an exact date, as I am currently swamped with work. Hope you can workaround the issue until then.
And thanks for spotting this and providing the example! _________________ Jens Halm
Spicefactory |
|
| Back to top |
|
 |
ricobeck
Joined: 30 Nov 2008 Posts: 7 Location: karlsruhe, germany
|
Posted: Sun Nov 30, 2008 6:30 pm Post subject: |
|
|
ok, thank you very much for confirming this as a bug.
the only way for working arround this is loading all
files in the root context.
would be nice to see this fixed in 1.0.3.  |
|
| Back to top |
|
 |
Jens Halm Site Admin
Joined: 21 Sep 2007 Posts: 1488 Location: Cologne Germany
|
Posted: Sun Nov 30, 2008 6:46 pm Post subject: |
|
|
Ha! There actually is an easy workaround!
All that is broken is the order of events: The COMPLETE event for the child ApplicationContext gets fired before the internal event that triggers the bundle initialization.
If you add a timer like this:
| Code: | private function handleSubContext(event : TaskEvent) : void
{
var t:Timer = new Timer(200, 1);
t.addEventListener(TimerEvent.TIMER, onTimer);
t.start();
}
private function onTimer (event:Event) : void {
var context : ApplicationContext =
ApplicationContext.forName('subContext');
var mySubContext : SubContextItem =
context.getObject('mySubContextItem') as SubContextItem;
log.trace(mySubContext.localizedSubTitle);
} |
It actually works. I guess you can live with that workaround until this gets fixed. _________________ Jens Halm
Spicefactory |
|
| Back to top |
|
 |
ricobeck
Joined: 30 Nov 2008 Posts: 7 Location: karlsruhe, germany
|
Posted: Sun Nov 30, 2008 7:12 pm Post subject: |
|
|
HA! implemented it in a real life project; i can say:
it works! thank you.  |
|
| Back to top |
|
 |
trispo
Joined: 03 Jul 2008 Posts: 63 Location: Ettlingen, Germany
|
Posted: Mon Dec 01, 2008 9:15 am Post subject: |
|
|
Hey Jens,
unfortunately your workaround doesn't work always. I'm not sure why, but sometimes the message for a specified key is not found and is displayed as ??key?? although the key exists in the xml file. In some cases some of the keys are found where others are not found. That is really strange.
trispo |
|
| Back to top |
|
 |
Jens Halm Site Admin
Joined: 21 Sep 2007 Posts: 1488 Location: Cologne Germany
|
Posted: Mon Dec 01, 2008 10:05 am Post subject: |
|
|
Can't say much about that without knowing more details, but it is very unlikely that this has to do with the issue discussed in this thread. _________________ Jens Halm
Spicefactory |
|
| Back to top |
|
 |
trispo
Joined: 03 Jul 2008 Posts: 63 Location: Ettlingen, Germany
|
Posted: Mon Dec 01, 2008 7:36 pm Post subject: |
|
|
mmmmh. the problem occurs only when trying to retrieve the message with: | Code: | | ApplicationContext.root.getMessage(myKey, "myBundle"); |
If I use parsley configuration with the <message />-tag everything works fine. But unfortunately I have to build the keys dynamically like:
| Code: | | myKey = "key"+currentPage; |
So there is a need for me to have option 1 work.
Thanks, trispo |
|
| Back to top |
|
 |
Jens Halm Site Admin
Joined: 21 Sep 2007 Posts: 1488 Location: Cologne Germany
|
Posted: Mon Dec 01, 2008 9:02 pm Post subject: |
|
|
Just a blind guess: Do you try to access messages in a sub-context from the root context? That will not (and cannot) work. The dependencies are one-way, meaning a child context can see messages/objects in a parent context, but not vice-versa. Similar mechanism like with ApplicationDomains. In that case you need to access the message through a reference to the child ApplicationContext.
Not sure if this is the case in your application, but without seeing a full example, I'm shooting in the dark.  _________________ Jens Halm
Spicefactory |
|
| Back to top |
|
 |
trispo
Joined: 03 Jul 2008 Posts: 63 Location: Ettlingen, Germany
|
Posted: Tue Dec 02, 2008 7:35 am Post subject: |
|
|
Oh my ....., damn. Of course you're right. So I didn't change the lines of code. They worked obviously because before the changings I did load the messages with the root context. But that was what I don't want any more
Thank you was your hint. I'm sure this was the problem.
trispo |
|
| Back to top |
|
 |
|