Quote from: splittingred at Aug 26, 2009, 11:34 PM
Quote from: BobRay at Aug 26, 2009, 02:16 AM
Second, am I correct in saying that if I wanted to show both English and French language strings on the same page, (say, for a Canadian site), I’d have to load both languages manually into the database with "Import Lexicon" and then, either have no duplicate keys between the two, or switch back and forth using lexicon->load() for each string?
Ugh, you’ve exposed the main problem of the Lexicon structure to date. The answer is that you’d have to switch, and let me explain why:
I kind of thought so, but since I’m so often wrong, I hesitated to say it.
It’s pretty easy to imagine that for a form done with SPForm or eForm on a site in Canada, Spain, Ireland, and a bunch of other places, you’d want to have every form field’s caption in two languages (English/French, Spanish/Catalonian, Irish/English).
1) There’s no separate array for each language. Now that I think about it, that could easily be fixable; just nest the topics inside a language-specific array. That would fix your switching problem. You would, however, have to manually load the language (if by tags, using the &lang=``) attribute for each secondary language entry you want.
I’m not crazy about any of the solutions here.
Having to reload the whole language set multiple times on a single page to avoid collisions seems wrong, especially since we have the information in the lexicon_entries table to avoid it.
I guess we could just suggest that developers use a language prefix on the keys: lexicion(’fr-firstName’) but then I’d have to change all the language-string keys in SPForm to en-spf-key which would annoy over 90% of the users for no reason.
We could add methods: lexicon->setNamespace() and lexicon->setLanguage(), but that creates unacceptable side-effect issues.
We could make lexicon->load() preserve the language, namespace, and topic, but that would probably mean a performance and memory hit.
We could get language strings straight from the DB rather than the lexicon with the ability to specify lang, namespace, and topic. Maybe xPDO caching would protect us from the performance hit -- we’d gain memory.
This is my favorite solution, I think:
We could create a new object called, say, "minilexicon" with its own load() and get() methods, both of which allowed the use of lang, namespace, and topic.
It would solve the problem of collisions with dual languages -- you could just instantiate two minilexicons. It separates 3PC lexicons from the core lexicon, which should speed up the manager. I think it would mean some memory savings when these go out of scope. It should solve the issue of collisions with core entries also, which I think could be a serious problem, though 3PC developers should really be using a prefix on their keys. It also fits nicely with the language directory structure I mentioned in the other thread since minilexicon->load() should know where to find things if they weren’t in the database and the minilexicon->get() method could optionally perform a minilexicon->load() of a topic (or the whole namespace) whenever the key wasn’t found.
I’m not crazy about the term "minilexicon," but I couldn’t come up with anything better.