mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-30 21:40:43 +02:00
Merge pull request #6534 from Crizz0/ticket/17191
[ticket/17191] New config values to language/en/composer.json
This commit is contained in:
@@ -387,7 +387,7 @@ class feed
|
||||
'FEED_TITLE' => $this->config['sitename'],
|
||||
'FEED_SUBTITLE' => $this->config['site_desc'],
|
||||
'FEED_UPDATED' => $this->feed_helper->format_date($feed_updated_time),
|
||||
'FEED_LANG' => $this->user->lang['USER_LANG'],
|
||||
'FEED_LANG' => $this->language->lang('USER_LANG'),
|
||||
'FEED_AUTHOR' => $this->config['sitename'],
|
||||
|
||||
// Feed entries
|
||||
|
@@ -384,10 +384,27 @@ class language
|
||||
$this->load_core_file($lang_file);
|
||||
}
|
||||
|
||||
$this->inject_default_variables();
|
||||
|
||||
$this->common_language_files_loaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject default values based on composer.json
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function inject_default_variables(): void
|
||||
{
|
||||
$lang_values = $this->loader->get_composer_lang_values($this->language_fallback);
|
||||
|
||||
$this->lang['DIRECTION'] = $lang_values['direction'] ?? 'ltr';
|
||||
$this->lang['USER_LANG'] = $lang_values['user_lang'] ?? 'en-gb';
|
||||
$this->lang['PLURAL_RULE'] = $lang_values['plural_rule'] ?? 1;
|
||||
$this->lang['RECAPTCHA_LANG'] = $lang_values['recaptcha_lang'] ?? 'en-GB';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine which plural form we should use.
|
||||
*
|
||||
@@ -404,7 +421,7 @@ class language
|
||||
public function get_plural_form($number, $force_rule = false)
|
||||
{
|
||||
$number = (int) $number;
|
||||
$plural_rule = ($force_rule !== false) ? $force_rule : ((isset($this->lang['PLURAL_RULE'])) ? $this->lang['PLURAL_RULE'] : 1);
|
||||
$plural_rule = ($force_rule !== false) ? $force_rule : ((isset($this->lang['PLURAL_RULE'])) ? $this->lang['PLURAL_RULE'] : 1);
|
||||
|
||||
/**
|
||||
* The following plural rules are based on a list published by the Mozilla Developer Network
|
||||
|
@@ -30,7 +30,8 @@ class language_file_helper
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $phpbb_root_path Path to phpBB's root
|
||||
* @param string $phpbb_root_path Path to phpBB's root
|
||||
*
|
||||
*/
|
||||
public function __construct(string $phpbb_root_path)
|
||||
{
|
||||
@@ -91,7 +92,7 @@ class language_file_helper
|
||||
*/
|
||||
protected function get_language_data_from_json(array $data) : array
|
||||
{
|
||||
if (!isset($data['extra']['language-iso']) || !isset($data['extra']['english-name']) || !isset($data['extra']['local-name']))
|
||||
if (!isset($data['extra']['language-iso']) || !isset($data['extra']['english-name']) || !isset($data['extra']['local-name']) || !isset($data['extra']['direction']) || !isset($data['extra']['user-lang']) || !isset($data['extra']['plural-rule']) || !isset($data['extra']['recaptcha-lang']))
|
||||
{
|
||||
throw new DomainException('INVALID_LANGUAGE_PACK');
|
||||
}
|
||||
@@ -115,6 +116,10 @@ class language_file_helper
|
||||
'author' => implode(', ', $authors),
|
||||
'version' => $data['version'],
|
||||
'phpbb_version' => $data['extra']['phpbb-version'],
|
||||
'direction' => $data['extra']['direction'],
|
||||
'user_lang' => $data['extra']['user-lang'],
|
||||
'plural_rule' => $data['extra']['plural-rule'],
|
||||
'recaptcha_lang'=> $data['extra']['recaptcha-lang'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -186,6 +186,39 @@ class language_file_loader
|
||||
throw new language_file_not_found('Language file ' . $language_file_path . ' couldn\'t be opened.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language values from composer.json files
|
||||
*
|
||||
* @param array|string $locales
|
||||
* @return array
|
||||
*/
|
||||
public function get_composer_lang_values(array|string $locales): array
|
||||
{
|
||||
if (!is_array($locales))
|
||||
{
|
||||
$locales = [$locales];
|
||||
}
|
||||
|
||||
$file_helper = new language_file_helper($this->phpbb_root_path);
|
||||
$composer_lang_vars = $file_helper->get_available_languages();
|
||||
|
||||
foreach ($composer_lang_vars as $key => $value)
|
||||
{
|
||||
$composer_lang_vars[$value['iso']] = $value;
|
||||
unset($composer_lang_vars[$key]);
|
||||
}
|
||||
|
||||
foreach ($locales as $locale)
|
||||
{
|
||||
if (isset($composer_lang_vars[$locale]))
|
||||
{
|
||||
return $composer_lang_vars[$locale];
|
||||
}
|
||||
}
|
||||
|
||||
return count($composer_lang_vars) ? array_shift($composer_lang_vars) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads language file
|
||||
*
|
||||
|
Reference in New Issue
Block a user