Update of /cvsroot/phpwebapp/web_app/l10n
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22457/l10n
Modified Files:
class.L10n.php
Added Files:
wbJSL10n.php wbJSL10n.html class.L10n.js
Log Message:
added translation (i18n/l10n) support for messages in the JS code
--- NEW FILE: wbJSL10n.php ---
<?php
/*
This file is part of phpWebApp, which is a framework for building web
application based on relational databases.
Copyright 2001,2002,2003,2004 Dashamir Hoxha, das...@us...
phpWebApp is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
phpWebApp is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with phpWebApp; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* Includes the JS L10n messages in the HTML page.
* @package l10n
*/
class wbJSL10n extends WebObject
{
function onRender()
{
global $webPage;
$arr_msg = array();
for ($i=0; $i < sizeof($webPage->js_i18n_messages); $i++)
{
$msgid = $webPage->js_i18n_messages[$i];
$msgstr = T_($msgid);
$arr_msg[] = "l10n.addMsg(\"$msgid\", \"$msgstr\");";
}
//add the template variable {{JS_L10N_MESSAGES}}
WebApp::addVar("JS_L10N_MESSAGES", implode($arr_msg, "\n "));
}
}
?>
--- NEW FILE: wbJSL10n.html ---
<webbox id="wbJSL10n">
<!--# insert the JS l10n messages #-->
<script type="text/javascript" language="javascript"
src="{{./}}class.L10n.js"></script>
<script type="text/javascript" language="javascript">
//<![CDATA[
l10n = new L10n();
{{JS_L10N_MESSAGES}}
//]]>
</script>
</webbox>
--- NEW FILE: class.L10n.js ---
//-*- mode: C; -*-//tells emacs to use mode C for this file
/*
Copyright 2001,2002,2003 Dashamir Hoxha, das...@us...
This file is part of phpWebApp.
phpWebApp is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
phpWebApp is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with phpWebApp; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* L10n class keeps a list of translatable messages and their
* translation. It helps to localize messages in the JS code.
*/
function L10n()
{
this.messages = new Array();
this.addMsg = l10n_addMsg;
this.gettext = l10n_gettext;
}
/** Add a new message and its translation in the list. */
function l10n_addMsg(msgid, msgstr)
{
var msg = { id:msgid, str:msgstr };
this.messages.push(msg);
}
/** Return the translation of a message. */
function l10n_gettext(msgid)
{
var i;
for (i=0; i < this.messages.length; i++)
if (this.messages[i].id == msgid)
{
//found, return the translation
return this.messages[i].str;
}
//not found, return the msgid itself
return msgid;
}
function T_(msgid)
{
return l10n.gettext(msgid);
}
Index: class.L10n.php
===================================================================
RCS file: /cvsroot/phpwebapp/web_app/l10n/class.L10n.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** class.L10n.php 16 Jun 2005 11:34:37 -0000 1.2
--- class.L10n.php 21 Jun 2005 08:39:51 -0000 1.3
***************
*** 55,58 ****
--- 55,60 ----
* the translation file (*.mo) of the containing template or webbox
* (from which this template/webbox is included directly or indirectly).
+ *
+ * @package l10n
*/
class L10n
|