Steve Piercy - Web Site Builder Re: Introduction to knop_lang
Dec 03, 2007; 10:56
Steve Piercy - Web Site Builder
Re: Introduction to knop_lang
This looks fairly comprehensive. Very nice work. Thanks, Johan!
What would the data model look like? Would "language packs" be text files or records in a table?
--steve
On Monday, December 3, 2007, inbox_js@solve.se (Johan Solve) pronounced:
>A knop_lang object holds all language strings for all supported languages. >Strings are stored under a unique text key, but the same key is of course used >for the different language versions of the same string. >Strings can be separated into different variables if it helps managing them. > >When the language of a string object is set, that language is used for all >subsequent requests for strings until another language is set. > >If no language is set, knop_lang uses the browser's preferred language if it's >available in the knop_lang object, >otherwise it defaults to the first language (unless a default language has been >set). > > >Examples > var: 'lang_messages'=(knop_lang: -default='en'); > $lang_messages -> (addstring: -key='welcome', -value='Welcome to the home page', >-language='en'); > $lang_messages -> (addstring: -key='welcome', -value='V§lkommen till hemsidan', >-language='sv'); > $lang_messages -> (addstring: -key='loggedin', -value='You are logged in as #1# >#2#', -language='en'); > $lang_messages -> (addstring: -key='loggedin', -value='Du §r inloggad som #1# >#2#', -language='sv'); > > // proper call, defaults to the browser's preferred language > $lang_messages -> (getstring: 'welcome'); > // shorthand call > $lang_messages -> welcome; > > // change language > $lang_messages -> (setlanguage: 'sv'); > $lang_messages -> welcome; > > // proper call with replacements > $lang_messages -> (getstring: -key='loggedin': -replace=(array: (field: >'firstname'), (field: 'lastname'))); > > // shorthand call with replacements > $lang_messages -> (loggedin: -replace=(array: (field: 'firstname'), (field: >'lastname'))); > > > >Tag reference (please excuse the bad formatting...) > > >knop_lang > -optional='default', // default language > -optional='fallback'; // if specified, falls back to default language if >key is missing > >-> addstring > -required='language', > -required='key', // textkey to store the string under. Replaces any existing >key for the same language. > -required='value'; // The actual string (can also be compound expression). Can >contain replacement tokens #1#, #2# etc. > >-> addlanguage // adds a map with language strings for an entire language. > // Replaces all existing language strings for that language. > -required='language', > -required='strings', -type='map'; > >-> getstring // returns a specific text string in the language that has previously >been set for the instance. > // If the string is not available in the chosen language and -fallback >is specified, > // the string for the language that was first specified for that key >will be returned. > -required='key', // textkey to return the string for > -optional='language', -copy, // to return a string for a specified language >(temporary override) > -optional='replace', -copy; // single value or array of values that will be >used as substitutions > // for placeholders #1#, #2# etc in the returned >string, in the order they appear. > // Replacements can be compund expressions, >which will be executed. > // Can also be map or pair array, and in that >case the left hand element of the map/array will be replaced by the right hand >element. > >-> setlanguage // sets the current language for the string object > -required='language'; // string > >-> validlanguage // checks if a specified language exists in the string object, >returns true or false. > -required='language'; // string > >-> browserlanguage // autodetects and returns the most preferred language out of all >available languages > // as specified by the browser's accept-language q-value > >-> languages // returns an array of all available languages in the string object >(out of the languages in the -language array if specified) > -optional='language', -copy; //array or string > >-> keys // returns array of all text keys in the string object > >
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Steve Piercy Web Site Builder Soquel, CA <web@StevePiercy.com> <http://www.StevePiercy.com/>
############################################################# This message is sent to you because you are subscribed to the mailing list <knop@lists.montania.se>. To unsubscribe, E-mail to: <knop-off@lists.montania.se> Send administrative queries to <knop-request@lists.montania.se> List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html Project homepage http://montania.se/projects/knop/ Google Code has the latest downloads at http://code.google.com/p/knop/
Dec 03
Johan Solve Introduction to knop_lang
Dec 03, 2007; 16:46
Johan Solve
Introduction to knop_lang
Dec 03
Jolle Carlestam Re: Introduction to knop_lang
Dec 03, 2007; 21:27
Jolle Carlestam
Re: Introduction to knop_lang
Dec 03
Johan Solve Re: Introduction to knop_lang
Dec 03, 2007; 22:32
Johan Solve
Re: Introduction to knop_lang
Search
Lasso Programming
This site manages and broadcasts several email lists pertaining to Lasso Programming and technologies related and used by Lasso developers. Sign up today!