Skip to content

Commit

Permalink
Load language strings for a default language to a separate array
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Babker committed Aug 3, 2017
1 parent cdaee9e commit 98539de
Showing 1 changed file with 51 additions and 4 deletions.
55 changes: 51 additions & 4 deletions libraries/src/Joomla/CMS/Language/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ class Language
*/
protected $strings = array();

/**
* Translations for the default language
*
* @var array
* @since 11.1
*/
protected $defaultStrings = array();

/**
* An array of used text, used during debugging.
*
Expand Down Expand Up @@ -176,6 +184,14 @@ class Language
*/
protected $searchDisplayedCharactersNumberCallback = null;

/**
* Tracking flag indicating a default language is being loaded.
*
* @var boolean
* @since __DEPLOY_VERSION__
*/
protected $loadingDefault = false;

/**
* Constructor activating the default information of the language.
*
Expand All @@ -186,7 +202,8 @@ class Language
*/
public function __construct($lang = null, $debug = false)
{
$this->strings = array();
$this->defaultStrings = array();
$this->strings = array();

if ($lang == null)
{
Expand Down Expand Up @@ -346,6 +363,24 @@ public function _($string, $jsSafe = false, $interpretBackSlashes = true)
$this->used[$key][] = $caller;
}
}
// Only look in the default store if debugging is not active to allow a key to be reported as untranslated in the active language
elseif (!$this->debug && isset($this->defaultStrings[$key]))
{
$string = $this->debug ? '**' . $this->defaultStrings[$key] . '**' : $this->defaultStrings[$key];

// Store debug information
if ($this->debug)
{
$caller = $this->getCallerInfo();

if (!array_key_exists($key, $this->used))
{
$this->used[$key] = array();
}

$this->used[$key][] = $caller;
}
}
else
{
if ($this->debug)
Expand Down Expand Up @@ -720,7 +755,11 @@ public function load($extension = 'joomla', $basePath = JPATH_BASE, $lang = null
// with $default set to true
if (!$this->debug && ($lang != $this->default) && $default)
{
$this->loadingDefault = true;

$this->load($extension, $basePath, $this->default, false, true);

$this->loadingDefault = false;
}

$path = LanguageHelper::getLanguagePath($basePath, $lang);
Expand Down Expand Up @@ -756,7 +795,7 @@ public function load($extension = 'joomla', $basePath = JPATH_BASE, $lang = null
// If the one we tried is different than the new name, try again
if ($oldFilename != $filename)
{
$result = $this->loadLanguage($filename, $extension, false);
$result = $this->loadLanguage($filename, $extension);
}
}
}
Expand Down Expand Up @@ -794,7 +833,15 @@ protected function loadLanguage($filename, $extension = 'unknown')
{
if (is_array($strings) && count($strings))
{
$this->strings = array_replace($this->strings, $strings, $this->override);
if ($this->loadingDefault)
{
$this->defaultStrings = array_replace($this->defaultStrings, $strings, $this->override);
}
else
{
$this->strings = array_replace($this->strings, $strings, $this->override);
}

$result = true;
}
}
Expand Down Expand Up @@ -1214,7 +1261,7 @@ public function hasKey($string)
{
$key = strtoupper($string);

return isset($this->strings[$key]);
return isset($this->strings[$key]) || isset($this->defaultStrings[$key]);
}

/**
Expand Down

0 comments on commit 98539de

Please sign in to comment.