LampCMS
LampCMS copied to clipboard
Work on I18N class
Write I18N class based on Mongo. Collection will have string as _id, then object of lang=>string Then when looking for string we select all translations, if requested lang key not found, then use default lang, if default lang not found (usually this means the findOne will return empty) then use string key itself, replacing _ with space and uppercasing first word. Lang keys should be line 'en_US' or just 'en', not really sure yet.
the value of _id will be like en_US, fr_FR .... First it will be easy to just get all supported languages: just select all from I18N - only get _id and lang_name keys lang_name is just descriptive name like "English US" All the records will have 'strings' object as nested object with string => value pairs The I18N Class will be serializable and will go into user's SESSION for caching. This is how it works:
Object holds $aLocale array. Object has $locale = en_US for example, to indicate which locate the strings are in. Then to lookup a string we do this: if !array_key_exists($str, $this->aLocale) then fetch another array from Mongo, this time with default values for the "language-only", for example "en" and do the array_merge with aLocate. Then if values still not found then fetch default lang array and merge it again. Actually this can be just one step: fetch array in default lang, then fetch array in non-locate lang, for example if user's lang is en_GB we then select 2 records: 'en' and default lang - if default lang is not already the same as 'en' We then merge the 3 arrays - Locale, default lang and default. The result is the Locale... Me also set "merged" flag to "YES" to then if we still cannot find the string we don't do the step 2 again and instead we will just use the string as value, at the same time adding it to Locale array - sort of like for caching... The small possible problem is that admin adds new string(s) while peeps are still logged in and then they are using outdated array, but this is not really a big deal...
What if we do one select where locate $in 'user's locate', 'no-locale-lang', 'default lang'. Then merge these 3 and that's our array! Put it into user's session and reuse! Can EVEN cache this result array in Cache to reuse between users! Just make sure to use the 'tag' in cache so it can be removed from cache easily by using tag.