mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-08 00:54:50 +01:00
got clientside translations working for etemplate2 apps: egw.lang("%1 timesheet(s) %2", 5, egw.lang("deleted"))
This commit is contained in:
parent
934e33fdd7
commit
16c6a8d4f9
@ -768,9 +768,10 @@ abstract class egw_framework
|
||||
$java_script .= self::get_script_links();
|
||||
|
||||
// set webserver_url for json
|
||||
$java_script .= "<script type=\"text/javascript\">\nwindow.egw_webserverUrl = '".
|
||||
$java_script .= "<script type=\"text/javascript\">\nwindow.egw_webserverUrl = egw.webserverUrl = '".
|
||||
($GLOBALS['egw_info']['server']['enforce_ssl'] && substr($GLOBALS['egw_info']['server']['webserver_url'],0,8) != 'https://' ? 'https://'.$_SERVER['HTTP_HOST'] : '').
|
||||
$GLOBALS['egw_info']['server']['webserver_url']."';\n";
|
||||
$java_script .= 'window.egw_appName = "'.$GLOBALS['egw_info']['flags']['currentapp'].'";'."\n";
|
||||
|
||||
// add link registry to non-popup windows, if explicit requested (idots_framework::navbar() loads it, if not explicit specified!)
|
||||
if ($GLOBALS['egw_info']['flags']['js_link_registry'])
|
||||
|
@ -16,9 +16,9 @@ var egw;
|
||||
|
||||
/**
|
||||
* Central object providing all kinds of api services on clientside:
|
||||
* - preferences
|
||||
* - configuration
|
||||
* - link registry
|
||||
* - preferences: egw.preferences("dateformat")
|
||||
* - translation: egw.lang("%1 entries deleted", 5)
|
||||
* - link registry: egw.open(123, "infolog")
|
||||
*/
|
||||
if (window.opener && typeof window.opener.egw == 'object')
|
||||
{
|
||||
@ -33,6 +33,8 @@ else
|
||||
egw = {
|
||||
/**
|
||||
* Object holding the prefences as 2-dim. associative array, use egw.preference(name[,app]) to access it
|
||||
*
|
||||
* @access: private, use egw.preferences() or egw.set_perferences()
|
||||
*/
|
||||
prefs: {
|
||||
common: {
|
||||
@ -41,6 +43,13 @@ else
|
||||
lang: "en"
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* base-URL of the EGroupware installation
|
||||
*
|
||||
* get set via egw_framework::header()
|
||||
*/
|
||||
webserverUrl: "/egroupware",
|
||||
|
||||
/**
|
||||
* Setting prefs for an app or 'common'
|
||||
@ -69,7 +78,7 @@ else
|
||||
*/
|
||||
preference: function(_name, _app)
|
||||
{
|
||||
if (typeof app == 'undefined') _app = 'common';
|
||||
if (typeof _app == 'undefined') _app = 'common';
|
||||
|
||||
if (typeof this.prefs[_app] == 'undefined')
|
||||
{
|
||||
@ -80,6 +89,8 @@ else
|
||||
|
||||
/**
|
||||
* Translations
|
||||
*
|
||||
* @access: private, use egw.lang() or egw.set_lang_arr()
|
||||
*/
|
||||
lang_arr: {},
|
||||
|
||||
@ -102,7 +113,31 @@ else
|
||||
*/
|
||||
lang: function(_msg, _arg1)
|
||||
{
|
||||
return _msg;
|
||||
var translation = _msg;
|
||||
_msg = _msg.toLowerCase();
|
||||
|
||||
// search apps in given order for a replacement
|
||||
var apps = [window.egw_appName, 'etemplate', 'common'];
|
||||
for(var i = 0; i < apps.length; ++i)
|
||||
{
|
||||
if (typeof this.lang_arr[apps[i]][_msg] != 'undefined')
|
||||
{
|
||||
translation = this.lang_arr[apps[i]][_msg];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (arguments.length == 1) return translation;
|
||||
|
||||
if (arguments.length == 2) return translation.replace('%1', arguments[1]);
|
||||
|
||||
// to cope with arguments containing '%2' (eg. an urlencoded path like a referer),
|
||||
// we first replace all placeholders '%N' with '|%N|' and then we replace all '|%N|' with arguments[N]
|
||||
translation = translation.replace(/%([0-9]+)/g, '|%$1|');
|
||||
for(var i = 1; i < arguments.length; ++i)
|
||||
{
|
||||
translation = translation.replace('|%'+i+'|', arguments[i]);
|
||||
}
|
||||
return translation;
|
||||
},
|
||||
|
||||
/**
|
||||
@ -146,7 +181,7 @@ else
|
||||
alert('egw.open() type "'+type+'" is NOT defined in link registry for app "'+app+'"!');
|
||||
return;
|
||||
}
|
||||
var url = egw_webserverUrl+'/index.php';
|
||||
var url = this.webserverUrl+'/index.php';
|
||||
var delimiter = '?';
|
||||
var params = app_registry[type];
|
||||
if (type == 'view' || type == 'edit') // add id parameter for type view or edit
|
||||
@ -196,6 +231,8 @@ else
|
||||
|
||||
/**
|
||||
* Link registry
|
||||
*
|
||||
* @access: private, use egw.open() or egw.set_link_registry()
|
||||
*/
|
||||
link_registry: null,
|
||||
|
||||
|
@ -22,6 +22,10 @@ $GLOBALS['egw_info'] = array(
|
||||
|
||||
include '../header.inc.php';
|
||||
|
||||
// just to be sure, noone tries something nasty ...
|
||||
if (!preg_match('/^[a-z0-9_]+$/i', $_GET['app'])) die('No valid application-name given!');
|
||||
if (!preg_match('/^[a-z]{2}(-[a-z]{2})?$/i', $_GET['lang'])) die('No valid lang-name given!');
|
||||
|
||||
// use an etag with app, lang and a hash over the creation-times of all lang-files
|
||||
$etag = '"'.$_GET['app'].'-'.$_GET['lang'].'-'.md5($GLOBALS['egw_info']['server']['lang_ctimes']).'"';
|
||||
|
||||
@ -44,10 +48,7 @@ if (!count(translation::$lang_arr))
|
||||
translation::add_app($_GET['app'], 'en');
|
||||
}
|
||||
|
||||
|
||||
echo '
|
||||
if (typeof window.egw_lang == "undefined") window.egw_lang = {};
|
||||
$j.extend(window.egw_lang, '.json_encode(translation::$lang_arr).');';
|
||||
echo 'egw.set_lang_arr("'.$_GET['app'].'", '.json_encode(translation::$lang_arr).');';
|
||||
|
||||
// Content-Lenght header is important, otherwise browsers dont cache!
|
||||
Header('Content-Length: '.ob_get_length());
|
@ -87,7 +87,7 @@ class idots_framework extends egw_framework
|
||||
// make sure header is output only once
|
||||
if (self::$header_done) return '';
|
||||
self::$header_done = true;
|
||||
error_log(__METHOD__."() this->tpl=".array2string($this->tpl).' '.function_backtrace());
|
||||
|
||||
// add a content-type header to overwrite an existing default charset in apache (AddDefaultCharset directiv)
|
||||
header('Content-type: text/html; charset='.translation::charset());
|
||||
|
||||
@ -174,12 +174,6 @@ egw.set_preferences('.json_encode($GLOBALS['egw_info']['user']['preferences']['c
|
||||
$vars['current_users'] = $vars['quick_add'] = $vars['user_info']='';
|
||||
}
|
||||
|
||||
// add the name of the current application as global js variable - the
|
||||
// name of the current application can be obtained by using the
|
||||
// jsapi egw_getAppName() function
|
||||
$content .= '<script type="text/javascript">window.egw_appName = "'.
|
||||
$GLOBALS['egw_info']['flags']['currentapp'].'";</script>'."\n";
|
||||
|
||||
$this->tpl->set_var($vars);
|
||||
$content .= $this->tpl->fp('out','navbar_header');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user