From 1d7a1fa4252bd4c07d4277bf6a54bf354fbe1471 Mon Sep 17 00:00:00 2001 From: Robert Lyon Date: Wed, 20 May 2015 10:44:06 +1200 Subject: [PATCH] Allowing for non english theme / plugin lang files to be used Bug 1417120 The language location check now goes in this order: 1. /local string in selected language 2. theme/plugin directory, in selected language 3. langpack, in selected language 4. /local string in parent language (if any) 5. theme/plugin directory, in parent language 6. langpack, in parent language 7. /local string in English 8. theme/plugin directory, in English Change-Id: I24f61e24fadbca3a62fefa3855f4f444165d750a Signed-off-by: Robert Lyon --- htdocs/lib/mahara.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/htdocs/lib/mahara.php b/htdocs/lib/mahara.php index c3941ed62d..18ff096432 100644 --- a/htdocs/lib/mahara.php +++ b/htdocs/lib/mahara.php @@ -462,6 +462,8 @@ function get_string_location($identifier, $section, $variables, $replacefunc='fo // Define the locations of language strings for this section $langstringroot = get_language_root($lang); + $docroot = get_config('docroot'); + $langdirectory = ''; // The directory in which the language file for this string should ideally reside, if the language has implemented it if (false === strpos($section, '.')) { @@ -486,7 +488,13 @@ function get_string_location($identifier, $section, $variables, $replacefunc='fo } } - // First check all the normal locations for the string in the current language + // First check the theme/plugin locations + $result = get_string_local($docroot . $langdirectory, $lang . '/' . $section . '.php', $identifier); + if ($result !== false) { + return $replacefunc($result, $variables, $lang); + } + + // Then check the default location for the string in the current language $result = get_string_local($langstringroot . $langdirectory, $lang . '/' . $section . '.php', $identifier); if ($result !== false) { return $replacefunc($result, $variables, $lang); @@ -502,7 +510,15 @@ function get_string_location($identifier, $section, $variables, $replacefunc='fo $langfile = $langstringroot . 'lang/' . $lang . '/langconfig.php'; if (is_readable($langfile)) { if ($parentlang = get_string_from_file('parentlanguage', $langfile)) { - $result = get_string_local(get_language_root($parentlang) . 'lang/', $parentlang . '/' . $section . '.php', $identifier); + + // First check the theme/plugin locations + $result = get_string_local($docroot . $langdirectory, $parentlang . '/' . $section . '.php', $identifier); + if ($result !== false) { + return $replacefunc($result, $variables, $parentlang); + } + + // Then check the default location for the string in the current language + $result = get_string_local(get_language_root($parentlang) . $langdirectory, $parentlang . '/' . $section . '.php', $identifier); if ($result !== false) { return $replacefunc($result, $variables, $parentlang); } -- GitLab