[phpwebapp-commits] CVS: web_app/doc changes.txt,1.19,1.20
Brought to you by:
dashohoxha
From: Dashamir H. <das...@us...> - 2005-06-21 18:57:11
|
Update of /cvsroot/phpwebapp/web_app/doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6738/doc Modified Files: changes.txt Log Message: Index: changes.txt =================================================================== RCS file: /cvsroot/phpwebapp/web_app/doc/changes.txt,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** changes.txt 13 Jun 2005 14:25:47 -0000 1.19 --- changes.txt 21 Jun 2005 13:21:06 -0000 1.20 *************** *** 199,203 **** --- 199,284 ---- 'T_' is the name of the function whose strings will be extracted. + Tip: In order to translating attribute values, use a {{variable}} + inside the attribute value, and then in the PHP code that + adds the variable, get the appropriate translation. E.g. + + <input type="button" value="{{Search>>}}" /> (in HTML) + + WebApp::addVar('Search>>', T_("Search>>")); (in PHP) + + Tip: Some templates contain text, not just messages, which can + also be mixed with HTML tags (see e.g. + 'templates/search/help.html' in this case it is difficult + to translate it using translation messages. The best way is + to use a separate template for each language, like + 'help_en_US.html', 'help_sq_AL.html', etc. + When the template is included, something like this can be + used: + <include src="{{./}}help_{{lng}}.html" /> + where {{lng}} can be defined in the php code like this: + function onParse() + { + global $l10n; + WebApp::addVar('lng', $l10n->lng); + } + + ------------------------------------------------------------------- + + * Now it is possible to use translatable messages in the JS code + (e.g. in the messages that are displayed by alert()). Same as + in PHP and HTML, strings are translated by the function: + T_("...."). + + Attention: double quotes must be used ("), otherwise + xgettext will not be able to extract them. + + In order to have variables inside a message, you have to make + some tricks. E.g., to make translatable this message: + --code + var new_node_id = prompt("Rename node '" + node_id + "' to:"); + ---- + It can be written like this: + --code + var msg = T_("Rename node 'v_node_id' to:").replace(/v_node_id/, node_id); + //var msg = T_("Rename node 'v_node_id' to:"); + //msg = msg.replace(/v_node_id/, node_id); + var new_node_id = prompt(msg); + ---- + This allows the translator to change the position of the variable, + if needed. + + Note: How it Works + The JS function T_(msgid), which is included in the page by + the framework, returns the translation msgstr of the given msgid. + This translation is retrived from a list of translated messages, + which is contained by the JS object l10n of class L10n, which is + included in the page by the framework. If you view the source of + the page, you will see near the end something like this: + --code + <script type="text/javascript" language="javascript" + src="web_app/l10n/class.L10n.js"></script> + <script type="text/javascript" language="javascript"> + //<![CDATA[ + l10n = new L10n(); + l10n.addMsg("You are deleting this node and all the subnodes.", + "You are deleting this node and all the subnodes."); + l10n.addMsg("ID cannot be empty.", "ID cannot be empty."); + l10n.addMsg("Title cannot be empty.", "Title cannot be empty."); + l10n.addMsg("Please give an ID.", "Please give an ID."); + l10n.addMsg("Please give a title.", "Please give a title."); + l10n.addMsg("Rename 'v_item' to:", "Rename 'v_item' to:"); + l10n.addMsg("Your are deleting 'v_item'!", + "Your are deleting 'v_item'!"); + l10n.addMsg("Uploading:", "Uploading:"); + l10n.addMsg("Please wait...", "Please wait..."); + //]]> + </script> + ---- + This is generated automatically by the framework. For each JS file + that it includes in the <head> of the page, it also scans it for + translatable messages, gets their translation, and includes lines + l10n.addMsg(msgid, msgstr), as above. + ------------------------------------------------------------------- ------------------------------------------------------------------- |