mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/10824] Make languages use composer.json
PHPBB3-10824
This commit is contained in:
parent
a200446646
commit
8244aff9cb
4 changed files with 88 additions and 25 deletions
|
@ -265,20 +265,21 @@ class acp_language
|
|||
$lang_iso = $request->variable('iso', '');
|
||||
$lang_iso = basename($lang_iso);
|
||||
|
||||
if (!$lang_iso || !file_exists("{$phpbb_root_path}language/$lang_iso/iso.txt"))
|
||||
if (!$lang_iso || !file_exists("{$phpbb_root_path}language/$lang_iso/composer.json"))
|
||||
{
|
||||
trigger_error($user->lang['LANGUAGE_PACK_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$file = file("{$phpbb_root_path}language/$lang_iso/iso.txt");
|
||||
|
||||
$lang_pack = array(
|
||||
'iso' => $lang_iso,
|
||||
'name' => trim(htmlspecialchars($file[0], ENT_COMPAT)),
|
||||
'local_name'=> trim(htmlspecialchars($file[1], ENT_COMPAT, 'UTF-8')),
|
||||
'author' => trim(htmlspecialchars($file[2], ENT_COMPAT, 'UTF-8'))
|
||||
);
|
||||
unset($file);
|
||||
/** @var \phpbb\language\language_file_helper $language_helper */
|
||||
$language_helper = $phpbb_container->get('language.helper.language_file');
|
||||
try
|
||||
{
|
||||
$lang_pack = $language_helper->get_language_data_from_composer_file("{$phpbb_root_path}language/$lang_iso/composer.json");
|
||||
}
|
||||
catch (\DomainException $e)
|
||||
{
|
||||
trigger_error($user->lang['LANGUAGE_PACK_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
|
||||
$sql = 'SELECT lang_iso
|
||||
FROM ' . LANG_TABLE . "
|
||||
|
|
27
phpBB/language/en/composer.json
Executable file
27
phpBB/language/en/composer.json
Executable file
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"name": "en",
|
||||
"description": "phpBB Forum Software default style",
|
||||
"type": "phpbb-language",
|
||||
"version": "3.2.0-a1-dev",
|
||||
"homepage": "https://www.phpbb.com",
|
||||
"license": "GPL-2.0",
|
||||
"authors": [
|
||||
{
|
||||
"name": "phpBB Limited",
|
||||
"email": "operations@phpbb.com",
|
||||
"homepage": "https://www.phpbb.com/go/authors"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://tracker.phpbb.com",
|
||||
"forum": "https://www.phpbb.com/community/",
|
||||
"wiki": "https://wiki.phpbb.com",
|
||||
"irc": "irc://irc.freenode.org/phpbb"
|
||||
},
|
||||
"extra": {
|
||||
"language-iso": "en",
|
||||
"english-name": "British English",
|
||||
"local-name": "British English",
|
||||
"phpbb-version": "3.2.0-a1-dev"
|
||||
}
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
British English
|
||||
British English
|
||||
phpBB Limited
|
|
@ -45,7 +45,7 @@ class language_file_helper
|
|||
// Find available language packages
|
||||
$finder = new Finder();
|
||||
$finder->files()
|
||||
->name('iso.txt')
|
||||
->name('composer.json')
|
||||
->depth('== 1')
|
||||
->followLinks()
|
||||
->in($this->phpbb_root_path . 'language');
|
||||
|
@ -53,20 +53,58 @@ class language_file_helper
|
|||
$available_languages = array();
|
||||
foreach ($finder as $file)
|
||||
{
|
||||
$path = $file->getRelativePath();
|
||||
$info = explode("\n", $file->getContents());
|
||||
$json = $file->getContents();
|
||||
$data = json_decode($json, true);
|
||||
|
||||
$available_languages[] = array(
|
||||
// Get the name of the directory containing iso.txt
|
||||
'iso' => $path,
|
||||
|
||||
// Recover data from file
|
||||
'name' => trim($info[0]),
|
||||
'local_name' => trim($info[1]),
|
||||
'author' => trim($info[2])
|
||||
);
|
||||
$available_languages[] = $this->get_language_data_from_json($data);
|
||||
}
|
||||
|
||||
return $available_languages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect some data from the composer.json file
|
||||
*
|
||||
* @param string $path
|
||||
* @return array
|
||||
*/
|
||||
public function get_language_data_from_composer_file($path)
|
||||
{
|
||||
$json_data = file_get_contents($path);
|
||||
return $this->get_language_data_from_json(json_decode($json_data, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect some data from the composer.json data
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function get_language_data_from_json(array $data)
|
||||
{
|
||||
if (!isset($data['extra']['language-iso']) || !isset($data['extra']['english-name']) || !isset($data['extra']['local-name']))
|
||||
{
|
||||
throw new \DomainException('INVALID_LANGUAGE_PACK');
|
||||
}
|
||||
|
||||
$authors = array();
|
||||
if (isset($data['authors']))
|
||||
{
|
||||
foreach ($data['authors'] as $author)
|
||||
{
|
||||
if (isset($author['name']) && $author['name'] !== '')
|
||||
{
|
||||
$authors[] = $author['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'iso' => $data['extra']['language-iso'],
|
||||
|
||||
'name' => $data['extra']['english-name'],
|
||||
'local_name' => $data['extra']['local-name'],
|
||||
'author' => implode(', ', $authors),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue