From 63e195d7f0c286b0dcbc4ae30826ee88d811c372 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 11 May 2014 13:10:51 +0200 Subject: [PATCH] [ticket/12527] Restore missing files and variables check PHPBB3-12527 --- phpBB/adm/style/acp_language.html | 56 +++++++----------- phpBB/includes/acp/acp_language.php | 89 ++++++++++++++++++++++++++++- phpBB/language/en/acp/language.php | 1 + 3 files changed, 110 insertions(+), 36 deletions(-) diff --git a/phpBB/adm/style/acp_language.html b/phpBB/adm/style/acp_language.html index faf8159b49..4439f519e0 100644 --- a/phpBB/adm/style/acp_language.html +++ b/phpBB/adm/style/acp_language.html @@ -36,46 +36,32 @@ -

+ +

{L_MISSING_FILES}

- -
-

{L_MISSING_FILES}

-

{MISSING_FILES}

-
-

+
+ {L_MISSING_LANG_FILES} + + » {missing_files.FILE_NAME}
+ +
- -

{L_MISSING_LANG_VARIABLES}

+ +

{L_MISSING_VARS_EXPLAIN}

-

{L_MISSING_VARS_EXPLAIN}

- -
- - - - - - - - - - - - - - - {missing.TPL} - - -
{L_LANGUAGE_KEY}{L_LANGUAGE_VARIABLE}
{missing.FILE}
-
{S_FORM_TOKEN}
-
- -

+
+ {L_MISSING_LANG_VARIABLES} + +
+
+ +
{missing_varfile.variable.VAR_NAME}
+ +
+ +
-

{L_ACP_LANGUAGE_PACKS}

diff --git a/phpBB/includes/acp/acp_language.php b/phpBB/includes/acp/acp_language.php index d0920c3490..dfd3b06290 100644 --- a/phpBB/includes/acp/acp_language.php +++ b/phpBB/includes/acp/acp_language.php @@ -110,6 +110,8 @@ class acp_language $lang_entries = $db->sql_fetchrow($result); $db->sql_freeresult($result); + $lang_iso = $lang_entries['lang_iso']; + $template->assign_vars(array( 'S_DETAILS' => true, 'U_ACTION' => $this->u_action . "&action=details&id=$lang_id", @@ -117,10 +119,67 @@ class acp_language 'LANG_LOCAL_NAME' => $lang_entries['lang_local_name'], 'LANG_ENGLISH_NAME' => $lang_entries['lang_english_name'], - 'LANG_ISO' => $lang_entries['lang_iso'], + 'LANG_ISO' => $lang_iso, 'LANG_AUTHOR' => $lang_entries['lang_author'], + 'L_MISSING_FILES' => $user->lang('THOSE_MISSING_LANG_FILES', $lang_entries['lang_local_name']), + 'L_MISSING_VARS_EXPLAIN' => $user->lang('THOSE_MISSING_LANG_VARIABLES', $lang_entries['lang_local_name']), )); + // If current lang is different from the default lang, then highlight missing files and variables + if ($lang_iso != $config['default_lang']) + { + try + { + $iterator = new \RecursiveIteratorIterator( + new \phpbb\recursive_dot_prefix_filter_iterator( + new \RecursiveDirectoryIterator( + $phpbb_root_path . 'language/' . $config['default_lang'] . '/', + \FilesystemIterator::SKIP_DOTS + ) + ), + \RecursiveIteratorIterator::LEAVES_ONLY + ); + } + catch (\Exception $e) + { + return array(); + } + + foreach ($iterator as $file_info) + { + /** @var \RecursiveDirectoryIterator $file_info */ + $relative_path = $iterator->getInnerIterator()->getSubPathname(); + $relative_path = str_replace(DIRECTORY_SEPARATOR, '/', $relative_path); + + if (file_exists($phpbb_root_path . 'language/' . $lang_iso . '/' . $relative_path)) + { + if (substr($relative_path, 0 - strlen($phpEx)) === $phpEx) + { + $missing_vars = $this->compare_language_files($config['default_lang'], $lang_iso, $relative_path); + + if (!empty($missing_vars)) + { + $template->assign_block_vars('missing_varfile', array( + 'FILE_NAME' => $relative_path, + )); + + foreach ($missing_vars as $var) + { + $template->assign_block_vars('missing_varfile.variable', array( + 'VAR_NAME' => $var, + )); + } + } + } + } + else + { + $template->assign_block_vars('missing_files', array( + 'FILE_NAME' => $relative_path, + )); + } + } + } return; break; @@ -362,4 +421,32 @@ class acp_language unset($new_ary); } + + /** + * Compare two language files + */ + function compare_language_files($source_lang, $dest_lang, $file) + { + global $phpbb_root_path; + + $source_file = $phpbb_root_path . 'language/' . $source_lang . '/' . $file; + $dest_file = $phpbb_root_path . 'language/' . $dest_lang . '/' . $file; + + if (!file_exists($dest_file)) + { + return array(); + } + + $lang = array(); + include($source_file); + $lang_entry_src = $lang; + + $lang = array(); + include($dest_file); + $lang_entry_dst = $lang; + + unset($lang); + + return array_diff(array_keys($lang_entry_src), array_keys($lang_entry_dst)); + } } diff --git a/phpBB/language/en/acp/language.php b/phpBB/language/en/acp/language.php index 154551bd6e..5df99892ca 100644 --- a/phpBB/language/en/acp/language.php +++ b/phpBB/language/en/acp/language.php @@ -71,6 +71,7 @@ $lang = array_merge($lang, array( 'LANG_LOCAL_NAME' => 'Local name', 'MISSING_LANGUAGE_FILE' => 'Missing language file: %s', + 'MISSING_LANG_FILES' => 'Missing language files', 'MISSING_LANG_VARIABLES' => 'Missing language variables', 'MODS_FILES' => 'MODs language files',