4 require_once
"./Services/Object/classes/class.ilObject.php";
40 public function __construct($a_id = 0, $a_call_by_reference =
false)
43 $lng = $DIC->language();
46 parent::__construct($a_id, $a_call_by_reference);
51 $this->lang_default =
$lng->lang_default;
52 $this->lang_user =
$lng->lang_user;
53 $this->lang_path =
$lng->lang_path;
54 $this->cust_lang_path =
$lng->cust_lang_path;
55 $this->separator =
$lng->separator;
56 $this->comment_separator =
$lng->comment_separator;
70 if ($langObj->isInstalled()) {
71 $objects[] = $langObj;
105 if ($this->key == $this->lang_default) {
117 if ($this->key == $this->lang_user) {
132 if (substr($this->
getStatus(), 0, 9) ==
"installed") {
147 if (substr($this->
getStatus(), 10) ==
"local") {
162 if (!empty($scope)) {
163 if ($scope ==
'global') {
166 $scopeExtension =
'.' . $scope;
172 if ($this->
check($scope)) {
175 $this->
flush(
'keep_local');
183 $newDesc =
'installed';
184 } elseif ($scope ==
'local') {
185 $newDesc =
'installed_local';
203 if ((substr($this->status, 0, 9) ==
"installed") && ($this->key != $this->lang_default) && ($this->key != $this->lang_user)) {
223 if ($this->
check()) {
224 $this->
flush(
'keep_local');
230 if ($this->
isLocal() ==
true) {
231 if ($this->
check(
'local')) {
250 $refreshed = array();
254 if ($langObj->refresh()) {
255 $refreshed[] = $langObj->getKey();
260 self::refreshPlugins($refreshed);
271 $ilPluginAdmin = $DIC[
'ilPluginAdmin'];
274 include_once(
"./Services/Component/classes/class.ilPluginSlot.php");
276 foreach ($slots as $slot) {
277 $act_plugins = $ilPluginAdmin->getActivePluginsForSlot(
278 $slot[
"component_type"],
279 $slot[
"component_name"],
282 foreach ($act_plugins as $plugin) {
283 include_once(
"./Services/Component/classes/class.ilPlugin.php");
285 $slot[
"component_type"],
286 $slot[
"component_name"],
290 if (is_object($pl)) {
291 $pl->updateLanguages($a_lang_keys);
306 $ilDB = $DIC->database();
308 if (!$a_keep_local_change) {
309 $ilDB->manipulate(
"DELETE FROM lng_data WHERE lang_key = " .
310 $ilDB->quote($a_lang_key,
"text"));
312 $ilDB->manipulate(
"DELETE FROM lng_data WHERE lang_key = " .
313 $ilDB->quote($a_lang_key,
"text") .
314 " AND local_change IS NULL");
322 public function flush($a_mode =
'all')
325 $ilDB = $DIC->database();
329 if ($a_mode ==
'all') {
330 $ilDB->manipulate(
"DELETE FROM lng_modules WHERE lang_key = " .
331 $ilDB->quote($this->key,
"text"));
345 $ilDB = $DIC->database();
347 if ($a_min_date ==
"") {
348 $a_min_date =
"1980-01-01 00:00:00";
350 if ($a_max_date ==
"") {
351 $a_max_date =
"2200-01-01 00:00:00";
355 "SELECT * FROM lng_data WHERE lang_key = %s " .
356 "AND local_change >= %s AND local_change <= %s",
357 $ilDB->quote($this->key,
"text"),
358 $ilDB->quote($a_min_date,
"timestamp"),
359 $ilDB->quote($a_max_date,
"timestamp")
365 $changes[
$row[
"module"]][
$row[
"identifier"]] = $row[
"value"];
379 $ilDB = $DIC->database();
382 "SELECT MAX(local_change) last_change FROM lng_data " .
383 "WHERE lang_key = %s AND local_change IS NOT NULL",
384 $ilDB->quote($a_key,
"text")
389 return $row[
'last_change'];
405 $ilDB = $DIC->database();
409 "SELECT * FROM lng_data WHERE lang_key = %s AND module = %s AND local_change IS NOT NULL",
410 array(
'text',
'text'),
411 array($a_key, $a_module)
415 $changes[
$row[
'identifier']] = $row[
'value'];
429 $ilDB = $DIC->database();
431 if (!empty($scope)) {
432 if ($scope ==
'global') {
435 $scopeExtension =
'.' . $scope;
440 if ($scope ==
"local") {
441 $path = $this->cust_lang_path;
444 $lang_file =
$path .
"/ilias_" . $this->key .
".lang" . $scopeExtension;
446 if (is_file($lang_file)) {
448 $lang_array = array();
449 $lang_array[
"common"] = array();
452 if ($content = $this->
cut_header(file($lang_file))) {
458 } elseif ($scope ==
'local') {
462 $change_date = date(
"Y-m-d H:i:s", time());
463 $min_date = date(
"Y-m-d H:i:s", filemtime($lang_file));
467 foreach ($content as
$key => $val) {
473 $separated = explode($this->separator, trim($val));
474 $pos = strpos($separated[2], $this->comment_separator);
475 if ($pos !==
false) {
476 $separated[3] = substr($separated[2], $pos + strlen($this->comment_separator));
477 $separated[2] = substr($separated[2], 0, $pos);
481 $local_value = $local_changes[$separated[0]][$separated[1]];
486 if ($local_value !=
"" and $local_value != $separated[2]) {
488 $lang_array[$separated[0]][$separated[1]] = $local_value;
491 if ($double_checker[$separated[0]][$separated[1]][$this->key]) {
492 $this->
ilias->raiseError(
493 "Duplicate Language Entry in $lang_file:\n$val",
494 $this->
ilias->error_obj->MESSAGE
497 $double_checker[$separated[0]][$separated[1]][
$this->key] =
true;
510 $lang_array[$separated[0]][$separated[1]] = $separated[2];
512 } elseif ($scope ==
'local') {
515 if ($local_value !=
"") {
517 $lang_array[$separated[0]][$separated[1]] = $local_value;
531 $lang_array[$separated[0]][$separated[1]] = $separated[2];
539 } elseif ($scope ==
'local') {
540 $ld =
"installed_local";
543 $query =
"UPDATE object_data SET " .
544 "description = " .
$ilDB->quote(
$ld,
"text") .
", " .
545 "last_update = " .
$ilDB->now() .
" " .
546 "WHERE title = " .
$ilDB->quote($this->key,
"text") .
" " .
552 foreach ($lang_array as
$module => $lang_arr) {
553 if ($scope ==
"local") {
554 $q =
"SELECT * FROM lng_modules WHERE " .
555 " lang_key = " .
$ilDB->quote($this->key,
"text") .
557 $set =
$ilDB->query($q);
559 $arr2 = unserialize(
$row[
"lang_array"]);
560 if (is_array($arr2)) {
561 $lang_arr = array_merge($arr2, $lang_arr);
564 ilObjLanguage::replaceLangModule($this->key,
$module, $lang_arr);
572 final public static function replaceLangModule($a_key, $a_module, $a_array)
575 $ilDB = $DIC->database();
580 $ilDB->manipulate(sprintf(
581 "DELETE FROM lng_modules WHERE lang_key = %s AND module = %s",
582 $ilDB->quote($a_key,
"text"),
583 $ilDB->quote($a_module,
"text")
590 $ilDB->insert(
"lng_modules", array(
591 "lang_key" => array(
"text", $a_key),
592 "module" => array(
"text", $a_module),
593 "lang_array" => array(
"clob", serialize((array) $a_array))
599 "SELECT lang_array FROM lng_modules WHERE lang_key = %s AND module = %s",
600 array(
'text',
'text'),
601 array($a_key, $a_module)
605 $unserialied = unserialize(
$row[
'lang_array']);
606 if (!is_array($unserialied)) {
610 "Data for module '" . $a_module .
"' of language '" . $a_key .
"' is not correctly saved. " .
611 "Please check the collation of your database tables lng_data and lng_modules. It must be utf8_unicode_ci.",
625 $a_local_change = null,
629 $ilDB = $DIC->database();
634 if (isset($a_remarks)) {
635 $a_remarks = substr($a_remarks, 0, 250);
637 if ($a_remarks ==
'') {
641 if (isset($a_value)) {
642 $a_value = substr($a_value, 0, 4000);
644 if ($a_value ==
'') {
651 'module' => array(
'text',$a_module),
652 'identifier' => array(
'text',$a_identifier),
653 'lang_key' => array(
'text',$a_lang_key)
656 'value' => array(
'text',$a_value),
657 'local_change' => array(
'timestamp',$a_local_change),
658 'remarks' => array(
'text', $a_remarks)
687 $a_local_change = null,
691 $ilDB = $DIC->database();
693 if (isset($a_remarks)) {
694 $a_remarks = substr($a_remarks, 0, 250);
696 if ($a_remarks ==
'') {
700 if (isset($a_value)) {
701 $a_value = substr($a_value, 0, 4000);
703 if ($a_value ==
'') {
707 $ilDB->manipulate(sprintf(
709 "SET value = %s, local_change = %s, remarks = %s " .
710 "WHERE module = %s AND identifier = %s AND lang_key = %s ",
711 $ilDB->quote($a_value,
"text"),
712 $ilDB->quote($a_local_change,
"timestamp"),
713 $ilDB->quote($a_remarks,
"text"),
714 $ilDB->quote($a_module,
"text"),
715 $ilDB->quote($a_identifier,
"text"),
716 $ilDB->quote($a_lang_key,
"text")
727 $ilDB = $DIC->database();
729 $ilDB->manipulate(sprintf(
730 "DELETE FROM lng_data " .
731 "WHERE module = %s AND identifier = %s AND lang_key = %s ",
732 $ilDB->quote($a_module,
"text"),
733 $ilDB->quote($a_identifier,
"text"),
734 $ilDB->quote($a_lang_key,
"text")
750 $ilDB = $DIC->database();
752 $query =
"UPDATE usr_pref SET " .
753 "value = " .
$ilDB->quote($this->lang_default,
"text") .
" " .
754 "WHERE keyword = " .
$ilDB->quote(
'language',
"text") .
" " .
755 "AND value = " .
$ilDB->quote($lang_key,
"text");
769 foreach ($content as
$key => $val) {
770 if (trim($val) ==
"<!-- language file start -->") {
771 return array_slice($content,
$key + 1);
801 include_once(
"./Services/Utilities/classes/class.ilStr.php");
803 if (!empty($scope)) {
804 if ($scope ==
'global') {
807 $scopeExtension =
'.' . $scope;
812 if ($scope ==
"local") {
813 $path = $this->cust_lang_path;
819 if (!is_dir(
$path)) {
820 $this->
ilias->raiseError(
"Directory not found: " .
$path, $this->
ilias->error_obj->MESSAGE);
826 $lang_file =
"ilias_" . $this->key .
".lang" . $scopeExtension;
829 if (!is_file($lang_file)) {
830 $this->
ilias->raiseError(
"File not found: " . $lang_file, $this->
ilias->error_obj->MESSAGE);
834 $content = $this->
cut_header(file($lang_file));
835 if ($content ===
false) {
836 $this->
ilias->raiseError(
"Wrong Header in " . $lang_file, $this->
ilias->error_obj->MESSAGE);
841 foreach ($content as
$key => $val) {
842 $separated = explode($this->separator, trim($val));
843 $num = count($separated);
847 $this->
ilias->raiseError(
"Wrong parameter count in " . $lang_file .
" in line $line (Value: $val)! Please check your language file!", $this->
ilias->error_obj->MESSAGE);
850 $this->
ilias->raiseError(
"Non UTF8 character found in " . $lang_file .
" in line $line (Value: $val)! Please check your language file!", $this->
ilias->error_obj->MESSAGE);
866 $ilDB = $DIC->database();
867 $lng = $DIC->language();
869 $set =
$ilDB->query(
"SELECT COUNT(*) cnt FROM usr_data ud JOIN usr_pref up" .
870 " ON ud.usr_id = up.usr_id " .
871 " WHERE up.value = " .
$ilDB->quote($a_lang,
"text") .
872 " AND up.keyword = " .
$ilDB->quote(
"language",
"text"));
873 $rec =
$ilDB->fetchAssoc($set);
876 if ($a_lang ==
$lng->lang_default) {
877 $set2 =
$ilDB->query(
"SELECT COUNT(*) cnt FROM usr_data ud LEFT JOIN usr_pref up" .
878 " ON (ud.usr_id = up.usr_id AND up.keyword = " .
$ilDB->quote(
"language",
"text") .
")" .
879 " WHERE up.value IS NULL ");
880 $rec2 =
$ilDB->fetchAssoc($set2);
883 return (
int) $rec[
"cnt"] + (int) $rec2[
"cnt"];
optimizeData()
optimizes the db-table langdata
static getPluginObject(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
isUserLanguage()
check if language is system language
static getInstalledLanguages()
Get the language objects of the installed languages.
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
static countUsers($a_lang)
Count number of users that use a language.
isInstalled()
Check language object status, and return true if language is installed.
insert($scope='')
insert language data from file into database
__construct($a_id=0, $a_call_by_reference=false)
Constructor.
setTitle($a_title)
set object title
if($modEnd===false) $module
getStatus()
get language status
uninstall()
uninstall current language
check($scope='')
Validate the logical structure of a lang file.
static _getLocalChangesByModule($a_key, $a_module)
Get the local changes of a language module.
static _deleteLangData($a_lang_key, $a_keep_local_change=false)
Delete languge data.
getLocalChanges($a_min_date="", $a_max_date="")
get locally changed language entries
isSystemLanguage()
check if language is system language
static deleteLangEntry($a_module, $a_identifier, $a_lang_key)
Delete lang entry.
refresh()
refresh current language
resetUserLanguage($lang_key)
search ILIAS for users which have selected '$lang_key' as their prefered language and reset them to d...
redirection script todo: (a better solution should control the processing via a xml file) ...
install($scope='')
install current language
flush($a_mode='all')
remove language data from database
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
static refreshAll()
Refresh all installed languages.
isLocal()
Check language object status, and return true if a local language file is installed.
setDescription($a_desc)
set object description
static updateLangEntry( $a_module, $a_identifier, $a_lang_key, $a_value, $a_local_change=null, $a_remarks=null)
Replace lang entry.
update()
update object in db
static _getLastLocalChange($a_key)
get the date of the last local change
static refreshPlugins($a_lang_keys=null)
static replaceLangEntry( $a_module, $a_identifier, $a_lang_key, $a_value, $a_local_change=null, $a_remarks=null)
Replace lang entry.
static getAllSlots()
Get all plugin slots.
static cut_header($content)
remove lang-file haeder information from '$content' This function seeks for a special keyword where t...
static isUtf8($a_str)
Check whether string is utf-8.