By: Skrol29
Date: 2005-04-18
Time: 01:11
|
Multilanguage ApplicationsTinyButStrong has an easy technique for multilanguage support in your applications.
The MergeField() method enables you to merge a set of TBS fields by passing them to a user function. Technique 1 for text retrieved by its id: HTML :
Technique 2 for text directly in the field: HTML :
|
||||
By: khanhvu
Date: 2006-09-14
Time: 12:21
|
Re: Multilanguage ApplicationsDear Skrol29 !
I have read your Tips & Tricks of Multilanguage Applications but I can not understand how to start with this. I'm working on a project that have multilanguage, ofcouse building with TBS. With Traditional PHP, I will make a language file and define language text string then showing in template like this: {WELCOME} Ex: In english.php: define(WELCOME,"WELCOME"); In French.php: define(WELCOME,"BONJOUR"); How can I do this with TBS ? Thank you very much Mr Skrol29 ! |
||||
By: Skrol29
Date: 2006-09-15
Time: 00:52
|
Re: Multilanguage ApplicationsHello,
I think it is faster when you save multilanguage strings into PHP variables instead of constant. However, if you'd like to kepp constants, you can marge them using the same technique as above but with a function like this:
By the way : constants will be mergable using special var fields in TBS version 3.2.0 which is available in beta yet (see some messages before). |
||||
By: khanhvu
Date: 2006-09-15
Time: 06:29
|
Re: Multilanguage ApplicationsThanks Mr Skrol,
I have made this works: In en.php: $lang['WELCOME'] = 'WELCOME'; In fr.php $lang['WELCOME'] = 'BONJOUR'; In PHP file: $lang = array($lang); $TBS->MergeBlock('lang',$lang); In HTML file: [lang.WELCOME] Is this way better ? I understand your translatel function but I don't understand its usage. I mean how you make lang file, code file and html file with your function. Can you explain more. Thank you. |
||||
By: sheepy
Date: 2006-09-28
Time: 01:03
|
Re: Multilanguage ApplicationsYes currently I also use you solution, khanhvu.
Skrol29's technique 1 is good in the sense that it is called once for each language id, so you don't have to load the whole language table, useful if language resource is stored in database, with reasonable performance if sql query cache is enabled. Technique 2 is good in the sense that you can have localisation resources embeded in template. Whlie it's fast and simple IMHO it will make addition of language more painful, although for most sites this will never happens. If you have to load the whole table anyway, like if you are storing them in php or like if I am storing them in csv, then the way we do it works just fine. But if you want more control or additional functionality like safeguard for missing index, then user function is the way to go. In term of performance, since you're storing the array in php, with php optimisation like APC (Alternative PHP Cache) or Zend Cache you will have nothing to worry about. They should be installed by most if not every shared web host. |
||||
By: Pirjo Posio
Date: 2007-09-25
Time: 15:38
|
Re: Multilanguage ApplicationsHere's a solution, that can be used for internationalization purposes or just data in one language, where you can store variables embedded in the database records, if you wish. Or some records may contain variables, some not.
This technique I would like to call template swapping. (Have a temporary template). Here we have a login form (I borrowed one of Skrol29's, thank you!) and below the login form there is a one line message, that comes from the database, with some embedded variables. The database field is represented here by just a string. HTML:
Thanks for help given by Skrol29 and TomH! I hope this helps someone else. |
||||
By: Pirjo Posio
Date: 2007-10-04
Time: 12:37
|
Variables embedded in variables in TBS templatesTo make my post above more general:
If you have a need to merge a variable containing other php-variables try this:
PHP program that makes a submerge to merge the variables embedded in the string that is to make the contents of $msglang. Afterwards, there is a merge as usual to merge the main template.
|
||||
By: TomH
Date: 2010-09-18
Time: 23:26
|
Re: Variables embedded in variables in TBS templates((Hello Ms. Pirjo, hope you are well))
I have been trying some new things (for me) and I searched this forum for related coding as a way to see if I was on track. The code above by Pirjo has inspired me to to take the next step and make a function to do the dirty work. In this application I want to be able to interrupt the TBS processing for the current page and do the following: * read in a template having TBS blocks * populate the blocks with db content * save the merged template for later use * resume TBS processing for the current page Here's my first pass at a function to do this -- it actually seems to be working - it does create the merged subtemplate. And it does expire and re-build the merged files as expected. I see no evidence "yet" that it is breaking the TBS for the current page. ((But this stuff really scares me!))
Here's the function as it's being ussd in the page script
I would greatly appreciate a critique of this approach -and- and warnings of weaknesses or outright errors. You can see a protptype of this at http://tomhenry.us/tbs3/cachenow_merged/contacts_merged_func.php sometimes easier to understand code when the page can be seen. Thanks very much for any guidance you can give. And thanks for TBS every day, TomH |