Skip to content

Commit

Permalink
Add function to load plugin lang from file name - refs BT#16742
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Nov 27, 2020
1 parent 688dd4f commit 2423c1c
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions main/inc/lib/plugin.class.php
Expand Up @@ -456,6 +456,37 @@ public function get_lang($name)
return get_lang($name);
}

/**
* @param string $variable
* @param string $language
*
* @return string
*/
public function getLangFromFile($variable, $language)
{
static $langStrings = [];

if (empty($langStrings[$language])) {
$root = api_get_path(SYS_PLUGIN_PATH);
$pluginName = $this->get_name();

$englishPath = "$root$pluginName/lang/$language.php";

if (is_readable($englishPath)) {
$strings = [];
include $englishPath;

$langStrings[$language] = $strings;
}
}

if (isset($langStrings[$language][$variable])) {
return $langStrings[$language][$variable];
}

return $this->get_lang($variable);
}

/**
* Caller for the install_course_fields() function.
*
Expand Down

0 comments on commit 2423c1c

Please sign in to comment.