Hi there,
I had a simple plan: I wanted to get two values of a single key from two different lexicons. Why? I wanted to build a switch which reads settings from the lexicon to get different reaction depending on the language.
I'll try to explain it a little more. Let's say, because it's easy, I wanted to know what "about_msg" (from core / about) would be in French and German.
Bob (Page 350 in HIS book) and the RTFM (
http://rtfm.modx.com/revolution/2.x/developing-in-modx/advanced-development/internationalization) say, that something like this can be done:
$modx->lexicon->load('es:school:playground');
$modx->lexicon('school.basketball');
They said, that "This would load the Spanish version of the 'playground' Topic for the 'school' Namespace. Fun, huh?". Actually, no, it is no fun. Lets see why.
For my example it would be this code (the "echo" is just for easier testing):
$modx->lexicon->load('fr:core:about');
echo $modx->lexicon('about_msg');
Yeah, one CAN do that (no error message) but it does NOT work as planned. ;-)
This thing here IS working:
$modx->lexicon->load('core:about');
echo $modx->lexicon('about_msg');
But I wanted to specify a language! They said I could! But the output I get is a result of the current cultureKey setting. Damn. ;-)
So, I set the culture key manually (Thank you, @WimHauben) which looked like this:
$modx->setOption('cultureKey', 'fr');
$modx->lexicon->load('core:about');
echo $modx->lexicon('about_msg');
OK, THAT worked well. Problem solved!?
But now I am asking myself why I can load a lexicon in a specific language. Why did Bob and RTFM say so? What am I missing?
And another question: is it OK so change the cultureKey in a snippet when I only want to get a certain value from a certain lexicon? Do I REALLY have to do it this way? Isn't there a less risky way? I mean, changing the cultureKey for a simple "gimme that setting" task seems a little bit, well, unconventional. Right?
Or can someone explain how they ment it and how I can change my code?