mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-25 16:19:00 +01:00
fixed translations on client-side: server sends now currentapp and langRequire to client, which uses that to translate phrases, langRequire is only stored in egw object for matching app-name and window!
This commit is contained in:
parent
a6311fa1a3
commit
0bb8093426
@ -127,6 +127,25 @@ class etemplate_new extends etemplate_widget_template
|
||||
// some apps (eg. InfoLog) set app_header only in get_rows depending on filter settings
|
||||
self::$request->app_header = $GLOBALS['egw_info']['flags']['app_header'];
|
||||
|
||||
// compile required translations translations
|
||||
translation::add_app('etemplate');
|
||||
$currentapp = $GLOBALS['egw_info']['flags']['currentapp'];
|
||||
$langRequire = array('common' => array(), 'etemplate' => array()); // keep that order
|
||||
foreach(translation::$loaded_apps as $l_app => $lang)
|
||||
{
|
||||
if (!in_array($l_app, array($currentapp, 'custom')))
|
||||
{
|
||||
$langRequire[$l_app] = array('app' => $l_app, 'lang' => $lang);
|
||||
}
|
||||
}
|
||||
foreach(array($currentapp, 'custom') as $l_app)
|
||||
{
|
||||
if (isset(translation::$loaded_apps[$l_app]))
|
||||
{
|
||||
$langRequire[$l_app] = array('app' => $l_app, 'lang' => translation::$loaded_apps[$l_app]);
|
||||
}
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'etemplate_exec_id' => self::$request->id(),
|
||||
'app_header' => self::$request->app_header,
|
||||
@ -135,6 +154,8 @@ class etemplate_new extends etemplate_widget_template
|
||||
'readonlys' => self::$request->readonlys,
|
||||
'modifications' => self::$request->modifications,
|
||||
'validation_errors' => self::$validation_errors,
|
||||
'langRequire' => array_values($langRequire),
|
||||
'currentapp' => $currentapp,
|
||||
);
|
||||
|
||||
// Info required to load the etemplate client-side
|
||||
@ -143,7 +164,7 @@ class etemplate_new extends etemplate_widget_template
|
||||
'name' => $this->name,
|
||||
'url' => $GLOBALS['egw_info']['server']['webserver_url'].$this->rel_path,
|
||||
'data' => $data,
|
||||
'DOMNodeID' => $dom_id
|
||||
'DOMNodeID' => $dom_id,
|
||||
);
|
||||
if (self::$response) // call is within an ajax event / form submit
|
||||
{
|
||||
@ -168,15 +189,6 @@ class etemplate_new extends etemplate_widget_template
|
||||
egw_framework::validate_file('.','app',$app,false);
|
||||
}
|
||||
|
||||
|
||||
// load translations
|
||||
translation::add_app('etemplate');
|
||||
$langRequire = array();
|
||||
foreach(translation::$loaded_apps as $l_app => $lang)
|
||||
{
|
||||
$langRequire[] = array('app' => $l_app, 'lang' => $lang);
|
||||
}
|
||||
|
||||
$header = $GLOBALS['egw']->framework->header(array(
|
||||
'etemplate' => $load_array
|
||||
));
|
||||
|
@ -81,14 +81,6 @@ var et2_template = et2_DOMWidget.extend(
|
||||
{
|
||||
var template_name = this.options.template || this.id;
|
||||
|
||||
// Set the api instance to the first part of the name of the
|
||||
// template, if it's in app.function.template format
|
||||
var splitted = template_name.split('.');
|
||||
if(splitted.length >= 3)
|
||||
{
|
||||
this.setApiInstance(egw(splitted[0], this._parent.egw().window));
|
||||
}
|
||||
|
||||
// Check to see if XML is known
|
||||
var xml = null;
|
||||
var templates = this.getRoot().getInstanceManager().templates;
|
||||
@ -98,7 +90,7 @@ var et2_template = et2_DOMWidget.extend(
|
||||
// eg: row instead of app.something.row
|
||||
for(var key in templates)
|
||||
{
|
||||
splitted = key.split('.');
|
||||
var splitted = key.split('.');
|
||||
if(splitted[splitted.length-1] == template_name)
|
||||
{
|
||||
xml = templates[key];
|
||||
@ -108,7 +100,7 @@ var et2_template = et2_DOMWidget.extend(
|
||||
if(!xml)
|
||||
{
|
||||
// Ask server
|
||||
splitted = template_name.split('.');
|
||||
var splitted = template_name.split('.');
|
||||
var path = this.egw().webserverUrl + "/" + splitted.shift() + "/templates/default/" + splitted.join('.') + ".xet";
|
||||
|
||||
if(splitted.length)
|
||||
|
@ -189,8 +189,14 @@ etemplate2.prototype._createArrayManagers = function(_data)
|
||||
*/
|
||||
etemplate2.prototype.load = function(_name, _url, _data, _callback)
|
||||
{
|
||||
|
||||
egw().debug("info", "Loaded data", _data);
|
||||
var currentapp = _data.currentapp || window.egw_appName;
|
||||
|
||||
// require necessary translations from server, if not already loaded
|
||||
if ($j.isArray(_data.langRequire))
|
||||
{
|
||||
egw(currentapp, window).langRequire(window, _data.langRequire);
|
||||
}
|
||||
|
||||
// Appname should be first part of the template name
|
||||
var split = _name.split('.');
|
||||
@ -221,7 +227,7 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback)
|
||||
|
||||
// Create the basic widget container and attach it to the DOM
|
||||
this.widgetContainer = new et2_container(null);
|
||||
this.widgetContainer.setApiInstance(egw(appname, egw.elemWindow(this.DOMContainer)));
|
||||
this.widgetContainer.setApiInstance(egw(currentapp, egw.elemWindow(this.DOMContainer)));
|
||||
this.widgetContainer.setInstanceManager(this);
|
||||
this.widgetContainer.setParentDOMNode(this.DOMContainer);
|
||||
|
||||
@ -264,7 +270,6 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback)
|
||||
$j(this.DOMContainer).trigger('load', this);
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Load & process
|
||||
if(!this.templates[_name])
|
||||
@ -642,6 +647,12 @@ function etemplate2_handle_load(_type, _response)
|
||||
{
|
||||
window.focus();
|
||||
}
|
||||
|
||||
// handle framework.setSidebox calls
|
||||
if (window.framework && jQuery.isArray(data['setSidebox']))
|
||||
{
|
||||
window.framework.setSidebox.apply(window, JSON.parse(data['setSidebox']));
|
||||
}
|
||||
|
||||
// regular et2 re-load
|
||||
if (typeof data.url == "string" && typeof data.data === 'object')
|
||||
|
@ -331,10 +331,13 @@ class translation
|
||||
//error_log(__METHOD__."('$app', '$lang') caching now ".(is_array($loaded)?'Array('.count($loaded).')':array2string($loaded))." egw_cache::setCache() returned ".array2string($ok));
|
||||
}
|
||||
}
|
||||
if ($loaded) self::$lang_arr = array_merge(self::$lang_arr, $loaded);
|
||||
self::$loaded_apps[$app] = $l;
|
||||
if ($loaded)
|
||||
{
|
||||
self::$lang_arr = array_merge(self::$lang_arr, $loaded);
|
||||
self::$loaded_apps[$app] = $l; // dont set something not existing to $loaded_apps, no need to load client-side
|
||||
}
|
||||
}
|
||||
//error_log(__METHOD__.'('.array2string($apps).", '$lang') took ".(1000*(microtime(true)-$start))." ms, loaded ".count($loaded)." phrases -> total=".count(self::$lang_arr));//.": ".function_backtrace());
|
||||
//error_log(__METHOD__.'('.array2string($apps).", '$lang') took ".(1000*(microtime(true)-$start))." ms, loaded_apps=".array2string(self::$loaded_apps).", loaded ".count($loaded)." phrases -> total=".count(self::$lang_arr));//.": ".function_backtrace());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,6 +18,9 @@
|
||||
egw_ready;
|
||||
*/
|
||||
|
||||
/**
|
||||
* @augments Class
|
||||
*/
|
||||
egw.extend('lang', egw.MODULE_GLOBAL, function() {
|
||||
|
||||
/**
|
||||
@ -34,6 +37,7 @@ egw.extend('lang', egw.MODULE_GLOBAL, function() {
|
||||
*
|
||||
* @param string _app
|
||||
* @param object _message message => translation pairs
|
||||
* @memberOf egw
|
||||
*/
|
||||
set_lang_arr: function(_app, _messages)
|
||||
{
|
||||
@ -60,7 +64,7 @@ egw.extend('lang', egw.MODULE_GLOBAL, function() {
|
||||
_msg = _msg.toLowerCase();
|
||||
|
||||
// search apps in given order for a replacement
|
||||
var apps = ['custom', this.getAppName(), 'etemplate', 'common'];
|
||||
var apps = this.lang_order || ['custom', this.getAppName(), 'etemplate', 'common'];
|
||||
for(var i = 0; i < apps.length; ++i)
|
||||
{
|
||||
if (typeof lang_arr[apps[i]] != "undefined" &&
|
||||
@ -105,6 +109,7 @@ egw.extend('lang', egw.MODULE_GLOBAL, function() {
|
||||
|
||||
// Build the file names which should be included
|
||||
var jss = [];
|
||||
var apps = [];
|
||||
for (var i = 0; i < _apps.length; i++)
|
||||
{
|
||||
if (typeof lang_arr[_apps[i].app] === "undefined")
|
||||
@ -113,6 +118,11 @@ egw.extend('lang', egw.MODULE_GLOBAL, function() {
|
||||
+ '/phpgwapi/lang.php?app='
|
||||
+ _apps[i].app + '&lang=' + _apps[i].lang);
|
||||
}
|
||||
apps.push(_apps[i].app);
|
||||
}
|
||||
if (this !== egw)
|
||||
{
|
||||
this.lang_order = apps.reverse();
|
||||
}
|
||||
|
||||
// Only continue if we need to include a language
|
||||
|
Loading…
Reference in New Issue
Block a user