Code Monkey home page Code Monkey logo

Comments (2)

snytkine avatar snytkine commented on June 27, 2024

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

from lampcms.

snytkine avatar snytkine commented on June 27, 2024

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.

from lampcms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.