protected _bindTextDomain ( string $domain ) : string | ||
$domain | string | Domain to bind |
return | string | Domain binded |
protected function _bindTextDomain($domain)
{
$this->_noLocale = true;
$core = true;
$merge = array();
$searchPaths = App::path('locales');
$plugins = CakePlugin::loaded();
if (!empty($plugins)) {
foreach ($plugins as $plugin) {
$pluginDomain = Inflector::underscore($plugin);
if ($pluginDomain === $domain) {
$searchPaths[] = CakePlugin::path($plugin) . 'Locale' . DS;
if (!Configure::read('I18n.preferApp')) {
$searchPaths = array_reverse($searchPaths);
}
break;
}
}
}
foreach ($searchPaths as $directory) {
foreach ($this->l10n->languagePath as $lang) {
$localeDef = $directory . $lang . DS . $this->category;
if (is_file($localeDef)) {
$definitions = static::loadLocaleDefinition($localeDef);
if ($definitions !== false) {
$this->_domains[$domain][$this->_lang][$this->category] = $definitions;
$this->_noLocale = false;
return $domain;
}
}
if ($core) {
$app = $directory . $lang . DS . $this->category . DS . 'core';
$translations = false;
if (is_file($app . '.mo')) {
$translations = static::loadMo($app . '.mo');
}
if ($translations === false && is_file($app . '.po')) {
$translations = static::loadPo($app . '.po');
}
if ($translations !== false) {
$this->_domains[$domain][$this->_lang][$this->category] = $translations;
$merge[$domain][$this->_lang][$this->category] = $this->_domains[$domain][$this->_lang][$this->category];
$this->_noLocale = false;
$core = null;
}
}
$file = $directory . $lang . DS . $this->category . DS . $domain;
$translations = false;
if (is_file($file . '.mo')) {
$translations = static::loadMo($file . '.mo');
}
if ($translations === false && is_file($file . '.po')) {
$translations = static::loadPo($file . '.po');
}
if ($translations !== false) {
$this->_domains[$domain][$this->_lang][$this->category] = $translations;
$this->_noLocale = false;
break 2;
}
}
}
if (empty($this->_domains[$domain][$this->_lang][$this->category])) {
$this->_domains[$domain][$this->_lang][$this->category] = array();
return $domain;
}
if (isset($this->_domains[$domain][$this->_lang][$this->category][""])) {
$head = $this->_domains[$domain][$this->_lang][$this->category][""];
foreach (explode("\n", $head) as $line) {
$header = strtok($line, ':');
$line = trim(strtok("\n"));
$this->_domains[$domain][$this->_lang][$this->category]["%po-header"][strtolower($header)] = $line;
}
if (isset($this->_domains[$domain][$this->_lang][$this->category]["%po-header"]["plural-forms"])) {
$switch = preg_replace("/(?:[() {}\\[\\]^\\s*\\]]+)/", "", $this->_domains[$domain][$this->_lang][$this->category]["%po-header"]["plural-forms"]);
$this->_domains[$domain][$this->_lang][$this->category]["%plural-c"] = $switch;
unset($this->_domains[$domain][$this->_lang][$this->category]["%po-header"]);
}
$this->_domains = Hash::mergeDiff($this->_domains, $merge);
if (isset($this->_domains[$domain][$this->_lang][$this->category][null])) {
unset($this->_domains[$domain][$this->_lang][$this->category][null]);
}
}
return $domain;
}