ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ilObjLanguage Class Reference

Class ilObjLanguage. More...

+ Inheritance diagram for ilObjLanguage:
+ Collaboration diagram for ilObjLanguage:

Public Member Functions

 __construct (int $a_id=0, bool $a_call_by_reference=false, ?LanguageFileDirectoryManager $language_file_directory_manager=null)
 Constructor. More...
 
 getKey ()
 get language key More...
 
 getStatus ()
 get language status More...
 
 isSystemLanguage ()
 check if language is system language More...
 
 isUserLanguage ()
 check if language is system language More...
 
 isInstalled ()
 Check language object status, and return true if language is installed. More...
 
 uninstall ()
 uninstall current language More...
 
 refresh ()
 refresh current language More...
 
 flush (string $a_mode="all")
 remove language data from database $a_mode "all" or "keep_local" More...
 
 getLocalChanges (string $a_min_date="", string $a_max_date="")
 get locally changed language entries More...
 
 insert ()
 insert language data from file into database, customizing included More...
 
 getModulesWithUnwrittenOverlay ()
 Modules whose PO/MO overlay could not be written or removed by the last operation (the database was written regardless). More...
 
 removeLocalChanges ()
 Reinstalls the language purely from the global/component files. More...
 
 resetUserLanguage (string $lang_key)
 search ILIAS for users which have selected '$lang_key' as their prefered language and reset them to default language (english). More...
 
 optimizeData ()
 optimizes the db-table langdata More...
 
 check (bool $shipped_only=false)
 Validate the logical structure of a lang file. More...
 
- Public Member Functions inherited from ilObject
 getObjectProperties ()
 
 flushObjectProperties ()
 
 withReferences ()
 determines whether objects are referenced or not (got ref ids or not) More...
 
 processAutoRating ()
 
 read ()
 
 getId ()
 
 setId (int $id)
 
 setRefId (int $ref_id)
 
 getRefId ()
 
 getType ()
 
 setType (string $type)
 
 getPresentationTitle ()
 get presentation title Normally same as title Overwritten for sessions More...
 
 getTitle ()
 
 getUntranslatedTitle ()
 Get untranslated object title WebDAV needs to access the untranslated title of an object. More...
 
 setTitle (string $title)
 
 getDescription ()
 
 setDescription (string $description)
 
 getLongDescription ()
 get object long description (stored in object_description) More...
 
 getImportId ()
 
 setImportId (string $import_id)
 
 setOfflineStatus (bool $status)
 
 getOfflineStatus ()
 
 supportsOfflineHandling ()
 
 getOwner ()
 
 getOwnerName ()
 get full name of object owner More...
 
 setOwner (int $usr_id)
 
 getCreateDate ()
 Get create date in YYYY-MM-DD HH-MM-SS format. More...
 
 getLastUpdateDate ()
 Get last update date in YYYY-MM-DD HH-MM-SS format. More...
 
 create ()
 note: title, description and type should be set when this function is called More...
 
 update ()
 
 MDUpdateListener (string $element)
 Metadata update listener. More...
 
 createMetaData ()
 
 updateMetaData ()
 
 deleteMetaData ()
 
 updateOwner ()
 update owner of object in db More...
 
 putInTree (int $parent_ref_id)
 maybe this method should be in tree object!? More...
 
 setPermissions (int $parent_ref_id)
 
 setParentRolePermissions (int $parent_ref_id)
 Initialize the permissions of parent roles (local roles of categories, global roles...) This method is overwritten in e.g. More...
 
 createReference ()
 creates reference for object More...
 
 countReferences ()
 
 delete ()
 delete object or referenced object (in the case of a referenced object, object data is only deleted if last reference is deleted) This function removes an object entirely from system!! More...
 
 initDefaultRoles ()
 init default roles settings Purpose of this function is to create a local role folder and local roles, that are needed depending on the object type. More...
 
 applyDidacticTemplate (int $tpl_id)
 
 getXMLZip ()
 
 getHTMLDirectory ()
 
 appendCopyInfo (int $target_id, int $copy_id, int $new_obj_id)
 Prepend Copy info if object with same name exists in that container. More...
 
 cloneDependencies (int $target_id, int $copy_id)
 Clone object dependencies. More...
 
 cloneMetaData (ilObject $target_obj)
 Copy meta data. More...
 
 selfOrParentWithRatingEnabled ()
 
 getPossibleSubObjects (bool $filter=true)
 get all possible sub objects of this type the object can decide which types of sub objects are possible jut in time overwrite if the decision distinguish from standard model More...
 

Static Public Member Functions

static getInstalledLanguages ()
 Get the language objects of the installed languages. More...
 
static getLangKeysOfInstalledLanguages ()
 Return the language keys of the installed languages. More...
 
static refreshPlugins (?array $a_lang_keys=null)
 Refresh languages of activated plugins $a_lang_keys keys of languages to be refreshed (not yet supported, all available will be refreshed) More...
 
static _deleteLangData (string $a_lang_key, bool $a_keep_local_change=false)
 Delete languge data $a_lang_key lang key. More...
 
static _getLastLocalChange (string $a_key)
 get the date of the last local change $a_key language key Return change_date "yyyy-mm-dd hh:mm:ss" More...
 
static _getLocalChangesByModule (string $a_key, string $a_module)
 Get the local changes of a language module. More...
 
static replaceLangModule (string $a_key, string $a_module, array $a_array, bool $refresh_original_from_shipped=false)
 Replace language module array. More...
 
static replaceLangEntry (string $a_module, string $a_identifier, string $a_lang_key, string $a_value, ?string $a_local_change=null, ?string $a_remarks=null)
 Replace lang entry. More...
 
static updateLangEntry (string $a_module, string $a_identifier, string $a_lang_key, string $a_value, ?string $a_local_change=null, ?string $a_remarks=null)
 Replace lang entry. More...
 
static deleteLangEntry (string $a_module, string $a_identifier, string $a_lang_key)
 Delete lang entry. More...
 
static cut_header (array $content)
 remove lang-file haeder information from '$content' This function seeks for a special keyword where the language information starts. More...
 
static countUsers (string $a_lang)
 Count number of users that use a language. More...
 
- Static Public Member Functions inherited from ilObject
static _lookupObjIdByImportId (string $import_id)
 Get (latest) object id for an import id. More...
 
static _lookupImportId (int $obj_id)
 
static _lookupOwnerName (int $owner_id)
 Lookup owner name for owner id. More...
 
static _getIdForImportId (string $import_id)
 
static _getAllReferences (int $id)
 get all reference ids for object ID More...
 
static _lookupTitle (int $obj_id)
 
static lookupOfflineStatus (int $obj_id)
 Lookup offline status using objectDataCache. More...
 
static _lookupOwner (int $obj_id)
 Lookup owner user ID for object ID. More...
 
static _getIdsForTitle (string $title, string $type='', bool $partial_match=false)
 
static _lookupDescription (int $obj_id)
 
static _lookupLastUpdate (int $obj_id, bool $formatted=false)
 
static _getLastUpdateOfObjects (array $obj_ids)
 
static _lookupObjId (int $ref_id)
 
static _setDeletedDate (int $ref_id, int $deleted_by)
 
static setDeletedDates (array $ref_ids, int $user_id)
 
static _resetDeletedDate (int $ref_id)
 
static _lookupDeletedDate (int $ref_id)
 
static _writeTitle (int $obj_id, string $title)
 write title to db (static) More...
 
static _writeDescription (int $obj_id, string $desc)
 write description to db (static) More...
 
static _writeImportId (int $obj_id, string $import_id)
 write import id to db (static) More...
 
static _lookupType (int $id, bool $reference=false)
 
static _isInTrash (int $ref_id)
 
static _hasUntrashedReference (int $obj_id)
 checks whether an object has at least one reference that is not in trash More...
 
static _lookupObjectId (int $ref_id)
 
static _getObjectsDataForType (string $type, bool $omit_trash=false)
 get all objects of a certain type More...
 
static _exists (int $id, bool $reference=false, ?string $type=null)
 checks if an object exists in object_data More...
 
static _getObjectsByType (string $obj_type="", ?int $owner=null)
 
static _prepareCloneSelection (array $ref_ids, string $new_type, bool $show_path=true)
 Prepare copy wizard object selection. More...
 
static getIconForType (string $type)
 
static _getIcon (int $obj_id=0, string $size="big", string $type="", bool $offline=false)
 Get icon for repository item. More...
 
static collectDeletionDependencies (array &$deps, int $ref_id, int $obj_id, string $type, int $depth=0)
 Collect deletion dependencies. More...
 
static getDeletionDependencies (int $obj_id)
 Get deletion dependencies. More...
 
static getLongDescriptions (array $obj_ids)
 
static getAllOwnedRepositoryObjects (int $user_id)
 
static fixMissingTitles ($type, array &$obj_title_map)
 Try to fix missing object titles. More...
 
static _lookupCreationDate (int $obj_id)
 
static _getObjectTypeIdByTitle (string $type, ?\ilDBInterface $ilDB=null)
 

Data Fields

string $separator
 separator of module, comment separator, identifier & values in language files More...
 
string $comment_separator
 
string $lang_default
 
string $lang_user
 
string $lang_path
 
string $key
 
string $status
 
string $cust_lang_path
 
string $absolute_path
 
- Data Fields inherited from ilObject
const TITLE_LENGTH = 255
 
const DESC_LENGTH = 128
 
const LONG_DESC_LENGTH = 4000
 
const TABLE_OBJECT_DATA = "object_data"
 
array $objectList
 
string $untranslatedTitle
 

Static Private Member Functions

static writeLangModule (string $a_key, string $a_module, array $a_array, bool $refresh_original_from_shipped)
 
static syncMigratedLanguageFile (string $a_key, string $a_module, array $a_array, bool $refresh_original_from_shipped=false)
 Mirrors the complete $a_array into the overlay with "replace" semantics (entries no longer in it are removed). More...
 

Private Attributes

LanguageFileDirectoryManager $language_file_directory_manager
 
InstalledLanguageRepository $repository
 
LanguageInstallationManager $manager
 
array $modules_with_unwritten_overlay = []
 

Additional Inherited Members

- Protected Member Functions inherited from ilObject
 doMDUpdateListener (string $a_element)
 
 beforeMDUpdateListener (string $a_element)
 
 doCreateMetaData ()
 
 beforeCreateMetaData ()
 
 doUpdateMetaData ()
 
 beforeUpdateMetaData ()
 
 doDeleteMetaData ()
 
 beforeDeleteMetaData ()
 
 handleAutoRating ()
 
 hasAutoRating ()
 
- Protected Attributes inherited from ilObject
ilLogger $obj_log
 
ILIAS $ilias
 
ilObjectDefinition $obj_definition
 
ilDBInterface $db
 
ilLogger $log
 
ilErrorHandling $error
 
ilTree $tree
 
ilAppEventHandler $app_event_handler
 
ilRbacAdmin $rbac_admin
 
ilRbacReview $rbac_review
 
ilObjUser $user
 
ilLanguage $lng
 
LOMServices $lom_services
 
bool $call_by_reference
 
int $max_title = self::TITLE_LENGTH
 
int $max_desc = self::DESC_LENGTH
 
bool $add_dots = true
 
int $ref_id = null
 
string $type = ""
 
string $title = ""
 
string $desc = ""
 
string $long_desc = ""
 
int $owner = 0
 
string $create_date = ""
 
string $last_update = ""
 
string $import_id = ""
 
bool $register = false
 

Detailed Description

Class ilObjLanguage.

Author
Sascha Hofmann shofm.nosp@m.ann@.nosp@m.datab.nosp@m.ay.d.nosp@m.e
Version
$Id$

Definition at line 40 of file class.ilObjLanguage.php.

Constructor & Destructor Documentation

◆ __construct()

ilObjLanguage::__construct ( int  $a_id = 0,
bool  $a_call_by_reference = false,
?LanguageFileDirectoryManager  $language_file_directory_manager = null 
)

Constructor.

$a_id reference_id or object_id $a_call_by_reference treat the id as reference_id (true) or object_id (false)

Definition at line 67 of file class.ilObjLanguage.php.

71 {
72 global $DIC;
73 $lng = $DIC->language();
74
75 // the first constructor argument is the customizing directory, not a global one
76 $this->language_file_directory_manager = $language_file_directory_manager
77 ?? ($DIC[LanguageFileDirectoryManager::class] ?? null)
79
80 $this->type = "lng";
81 parent::__construct($a_id, $a_call_by_reference);
82
83 $this->type = "lng";
84 $this->key = $this->title;
85 $this->status = $this->desc;
86 $this->lang_default = $lng->lang_default;
87 $this->lang_user = $lng->lang_user;
88 $this->lang_path = $lng->lang_path;
89 $this->cust_lang_path = $lng->getCustomLangPath();
90 $this->separator = $lng->separator;
91 $this->comment_separator = $lng->comment_separator;
92 $this->absolute_path = (string) realpath(__DIR__ . "/../../../../");
93
95 $DIC->database(),
96 $this->language_file_directory_manager,
97 new FixedInstallationRoot($this->absolute_path)
98 );
99 $this->manager = new LanguageInstallationManager(
100 $DIC->database(),
101 $this->language_file_directory_manager,
102 $this->absolute_path,
103 $this->repository,
104 null,
106 fn(): ?string => MigratedLanguageFilePaths::resolveClientDataDir($this->absolute_path)
107 );
108 }
A root determined by the caller, for the classes which are not wired by the component bootstrap.
Write access to the language installation: installing, flushing and registering languages in the data...
Delegates to ilCachedLanguage at call time, so it can be built at build time without the global cache...
LanguageFileDirectoryManager $language_file_directory_manager
string $desc
string $title
ilLanguage $lng
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26

References ilObject\$desc, $DIC, $language_file_directory_manager, ilObject\$lng, ilObject\$title, ILIAS\GlobalScreen\Provider\__construct(), ilLanguage\getCustomLangPath(), and ILIAS\UI\examples\Deck\repository().

+ Here is the call graph for this function:

Member Function Documentation

◆ _deleteLangData()

static ilObjLanguage::_deleteLangData ( string  $a_lang_key,
bool  $a_keep_local_change = false 
)
static

Delete languge data $a_lang_key lang key.

Definition at line 315 of file class.ilObjLanguage.php.

315 : void
316 {
317 global $DIC;
318 $ilDB = $DIC->database();
319
320 if (!$a_keep_local_change) {
321 $ilDB->manipulate("DELETE FROM lng_data WHERE lang_key = " .
322 $ilDB->quote($a_lang_key, "text"));
323 } else {
324 $ilDB->manipulate("DELETE FROM lng_data WHERE lang_key = " .
325 $ilDB->quote($a_lang_key, "text") .
326 " AND local_change IS NULL");
327 }
328 }

References $DIC, and $ilDB.

Referenced by flush().

+ Here is the caller graph for this function:

◆ _getLastLocalChange()

static ilObjLanguage::_getLastLocalChange ( string  $a_key)
static

get the date of the last local change $a_key language key Return change_date "yyyy-mm-dd hh:mm:ss"

Definition at line 392 of file class.ilObjLanguage.php.

392 : string
393 {
394 global $DIC;
395 $ilDB = $DIC->database();
396
397 $q = sprintf(
398 "SELECT MAX(local_change) last_change FROM lng_data " .
399 "WHERE lang_key = %s AND local_change IS NOT NULL",
400 $ilDB->quote($a_key, "text")
401 );
402 $result = $ilDB->query($q);
403
404 $db_last_change = null;
405 if (($row = $result->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) && $row["last_change"] !== null) {
406 $db_last_change = (string) $row["last_change"];
407 }
408
409 // a migrated module's overlay .po can carry a local_change lng_data never sees; the more recent one wins
410 $po_last_change = self::_getLastMigratedLocalChange($a_key);
411
412 return match (true) {
413 $db_last_change === null && $po_last_change === null => "",
414 $db_last_change === null => $po_last_change,
415 $po_last_change === null => $db_last_change,
416 default => max($db_last_change, $po_last_change),
417 };
418 }
const FETCHMODE_ASSOC

References $DIC, $ilDB, and ilDBConstants\FETCHMODE_ASSOC.

Referenced by ilObjLanguageFolderGUI\buildConfirmModal(), ilLanguageFolderTable\getRows(), PoLastLocalChangeTest\testDbValueWinsWhenItIsLaterThanThePoValue(), PoLastLocalChangeTest\testPoValueWinsWhenItIsLaterThanTheDbValue(), PoLastLocalChangeTest\testReturnsEmptyStringWhenNeitherSourceHasAnyLocalChange(), and PoLastLocalChangeTest\testReturnsTheDbValueUnchangedWhenNoMigratedModuleContributesAnything().

+ Here is the caller graph for this function:

◆ _getLocalChangesByModule()

static ilObjLanguage::_getLocalChangesByModule ( string  $a_key,
string  $a_module 
)
static

Get the local changes of a language module.

Reads lng_data only, same caveat as getLocalChanges(). Used by ilPluginLanguage::updateLanguages() to preserve local changes across an update.

$a_key Language key $a_module Module key Return array identifier => value

Definition at line 480 of file class.ilObjLanguage.php.

480 : array
481 {
482 global $DIC;
483 $ilDB = $DIC->database();
484
485 $changes = array();
486 $result = $ilDB->queryF(
487 "SELECT identifier, value FROM lng_data WHERE lang_key = %s AND module = %s AND local_change IS NOT NULL",
488 array("text", "text"),
489 array($a_key, $a_module)
490 );
491
492 while ($row = $ilDB->fetchAssoc($result)) {
493 $changes[$row["identifier"]] = $row["value"];
494 }
495 return $changes;
496 }

References $DIC, and $ilDB.

Referenced by ilPluginLanguage\updateLanguages().

+ Here is the caller graph for this function:

◆ check()

ilObjLanguage::check ( bool  $shipped_only = false)

Validate the logical structure of a lang file.

This function checks if a lang file exists, the file has a header, and each lang-entry consists of exactly three elements (module, identifier, value).

$shipped_only all but the customizing directory (see removeLocalChanges())

Delegates to InstalledLanguageRepository; callers (e.g. ilObjLanguageFolderGUI) turn a false into user feedback.

Definition at line 845 of file class.ilObjLanguage.php.

845 : bool
846 {
847 if ($shipped_only && $this->repository instanceof InstalledLanguageDatabaseRepository) {
848 return $this->repository->checkShippedLanguage($this->key);
849 }
850
851 return $this->repository->checkLanguage($this->key);
852 }

References ILIAS\UI\examples\Deck\repository().

Referenced by refresh(), and removeLocalChanges().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ countUsers()

static ilObjLanguage::countUsers ( string  $a_lang)
static

Count number of users that use a language.

Definition at line 857 of file class.ilObjLanguage.php.

857 : int
858 {
859 global $DIC;
860 $ilDB = $DIC->database();
861 $lng = $DIC->language();
862
863 $set = $ilDB->query("SELECT COUNT(*) cnt FROM usr_data ud JOIN usr_pref up" .
864 " ON ud.usr_id = up.usr_id " .
865 " WHERE up.value = " . $ilDB->quote($a_lang, "text") .
866 " AND up.keyword = " . $ilDB->quote("language", "text"));
867 $rec = $ilDB->fetchAssoc($set);
868
869 // add users with no usr_pref set to default language
870 if ($a_lang == $lng->lang_default) {
871 $set2 = $ilDB->query("SELECT COUNT(*) cnt FROM usr_data ud LEFT JOIN usr_pref up" .
872 " ON (ud.usr_id = up.usr_id AND up.keyword = " . $ilDB->quote("language", "text") . ")" .
873 " WHERE up.value IS NULL ");
874 $rec2 = $ilDB->fetchAssoc($set2);
875 }
876
877 return (int) $rec["cnt"] + (int) ($rec2["cnt"] ?? 0);
878 }

References $DIC, $ilDB, $lng, and ILIAS\Repository\int().

Referenced by ilLanguageFolderTable\getRows(), and ILIAS\Dashboard\DataRetrieval\Language\getRows().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cut_header()

static ilObjLanguage::cut_header ( array  $content)
static

remove lang-file haeder information from '$content' This function seeks for a special keyword where the language information starts.

if found it returns the plain language information, otherwise returns false

$content expecting an ILIAS lang-file Return content without header info OR false if no valid header was found

Returns
bool|array

Definition at line 812 of file class.ilObjLanguage.php.

813 {
814 foreach ($content as $key => $val) {
815 if (trim($val) === "<!-- language file start -->") {
816 return array_slice($content, $key + 1);
817 }
818 }
819
820 return false;
821 }

Referenced by ilObjLanguageFolder\checkAllLanguages().

+ Here is the caller graph for this function:

◆ deleteLangEntry()

static ilObjLanguage::deleteLangEntry ( string  $a_module,
string  $a_identifier,
string  $a_lang_key 
)
staticfinal

Delete lang entry.

Definition at line 768 of file class.ilObjLanguage.php.

768 : bool
769 {
770 global $DIC;
771 $ilDB = $DIC->database();
772
773 $ilDB->manipulate(sprintf(
774 "DELETE FROM lng_data " .
775 "WHERE module = %s AND identifier = %s AND lang_key = %s ",
776 $ilDB->quote($a_module, "text"),
777 $ilDB->quote($a_identifier, "text"),
778 $ilDB->quote($a_lang_key, "text")
779 ));
780
781 return true;
782 }

References $DIC, and $ilDB.

Referenced by ilObjLanguageExt\_deleteValues().

+ Here is the caller graph for this function:

◆ flush()

ilObjLanguage::flush ( string  $a_mode = "all")

remove language data from database $a_mode "all" or "keep_local"

Definition at line 334 of file class.ilObjLanguage.php.

334 : void
335 {
336 global $DIC;
337 $ilDB = $DIC->database();
338
339 self::_deleteLangData($this->key, ($a_mode === "keep_local"));
340
341 if ($a_mode === "all") {
342 $ilDB->manipulate("DELETE FROM lng_modules WHERE lang_key = " .
343 $ilDB->quote($this->key, "text"));
344 }
345 }
static _deleteLangData(string $a_lang_key, bool $a_keep_local_change=false)
Delete languge data $a_lang_key lang key.

References $DIC, $ilDB, and _deleteLangData().

Referenced by refresh(), removeLocalChanges(), and uninstall().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInstalledLanguages()

static ilObjLanguage::getInstalledLanguages ( )
static

Get the language objects of the installed languages.

Definition at line 114 of file class.ilObjLanguage.php.

114 : array
115 {
116 $objects = array();
117 $languages = ilObject::_getObjectsByType("lng");
118 foreach ($languages as $lang) {
119 $langObj = new ilObjLanguage((int) $lang["obj_id"], false);
120 if ($langObj->isInstalled()) {
121 $objects[] = $langObj;
122 } else {
123 unset($langObj);
124 }
125 }
126 return $objects;
127 }
Class ilObjLanguage.
static _getObjectsByType(string $obj_type="", ?int $owner=null)

References ilObject\_getObjectsByType().

+ Here is the call graph for this function:

◆ getKey()

ilObjLanguage::getKey ( )

get language key

Return language key

Definition at line 155 of file class.ilObjLanguage.php.

155 : string
156 {
157 return $this->key;
158 }

References $key.

Referenced by refresh(), and removeLocalChanges().

+ Here is the caller graph for this function:

◆ getLangKeysOfInstalledLanguages()

static ilObjLanguage::getLangKeysOfInstalledLanguages ( )
static

Return the language keys of the installed languages.

Matches only "installed", not "installed_local" (unlike ilLanguage::_getInstalledLanguages()); this affects ilPluginLanguage's language selection.

Returns
array

Definition at line 138 of file class.ilObjLanguage.php.

138 : array
139 {
140 $lang_keys = [];
141 foreach (ilObject::_getObjectsByType("lng") as $lang) {
142 if ($lang['desc'] === 'installed') {
143 $lang_keys[] = $lang['title'];
144 }
145 }
146 return $lang_keys;
147 }

References ilObject\_getObjectsByType().

Referenced by ilPluginLanguage\updateLanguages().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLocalChanges()

ilObjLanguage::getLocalChanges ( string  $a_min_date = "",
string  $a_max_date = "" 
)

get locally changed language entries

Reads lng_data only, not merged with the overlay (unlike _getLastLocalChange()): correct only while lng_data is dual-written for migrated modules (see replaceLangModule()).

$a_min_date minimum change date "yyyy-mm-dd hh:mm:ss" $a_max_date maximum change date "yyyy-mm-dd hh:mm:ss" Return array [module][identifier] => value

Definition at line 358 of file class.ilObjLanguage.php.

358 : array
359 {
360 global $DIC;
361 $ilDB = $DIC->database();
362
363 if ($a_min_date === "") {
364 $a_min_date = "1980-01-01 00:00:00";
365 }
366 if ($a_max_date === "") {
367 $a_max_date = "2200-01-01 00:00:00";
368 }
369
370 $q = sprintf(
371 "SELECT module, identifier, value FROM lng_data WHERE lang_key = %s " .
372 "AND local_change >= %s AND local_change <= %s",
373 $ilDB->quote($this->key, "text"),
374 $ilDB->quote($a_min_date, "timestamp"),
375 $ilDB->quote($a_max_date, "timestamp")
376 );
377 $result = $ilDB->query($q);
378
379 $changes = array();
380 while ($row = $result->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
381 $changes[$row["module"]][$row["identifier"]] = $row["value"];
382 }
383 return $changes;
384 }

References $DIC, $ilDB, and ilDBConstants\FETCHMODE_ASSOC.

◆ getModulesWithUnwrittenOverlay()

ilObjLanguage::getModulesWithUnwrittenOverlay ( )

Modules whose PO/MO overlay could not be written or removed by the last operation (the database was written regardless).

Returns
list<string>

Definition at line 513 of file class.ilObjLanguage.php.

513 : array
514 {
516 }
array $modules_with_unwritten_overlay

References $modules_with_unwritten_overlay.

◆ getStatus()

ilObjLanguage::getStatus ( )

get language status

Return language status

Definition at line 165 of file class.ilObjLanguage.php.

165 : string
166 {
167 return $this->status;
168 }

References $status.

Referenced by isInstalled(), and refresh().

+ Here is the caller graph for this function:

◆ insert()

ilObjLanguage::insert ( )

insert language data from file into database, customizing included

Definition at line 502 of file class.ilObjLanguage.php.

502 : void
503 {
504 $this->modules_with_unwritten_overlay = $this->manager->insertLanguageForInstallation($this->key);
505 }

Referenced by refresh().

+ Here is the caller graph for this function:

◆ isInstalled()

ilObjLanguage::isInstalled ( )

Check language object status, and return true if language is installed.

Return true if installed

Definition at line 199 of file class.ilObjLanguage.php.

199 : bool
200 {
201 if (str_starts_with($this->getStatus(), "installed")) {
202 return true;
203 } else {
204 return false;
205 }
206 }
getStatus()
get language status

References getStatus().

Referenced by refresh(), removeLocalChanges(), and ilObjLanguageExt\setLocal().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isSystemLanguage()

ilObjLanguage::isSystemLanguage ( )

check if language is system language

Definition at line 173 of file class.ilObjLanguage.php.

173 : bool
174 {
175 if ($this->key == $this->lang_default) {
176 return true;
177 } else {
178 return false;
179 }
180 }

◆ isUserLanguage()

ilObjLanguage::isUserLanguage ( )

check if language is system language

Definition at line 185 of file class.ilObjLanguage.php.

185 : bool
186 {
187 if ($this->key == $this->lang_user) {
188 return true;
189 } else {
190 return false;
191 }
192 }

◆ optimizeData()

ilObjLanguage::optimizeData ( )

optimizes the db-table langdata

Return true on success

Deprecated:

Definition at line 829 of file class.ilObjLanguage.php.

829 : bool
830 {
831 // Mantis #22313: removed table optimization
832 return true;
833 }

◆ refresh()

ilObjLanguage::refresh ( )

refresh current language

A single insert() covers global and local/customizing content.

Definition at line 277 of file class.ilObjLanguage.php.

277 : bool
278 {
279 if ($this->isInstalled() && $this->check()) {
280 $this->flush("keep_local");
281 $this->insert();
282 $this->setTitle($this->getKey());
283 $this->setDescription($this->getStatus());
284 $this->update();
285
286 return true;
287 }
288
289 return false;
290 }
flush(string $a_mode="all")
remove language data from database $a_mode "all" or "keep_local"
isInstalled()
Check language object status, and return true if language is installed.
getKey()
get language key
insert()
insert language data from file into database, customizing included
check(bool $shipped_only=false)
Validate the logical structure of a lang file.
setTitle(string $title)
setDescription(string $description)

References check(), flush(), getKey(), getStatus(), insert(), isInstalled(), ilObject\setDescription(), ilObject\setTitle(), and ilObject\update().

+ Here is the call graph for this function:

◆ refreshPlugins()

static ilObjLanguage::refreshPlugins ( ?array  $a_lang_keys = null)
static

Refresh languages of activated plugins $a_lang_keys keys of languages to be refreshed (not yet supported, all available will be refreshed)

Definition at line 296 of file class.ilObjLanguage.php.

296 : void
297 {
298 global $DIC;
299
300 $component_repository = $DIC["component.repository"];
301 foreach ($component_repository->getPlugins() as $plugin) {
302 if (!$plugin->isActive()) {
303 continue;
304 }
306 $handler->updateLanguages($a_lang_keys);
307 }
308 }
$handler
Definition: oai.php:31

References $DIC, $handler, and XapiProxy\$plugin.

Referenced by ILIAS\Language\Activities\RepositoryProvider\refreshPlugins().

+ Here is the caller graph for this function:

◆ removeLocalChanges()

ilObjLanguage::removeLocalChanges ( )

Reinstalls the language purely from the global/component files.

Must not use insert(): that merges the customizing directory back in and would reinstate what this method removes.

Return true if the language was installed and could be reinstalled

Definition at line 524 of file class.ilObjLanguage.php.

524 : bool
525 {
526 // The customizing file is not applied here - an invalid one must not block the reset
527 if (!$this->isInstalled() || !$this->check(true)) {
528 return false;
529 }
530
531 $this->flush("all");
532 $this->modules_with_unwritten_overlay = $this->manager->insertLanguageForRemovingLocalChanges($this->key);
533 $this->setTitle($this->getKey());
534 $this->setDescription("installed");
535 $this->update();
536
537 return true;
538 }

References check(), flush(), getKey(), isInstalled(), ilObject\setDescription(), ilObject\setTitle(), and ilObject\update().

+ Here is the call graph for this function:

◆ replaceLangEntry()

static ilObjLanguage::replaceLangEntry ( string  $a_module,
string  $a_identifier,
string  $a_lang_key,
string  $a_value,
?string  $a_local_change = null,
?string  $a_remarks = null 
)
staticfinal

Replace lang entry.

Definition at line 679 of file class.ilObjLanguage.php.

686 : bool {
687 global $DIC;
688 $ilDB = $DIC->database();
689
690 // avoid a cache flush here (see mantis #28818)
691 // ilGlobalCache::flushAll();
692
693 if (is_string($a_remarks) && $a_remarks !== '') {
694 $a_remarks = mb_substr($a_remarks, 0, 250);
695 }
696
697 if ($a_remarks === '') {
698 $a_remarks = null;
699 }
700
701 if ($a_value === "") {
702 $a_value = null;
703 } else {
704 $a_value = substr($a_value, 0, 4000);
705 }
706
707 $ilDB->replace(
708 "lng_data",
709 array(
710 "module" => array("text",$a_module),
711 "identifier" => array("text",$a_identifier),
712 "lang_key" => array("text",$a_lang_key)
713 ),
714 array(
715 "value" => array("text",$a_value),
716 "local_change" => array("timestamp",$a_local_change),
717 "remarks" => array("text", $a_remarks)
718 )
719 );
720 return true;
721 }

Referenced by ilPluginLanguage\updateLanguages().

+ Here is the caller graph for this function:

◆ replaceLangModule()

static ilObjLanguage::replaceLangModule ( string  $a_key,
string  $a_module,
array  $a_array,
bool  $refresh_original_from_shipped = false 
)
staticfinal

Replace language module array.

Central write path for module data (admin GUI edits, local-change delete, plugin update): rewrites the lng_modules row and dual-writes the same content into the overlay of a migrated module (see syncMigratedLanguageFile()). lng_data/lng_modules stay the rollback-safe source of truth while the PO/MO pilot runs.

Final: the signature only carries identifier => value, no per-entry reason text (unlike replaceLangEntry()'s $a_remarks); do not widen it.

Parameters
bool$refresh_original_from_shippedforwarded to MigratedLanguageFileSync::sync(); true only where $a_array reflects the current SHIPPED content (module reset, plugin language file re-applied)
Returns
bool false if the database was written but the overlay of a module maintained in PO files could not be

Definition at line 554 of file class.ilObjLanguage.php.

559 : bool {
560 global $DIC;
561
562 // DB write and overlay sync form one unit under the lock, also against a caller's read of the current content (see ilObjLanguageExt::_saveValues())
563 return MigratedLanguageFileSync::withOverlayLock(
564 $DIC->offsetExists(LanguageFileDirectoryManager::class) ? $DIC[LanguageFileDirectoryManager::class] : null,
565 $a_key,
566 $a_module,
567 MigratedLanguageFilePaths::resolveClientDataDir(ILIAS_ABSOLUTE_PATH),
568 static fn(): bool => self::writeLangModule($a_key, $a_module, $a_array, $refresh_original_from_shipped),
569 ILIAS_ABSOLUTE_PATH
570 );
571 }

Referenced by ilObjLanguageExt\_deleteValues(), PoMigrationWriteBackTest\testAddsANewEntryThatDidNotExistInTheFileBefore(), PoMigrationWriteBackTest\testANewEntryWithNoOriginalCommentIsAlwaysMarkedAsLocallyChanged(), PoMigrationWriteBackTest\testAnUnmodifiedShippedValueWithDisallowedMarkupIsSanitisedInTheDatabaseButNotInTheOverlay(), PoMigrationWriteBackTest\testInvalidatesIlLanguagesCacheSoTheNewValueIsVisibleImmediately(), PoMigrationWriteBackTest\testIsANoOpWhenNoDirectoryManagerIsRegisteredAtAll(), PoMigrationWriteBackTest\testIsANoOpWhenTheModuleHasNoContributedDirectory(), PoMigrationWriteBackTest\testRecompilesAMissingOverlayMoOnTheNextEdit(), PoMigrationWriteBackTest\testRemovesAnEntryThatIsNoLongerInTheReplacedArray(), ImportUsesShippedValuesOfMigratedModulesTest\testReplaceLangModuleReturnsFalseOnlyForAMigratedModuleWhoseOverlayCouldNotBeWritten(), PoMigrationWriteBackTest\testUpdatesAnExistingEntryAndClearsItsFuzzyFlag(), PoMigrationWriteBackTest\testWritingADifferentValueThanTheOriginalSetsALocalChangeTimestamp(), PoMigrationWriteBackTest\testWritingBackTheOriginalValueClearsAnExistingLocalChangeTimestamp(), ilPluginLanguage\updateLanguages(), and ILIAS\Language\Activities\RepositoryProvider\updateModuleCache().

+ Here is the caller graph for this function:

◆ resetUserLanguage()

ilObjLanguage::resetUserLanguage ( string  $lang_key)

search ILIAS for users which have selected '$lang_key' as their prefered language and reset them to default language (english).

A message is sent to all affected users

$lang_key international language key (2 digits)

Definition at line 791 of file class.ilObjLanguage.php.

791 : void
792 {
793 global $DIC;
794 $ilDB = $DIC->database();
795
796 $query = "UPDATE usr_pref SET " .
797 "value = " . $ilDB->quote($this->lang_default, "text") . " " .
798 "WHERE keyword = " . $ilDB->quote('language', "text") . " " .
799 "AND value = " . $ilDB->quote($lang_key, "text");
800 $ilDB->manipulate($query);
801 }

References $DIC, and $ilDB.

Referenced by uninstall().

+ Here is the caller graph for this function:

◆ syncMigratedLanguageFile()

static ilObjLanguage::syncMigratedLanguageFile ( string  $a_key,
string  $a_module,
array  $a_array,
bool  $refresh_original_from_shipped = false 
)
staticprivate

Mirrors the complete $a_array into the overlay with "replace" semantics (entries no longer in it are removed).

No-op for a module that is not migrated for $a_key. Failures are logged and signalled by false, not thrown: the DB write already succeeded and must not be undone (e.g. data directory not writable).

Definition at line 641 of file class.ilObjLanguage.php.

646 : bool {
647 global $DIC;
648
649 if (!$DIC->offsetExists(LanguageFileDirectoryManager::class)) {
650 return true;
651 }
652
653 try {
654 MigratedLanguageFileSync::sync(
655 $DIC[LanguageFileDirectoryManager::class],
656 ILIAS_ABSOLUTE_PATH,
657 $a_key,
658 $a_module,
659 $a_array,
660 MigratedLanguageFilePaths::resolveClientDataDir(ILIAS_ABSOLUTE_PATH),
661 $refresh_original_from_shipped
662 );
663 } catch (\Throwable $t) {
664 $DIC->logger()->forComponent('lang')->warning(sprintf(
665 'Could not sync migrated language file for module "%s", language "%s": %s',
666 $a_module,
667 $a_key,
668 $t->getMessage()
669 ));
670 return false;
671 }
672
673 return true;
674 }

◆ uninstall()

ilObjLanguage::uninstall ( )

uninstall current language

Return uninstalled language key

Definition at line 213 of file class.ilObjLanguage.php.

213 : string
214 {
215 if ((str_starts_with($this->status, "installed")) && ($this->key != $this->lang_default) && ($this->key != $this->lang_user)) {
216 $this->flush();
217 $this->modules_with_unwritten_overlay = self::removeMigratedMoFiles($this->key);
218 $this->setTitle($this->key);
219 $this->setDescription("not_installed");
220 $this->update();
221 $this->resetUserLanguage($this->key);
222
223 return $this->key;
224 }
225 return "";
226 }
resetUserLanguage(string $lang_key)
search ILIAS for users which have selected '$lang_key' as their prefered language and reset them to d...

References $key, flush(), resetUserLanguage(), ilObject\setDescription(), ilObject\setTitle(), and ilObject\update().

+ Here is the call graph for this function:

◆ updateLangEntry()

static ilObjLanguage::updateLangEntry ( string  $a_module,
string  $a_identifier,
string  $a_lang_key,
string  $a_value,
?string  $a_local_change = null,
?string  $a_remarks = null 
)
staticfinal

Replace lang entry.

Definition at line 726 of file class.ilObjLanguage.php.

733 : void {
734 global $DIC;
735 $ilDB = $DIC->database();
736
737 if (is_string($a_remarks) && $a_remarks !== '') {
738 $a_remarks = mb_substr($a_remarks, 0, 250);
739 }
740
741 if ($a_remarks === '') {
742 $a_remarks = null;
743 }
744
745 if ($a_value === "") {
746 $a_value = null;
747 } else {
748 $a_value = substr($a_value, 0, 4000);
749 }
750
751 $ilDB->manipulate(sprintf(
752 "UPDATE lng_data " .
753 "SET value = %s, local_change = %s, remarks = %s " .
754 "WHERE module = %s AND identifier = %s AND lang_key = %s ",
755 $ilDB->quote($a_value, "text"),
756 $ilDB->quote($a_local_change, "timestamp"),
757 $ilDB->quote($a_remarks, "text"),
758 $ilDB->quote($a_module, "text"),
759 $ilDB->quote($a_identifier, "text"),
760 $ilDB->quote($a_lang_key, "text")
761 ));
762 }

◆ writeLangModule()

static ilObjLanguage::writeLangModule ( string  $a_key,
string  $a_module,
array  $a_array,
bool  $refresh_original_from_shipped 
)
staticprivate

Definition at line 573 of file class.ilObjLanguage.php.

578 : bool {
579 global $DIC;
580 $ilDB = $DIC->database();
581
582 // avoid flushing the whole cache (see mantis #28818)
583 ilCachedLanguage::getInstance($a_key)->deleteInCache();
584
585 $ilDB->manipulate(sprintf(
586 "DELETE FROM lng_modules WHERE lang_key = %s AND module = %s",
587 $ilDB->quote($a_key, "text"),
588 $ilDB->quote($a_module, "text")
589 ));
590
591 /*$ilDB->manipulate(sprintf("INSERT INTO lng_modules (lang_key, module, lang_array) VALUES ".
592 "(%s,%s,%s)", $ilDB->quote($a_key, "text"),
593 $ilDB->quote($a_module, "text"),
594 $ilDB->quote(serialize($a_array), "clob")));*/
595 // a migrated module's shipped values as the build serves them; $a_array stays unprocessed for the overlay sync
596 $db_array = $DIC->offsetExists(LanguageFileDirectoryManager::class)
597 ? MigratedLanguageFileSync::databaseValuesOf(
598 $DIC[LanguageFileDirectoryManager::class],
599 ILIAS_ABSOLUTE_PATH,
600 $a_key,
601 $a_module,
602 $a_array
603 )
604 : $a_array;
605 $ilDB->insert("lng_modules", array(
606 "lang_key" => array("text", $a_key),
607 "module" => array("text", $a_module),
608 "lang_array" => array("clob", serialize($db_array))
609 ));
610
611 // check if the module is correctly saved
612 // see mantis #20046 and #19140
613 $result = $ilDB->queryF(
614 "SELECT lang_array FROM lng_modules WHERE lang_key = %s AND module = %s",
615 array("text","text"),
616 array($a_key, $a_module)
617 );
618 $row = $ilDB->fetchAssoc($result);
619
620 $unserialied = unserialize($row["lang_array"], ["allowed_classes" => false]);
621 if (!is_array($unserialied)) {
622 $escape = $DIC->refinery()->encode()->htmlSpecialCharsAsEntities();
623 $DIC->ui()->mainTemplate()->setOnScreenMessage(
624 'failure',
625 "Data for module '" . $escape->transform($a_module) . "' of language '" . $escape->transform($a_key) . "' is not correctly saved. " .
626 "Please check the collation of your database tables lng_data and lng_modules. It must be utf8_unicode_ci.",
627 true
628 );
629 // redirectByClass() exits inside the overlay lock callback: the flock() is released at request end, acceptable here
630 $DIC->ctrl()->redirectByClass(ilobjlanguagefoldergui::class, 'view');
631 }
632
633 return self::syncMigratedLanguageFile($a_key, $a_module, $a_array, $refresh_original_from_shipped);
634 }
static syncMigratedLanguageFile(string $a_key, string $a_module, array $a_array, bool $refresh_original_from_shipped=false)
Mirrors the complete $a_array into the overlay with "replace" semantics (entries no longer in it are ...

Field Documentation

◆ $absolute_path

string ilObjLanguage::$absolute_path

Definition at line 54 of file class.ilObjLanguage.php.

◆ $comment_separator

string ilObjLanguage::$comment_separator

Definition at line 47 of file class.ilObjLanguage.php.

◆ $cust_lang_path

string ilObjLanguage::$cust_lang_path

Definition at line 53 of file class.ilObjLanguage.php.

Referenced by ilObjLanguageExt\getCustLangPath().

◆ $key

◆ $lang_default

string ilObjLanguage::$lang_default

Definition at line 48 of file class.ilObjLanguage.php.

◆ $lang_path

string ilObjLanguage::$lang_path

Definition at line 50 of file class.ilObjLanguage.php.

Referenced by ilObjLanguageExt\getLangPath().

◆ $lang_user

string ilObjLanguage::$lang_user

Definition at line 49 of file class.ilObjLanguage.php.

◆ $language_file_directory_manager

LanguageFileDirectoryManager ilObjLanguage::$language_file_directory_manager
private

Definition at line 55 of file class.ilObjLanguage.php.

Referenced by __construct().

◆ $manager

LanguageInstallationManager ilObjLanguage::$manager
private

Definition at line 57 of file class.ilObjLanguage.php.

◆ $modules_with_unwritten_overlay

array ilObjLanguage::$modules_with_unwritten_overlay = []
private

Definition at line 59 of file class.ilObjLanguage.php.

Referenced by getModulesWithUnwrittenOverlay().

◆ $repository

InstalledLanguageRepository ilObjLanguage::$repository
private

Definition at line 56 of file class.ilObjLanguage.php.

◆ $separator

string ilObjLanguage::$separator

separator of module, comment separator, identifier & values in language files

Definition at line 46 of file class.ilObjLanguage.php.

◆ $status

string ilObjLanguage::$status

Definition at line 52 of file class.ilObjLanguage.php.

Referenced by getStatus().


The documentation for this class was generated from the following file: