Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work on I18N class #4

Open
snytkine opened this issue Feb 12, 2011 · 2 comments
Open

Work on I18N class #4

snytkine opened this issue Feb 12, 2011 · 2 comments
Labels

Comments

@snytkine
Copy link
Owner

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.

@snytkine
Copy link
Owner Author

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...

@snytkine snytkine reopened this Jun 10, 2011
@snytkine
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant