diff --git a/phpBB/includes/acp/acp_language.php b/phpBB/includes/acp/acp_language.php index b2d732d4a8..43d6b32dbe 100644 --- a/phpBB/includes/acp/acp_language.php +++ b/phpBB/includes/acp/acp_language.php @@ -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 . " diff --git a/phpBB/language/en/composer.json b/phpBB/language/en/composer.json new file mode 100755 index 0000000000..f72db34269 --- /dev/null +++ b/phpBB/language/en/composer.json @@ -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" + } +} diff --git a/phpBB/language/en/iso.txt b/phpBB/language/en/iso.txt deleted file mode 100644 index 2e45cc56d0..0000000000 --- a/phpBB/language/en/iso.txt +++ /dev/null @@ -1,3 +0,0 @@ -British English -British English -phpBB Limited \ No newline at end of file diff --git a/phpBB/phpbb/language/language_file_helper.php b/phpBB/phpbb/language/language_file_helper.php index 85de034fb8..8d6bb8cc0b 100644 --- a/phpBB/phpbb/language/language_file_helper.php +++ b/phpBB/phpbb/language/language_file_helper.php @@ -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), + ); + } }