diff --git a/4dev/locale/en_US-admin.po b/4dev/locale/en-admin.po similarity index 79% rename from 4dev/locale/en_US-admin.po rename to 4dev/locale/en-admin.po index b6c191f3..cdef1a50 100644 --- a/4dev/locale/en_US-admin.po +++ b/4dev/locale/en-admin.po @@ -8,13 +8,13 @@ msgid "" msgstr "" -"Project-Id-Version: en_US.UTF-8 LC_MESSAGES admin\n" +"Project-Id-Version: en.UTF-8 LC_MESSAGES admin\n" "Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n" "POT-Creation-Date: 2018-03-28 10:40+0900\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: clemens.schwaighofer@egplusww.co\n" "Language-Team: E-GRAPHICS COMMUNICATIONS Japan \n" -"Language: en_US\n" +"Language: en\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -32,20 +32,20 @@ msgstr "OUTPUT TEST ADMIN EN" # testing multi msgid "single" msgid_plural "multi" -msgstr[0] "Multi Admin en_US 0" -msgstr[1] "Multi Admin en_US 1" -msgstr[2] "Multi Admin en_US 2" +msgstr[0] "Multi Admin en 0" +msgstr[1] "Multi Admin en 1" +msgstr[2] "Multi Admin en 2" msgctxt "month name" msgid "May" -msgstr "May Admin en_US" +msgstr "May Admin en" msgctxt "month name" msgid "single" msgid_plural "multi" -msgstr[0] "Multi Admin month en_US 0" -msgstr[1] "Multi Admin month en_US 1" -msgstr[2] "Multi Admin month en_US 2" +msgstr[0] "Multi Admin month en 0" +msgstr[1] "Multi Admin month en 1" +msgstr[2] "Multi Admin month en 2" msgid "I should be translated" msgstr "I should be translated: I WAS TRANSLATED" diff --git a/4dev/locale/en_US-frontend.po b/4dev/locale/en-frontend.po similarity index 76% rename from 4dev/locale/en_US-frontend.po rename to 4dev/locale/en-frontend.po index 765359d0..f30277bd 100644 --- a/4dev/locale/en_US-frontend.po +++ b/4dev/locale/en-frontend.po @@ -2,13 +2,13 @@ msgid "" msgstr "" -"Project-Id-Version: en_US.UTF-8 LC_MESSAGES frontend\n" +"Project-Id-Version: en.UTF-8 LC_MESSAGES frontend\n" "Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n" "POT-Creation-Date: 2018-03-28 10:40+0900\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: clemens.schwaighofer@egplusww.co\n" "Language-Team: E-GRAPHICS COMMUNICATIONS Japan \n" -"Language: en_US\n" +"Language: en\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -19,6 +19,6 @@ msgstr "OUTPUT TEST FRONTEND EN" msgid "single" msgid_plural "multi" -msgstr[0] "Multi frontend en_US 0" -msgstr[1] "Multi frontend en_US 1" -msgstr[2] "Multi frontend en_US 2" +msgstr[0] "Multi frontend en 0" +msgstr[1] "Multi frontend en 1" +msgstr[2] "Multi frontend en 2" diff --git a/4dev/locale/ja-admin.po b/4dev/locale/ja-admin.po index 35e08f80..68cfeee6 100644 --- a/4dev/locale/ja-admin.po +++ b/4dev/locale/ja-admin.po @@ -8,7 +8,7 @@ msgid "" msgstr "" -"Project-Id-Version: ja_JP.UTF-8 LC_MESSAGES admin\n" +"Project-Id-Version: ja.UTF-8 LC_MESSAGES admin\n" "Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n" "POT-Creation-Date: 2018-03-28 10:40+0900\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" @@ -69,9 +69,20 @@ msgstr "OUTPUT TEST ADMIN JA" # testing multi msgid "single" msgid_plural "multi" -msgstr[0] "Multi Admin ja_JP 0" -msgstr[1] "Multi Admin ja_JP 1" -msgstr[2] "Multi Admin ja_JP 2" +msgstr[0] "Multi Admin ja 0" +msgstr[1] "Multi Admin ja 1" +msgstr[2] "Multi Admin ja 2" + +msgctxt "month name" +msgid "May" +msgstr "May Admin ja" + +msgctxt "month name" +msgid "single" +msgid_plural "multi" +msgstr[0] "Multi Admin month ja 0" +msgstr[1] "Multi Admin month ja 1" +msgstr[2] "Multi Admin month ja 2" # login string msgid "Hello %s" diff --git a/4dev/locale/ja-frontend.po b/4dev/locale/ja-frontend.po index 049707a1..fd9edb1a 100644 --- a/4dev/locale/ja-frontend.po +++ b/4dev/locale/ja-frontend.po @@ -2,7 +2,23 @@ msgid "" msgstr "" +"Project-Id-Version: ja.UTF-8 LC_MESSAGES frontend\n" +"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n" +"POT-Creation-Date: 2018-03-28 10:40+0900\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: clemens.schwaighofer@egplusww.com\n" +"Language-Team: E-GRAPHICS COMMUNICATIONS Japan \n" +"Language: ja\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1)\n" msgid "INPUT TEST" msgstr "OUTPUT TEST FRONTEND JA" + +msgid "single" +msgid_plural "multi" +msgstr[0] "Multi frontend ja 0" +msgstr[1] "Multi frontend ja 1" +msgstr[2] "Multi frontend ja 2" diff --git a/4dev/tests/CoreLibsLanguageGetLocaleTest.php b/4dev/tests/CoreLibsLanguageGetLocaleTest.php new file mode 100644 index 00000000..cd597e71 --- /dev/null +++ b/4dev/tests/CoreLibsLanguageGetLocaleTest.php @@ -0,0 +1,291 @@ + [ + // lang, domain, encoding, path + null, null, null, null, + // SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET + null, null, + // return array + [ + 'locale' => 'en_US.UTF-8', + 'lang' => 'en_US', + 'domain' => 'frontend', + 'encoding' => 'UTF-8', + 'path' => "/^\/(.*\/)?includes\/locale\/$/", + ], + ], + 'no params, session charset and lang' => [ + // lang, domain, encoding, path + null, null, null, null, + // SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET + 'ja_JP', 'UTF-8', + // return array + [ + 'locale' => 'ja_JP', + 'lang' => 'ja_JP', + 'domain' => 'frontend', + 'encoding' => 'UTF-8', + 'path' => "/^\/(.*\/)?includes\/locale\/$/", + ], + ], + 'no params, session charset and lang short' => [ + // lang, domain, encoding, path + null, null, null, null, + // SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET + 'ja', 'UTF-8', + // return array + [ + 'locale' => 'ja', + 'lang' => 'ja', + 'domain' => 'frontend', + 'encoding' => 'UTF-8', + 'path' => "/^\/(.*\/)?includes\/locale\/$/", + ], + ], + // param lang (no sessions) + 'locale param only, no sessions' => [ + // lang, domain, encoding, path + 'ja.UTF-8', null, null, null, + // SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET + null, null, + // return array + [ + 'locale' => 'ja.UTF-8', + 'lang' => 'ja', + 'domain' => 'frontend', + 'encoding' => 'UTF-8', + 'path' => "/^\/(.*\/)?includes\/locale\/$/", + ], + ], + // different locale setting + 'locale complex param only, no sessions' => [ + // lang, domain, encoding, path + 'ja_JP.SJIS', null, null, null, + // SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET + null, null, + // return array + [ + 'locale' => 'ja_JP.SJIS', + 'lang' => 'ja_JP', + 'domain' => 'frontend', + 'encoding' => 'SJIS', + 'path' => "/^\/(.*\/)?includes\/locale\/$/", + ], + ], + // param lang and domain (no override) + 'locale, domain params, no sessions' => [ + // lang, domain, encoding, path + 'ja.UTF-8', 'admin', null, null, + // SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET + null, null, + // return array + [ + 'locale' => 'ja.UTF-8', + 'lang' => 'ja', + 'domain' => 'admin', + 'encoding' => 'UTF-8', + 'path' => "/^\/(.*\/)?includes\/locale\/$/", + ], + ], + // param lang and domain (no override) + 'locale, domain, encoding params, no sessions' => [ + // lang, domain, encoding, path + 'ja.UTF-8', 'admin', 'UTF-8', null, + // SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET + null, null, + // return array + [ + 'locale' => 'ja.UTF-8', + 'lang' => 'ja', + 'domain' => 'admin', + 'encoding' => 'UTF-8', + 'path' => "/^\/(.*\/)?includes\/locale\/$/", + ], + ], + // lang, domain, path (no override) + 'locale, domain and path, no sessions' => [ + // lang, domain, encoding, path + 'ja.UTF-8', 'admin', '', __DIR__ . '/locale_other/', + // SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET + null, null, + // return array + [ + 'locale' => 'ja.UTF-8', + 'lang' => 'ja', + 'domain' => 'admin', + 'encoding' => 'UTF-8', + 'path' => "/^\/(.*\/)?locale_other\/$/", + ], + ], + // all params set (no override) + 'all parameter, no sessions' => [ + // lang, domain, encoding, path + 'ja', 'admin', 'UTF-8', __DIR__ . '/locale_other/', + // SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET + null, null, + // return array + [ + 'locale' => 'ja', + 'lang' => 'ja', + 'domain' => 'admin', + 'encoding' => 'UTF-8', + 'path' => "/^\/(.*\/)?locale_other\/$/", + ], + ], + // param lang and domain (no override) + 'long locale, domain, encoding params, no sessions' => [ + // lang, domain, encoding, path + 'de_CH.UTF-8@euro', 'admin', 'UTF-8', null, + // SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET + null, null, + // return array + [ + 'locale' => 'de_CH.UTF-8@euro', + 'lang' => 'de_CH', + 'domain' => 'admin', + 'encoding' => 'UTF-8', + 'path' => "/^\/(.*\/)?includes\/locale\/$/", + ], + ], + // TODO invalid params (bad path) (no override) + // TODO param calls, but with override set + ]; + } + + /** + * Undocumented function + * + * @covers ::setLocale + * @dataProvider setLocaleProvider + * @testdox lang settings lang $language, domain $domain, encoding $encoding, path $path; session lang: $SESSION_DEFAULT_LOCALE, session char: $SESSION_DEFAULT_CHARSET [$_dataName] + * + * @return void + */ + public function testsetLocale( + ?string $language, + ?string $domain, + ?string $encoding, + ?string $path, + ?string $SESSION_DEFAULT_LOCALE, + ?string $SESSION_DEFAULT_CHARSET, + array $expected, + ): void { + $return_lang_settings = []; + global $_SESSION; + // set override + if ($SESSION_DEFAULT_LOCALE !== null) { + $_SESSION['DEFAULT_LOCALE'] = $SESSION_DEFAULT_LOCALE; + } + if ($SESSION_DEFAULT_CHARSET !== null) { + $_SESSION['DEFAULT_CHARSET'] = $SESSION_DEFAULT_CHARSET; + } + // function call + if ($language === null && $domain === null && $encoding === null && $path === null) { + $return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(); + } elseif ($language !== null && $domain === null && $encoding === null && $path === null) { + $return_lang_settings = \CoreLibs\Language\GetLocale::setLocale( + $language + ); + } elseif ($language !== null && $domain !== null && $encoding === null && $path === null) { + $return_lang_settings = \CoreLibs\Language\GetLocale::setLocale( + $language, + $domain + ); + } elseif ($language !== null && $domain !== null && $encoding !== null && $path === null) { + $return_lang_settings = \CoreLibs\Language\GetLocale::setLocale( + $language, + $domain, + $encoding + ); + } else { + $return_lang_settings = \CoreLibs\Language\GetLocale::setLocale( + $language, + $domain, + $encoding, + $path + ); + } + // print "RETURN: " . print_r($return_lang_settings, true) . "\n"; + + foreach ( + [ + 'locale', 'lang', 'domain', 'encoding', 'path' + ] as $key + ) { + $value = $expected[$key]; + if (strpos($value, "/") === 0) { + // this is regex + $this->assertMatchesRegularExpression( + $value, + $return_lang_settings[$key], + 'assert regex failed for ' . $key + ); + } else { + // assert equal + $this->assertEquals( + $value, + $return_lang_settings[$key], + 'assert equal failed for ' . $key + ); + } + } + // unset all vars + $_SESSION = []; + unset($GLOBALS['OVERRIDE_LANG']); + } +} + +// __END__ diff --git a/4dev/tests/CoreLibsLanguageL10nTest.php b/4dev/tests/CoreLibsLanguageL10nTest.php index ac866c06..65cca215 100644 --- a/4dev/tests/CoreLibsLanguageL10nTest.php +++ b/4dev/tests/CoreLibsLanguageL10nTest.php @@ -87,44 +87,20 @@ final class CoreLibsLanguageL10nTest extends TestCase { return [ // 0: locale - // 1: path - // 2: domain - // 3: legacy load (Default true) + // 1: domain + // 2: encoding + // 3: path // 4: locale expected // 5: domain exepcted // 6: context (null for none) // 7: test string in // 8: test translated - 'legacy load en' => [ - 'en_utf8', - null, - null, - null, - // - 'en_utf8', - '', - // - null, - 'Original', - 'Translated frontend en_US', - ], - 'legacy load ja' => [ - 'ja_utf8', - null, - null, - null, - 'ja_utf8', - '', - null, - 'Original', - 'Translated frontend ja_JP', - ], // new style load 'gettext load en' => [ 'en_US.UTF-8', - __DIR__ . 'includes/locale/', 'frontend', - false, + __DIR__ . 'includes/locale/', + // 'en_US.UTF-8', 'frontend', null, @@ -133,9 +109,9 @@ final class CoreLibsLanguageL10nTest extends TestCase ], 'gettext load en' => [ 'en_US.UTF-8', - __DIR__ . 'includes/locale/', 'frontend', - false, + __DIR__ . 'includes/locale/', + // 'en_US.UTF-8', 'frontend', 'context', @@ -144,32 +120,33 @@ final class CoreLibsLanguageL10nTest extends TestCase ], 'gettext load ja' => [ 'ja_JP.UTF-8', - __DIR__ . 'includes/locale/', 'admin', - false, + __DIR__ . 'includes/locale/', + // 'ja_JP.UTF-8', 'admin', null, 'Original', 'Translated admin ja_JP', ], - // null set locale legacy - 'empty load legacy' => [ - null, - null, - null, - null, - '', - '', - null, - 'Original', + // mixed path and domain + 'mixed path and domain' => [ + 'en_US.UTF-8', + __DIR__ . 'includes/locale/', + 'frontend', + // + 'en_US.UTF-8', + 'frontend', + 'context', 'Original', + 'Original context frontend en_US', ], + // null set 'empty load new ' => [ '', '', '', - false, + // '', '', null, @@ -187,9 +164,8 @@ final class CoreLibsLanguageL10nTest extends TestCase * @testdox check l10n init with Locale $locale, Path $path, Domain $domain, Legacy: $legacy with $context [$_dataName] * * @param string|null $locale - * @param string|null $path * @param string|null $domain - * @param bool|null $legacy + * @param string|null $path * @param string $locale_expected * @param string $domain_expected * @param ?string $context @@ -199,9 +175,8 @@ final class CoreLibsLanguageL10nTest extends TestCase */ public function testL10nObject( ?string $locale, - ?string $path, ?string $domain, - ?bool $legacy, + ?string $path, string $locale_expected, string $domain_expected, ?string $context, @@ -210,14 +185,12 @@ final class CoreLibsLanguageL10nTest extends TestCase ): void { if ($locale === null) { $l10n = new \CoreLibs\Language\L10n(); - } elseif ($path === null) { - $l10n = new \CoreLibs\Language\L10n($locale); } elseif ($domain === null) { - $l10n = new \CoreLibs\Language\L10n($locale, $path); - } elseif ($legacy === null) { - $l10n = new \CoreLibs\Language\L10n($locale, $path, $domain); + $l10n = new \CoreLibs\Language\L10n($locale); + } elseif ($path === null) { + $l10n = new \CoreLibs\Language\L10n($locale, $domain); } else { - $l10n = new \CoreLibs\Language\L10n($locale, $path, $domain, $legacy); + $l10n = new \CoreLibs\Language\L10n($locale, $domain, $path); } // print "LOC: " . $locale . ", " . $l10n->getLocale() . ", " . $locale_expected . "\n"; // print "MO: " . $l10n->getMoFile() . "\n"; @@ -259,94 +232,64 @@ final class CoreLibsLanguageL10nTest extends TestCase { return [ // 0: locale - // 1: path - // 2: domain - // 3: legacy flag + // 1: domain + // 2: path + // 3: load error // 4: input string to translated // 5: expected locale // 6: expected domain // 7: expected translation // 8: change locale - // 9: change path - // 10: change domain - // 11: legacy flag + // 9: change domain + // 10: change path + // 11: change load error // 12: expected locale // 13: expected domain // 14: expected translation - 'legacy load and change (en->ja)' => [ - // set 0-3 - 'en_utf8', - null, - null, - null, - // status 4 - false, - // to translate 5 - 'Original', - // check setter 6-8 - 'en_utf8', - '', - 'Translated frontend en_US', - // set new 9-12 - 'ja_utf8', - null, - null, - null, - // status new 13 - false, - // check new setter 14-16 - 'ja_utf8', - '', - 'Translated frontend ja_JP', - ], 'load and change (en->ja)' => [ - // set 0-3 + // set 0-2 'en_US.UTF-8', - __DIR__ . 'includes/locale/', 'frontend', + __DIR__ . 'includes/locale/', + // status 3 false, - // status 4 - false, - // to translate 5 + // to translate 4 'Original', - // check setter 6-8 + // check setter 5-7 'en_US.UTF-8', 'frontend', 'Translated frontend en_US', - // set new 9-12 + // set new 8-10 'ja_JP.UTF-8', - __DIR__ . 'includes/locale/', 'frontend', + __DIR__ . 'includes/locale/', + // status new 11 false, - // status new 13 - false, - // check new setter 14-16 + // check new setter 12-14 'ja_JP.UTF-8', 'frontend', 'Translated frontend ja_JP', ], 'empty load and change to en' => [ - // set 0-3 + // set 0-2 '', '', '', + // status 3 false, - // status 4 - false, - // to translate 5 + // to translate 4 'Original', - // check setter 6-8 + // check setter 5-7 '', '', 'Original', - // set new 9-12 + // set new 8-10 'en_US.UTF-8', - __DIR__ . 'includes/locale/', 'frontend', + __DIR__ . 'includes/locale/', + // status new 11 false, - // status new 13 - false, - // check new setter 14-16 + // check new setter 12-14 'en_US.UTF-8', 'frontend', 'Translated frontend en_US', @@ -363,18 +306,16 @@ final class CoreLibsLanguageL10nTest extends TestCase * @testdox change locale from $locale and domain $domain to locale $locale_new and domain $domain_new [$_dataName] * * @param string|null $locale - * @param string|null $path * @param string|null $domain - * @param bool|null $legacy + * @param string|null $path * @param bool $load_error * @param string $original * @param string $locale_expected_a * @param string $domain_expected_a * @param string $translated_a * @param string|null $locale_new - * @param string|null $path_new * @param string|null $domain_new - * @param bool|null $legacy_new + * @param string|null $path_new * @param bool $load_error_new * @param string $locale_expected_b * @param string $domain_expected_b @@ -382,41 +323,37 @@ final class CoreLibsLanguageL10nTest extends TestCase * @return void */ public function testGetTranslator( - // 0-3 + // 0-2 ?string $locale, - ?string $path, ?string $domain, - ?bool $legacy, - // 4 + ?string $path, + // 3 bool $load_error, - // 5 + // 4 string $original, - // 6-8 + // 5-7 string $locale_expected_a, string $domain_expected_a, string $translated_a, - // 9-12 + // 8-10 ?string $locale_new, - ?string $path_new, ?string $domain_new, - ?bool $legacy_new, - // 13 + ?string $path_new, + // 11 bool $load_error_new, - // 14-16 + // 12-14 string $locale_expected_b, string $domain_expected_b, string $translated_b, ): void { if ($locale === null) { $l10n = new \CoreLibs\Language\L10n(); - } elseif ($path === null) { - $l10n = new \CoreLibs\Language\L10n($locale); } elseif ($domain === null) { - $l10n = new \CoreLibs\Language\L10n($locale, $path); - } elseif ($legacy === null) { - $l10n = new \CoreLibs\Language\L10n($locale, $path, $domain); + $l10n = new \CoreLibs\Language\L10n($locale); + } elseif ($path === null) { + $l10n = new \CoreLibs\Language\L10n($locale, $domain); } else { - $l10n = new \CoreLibs\Language\L10n($locale, $path, $domain, $legacy); + $l10n = new \CoreLibs\Language\L10n($locale, $domain, $path); } // print "LOC: " . $locale . ", " . $l10n->getLocale() . ", " . $locale_expected . "\n"; // status check @@ -441,67 +378,39 @@ final class CoreLibsLanguageL10nTest extends TestCase 'Translated string init assert failed' ); - // do reload with legacy l10nReloadMOfile IF legacy is null or true - // use getTranslator if legacy is false - if ($legacy === null || $legacy === true) { - // there is no null/empty locale allowed directly - // if empty will set previous one - if ($path_new === null) { - $ret_status = $l10n->l10nReloadMOfile($locale_new); - } elseif ($domain_new === null) { - $ret_status = $l10n->l10nReloadMOfile($locale_new, $path_new); - } elseif ($legacy_new === null) { - $ret_status = $l10n->l10nReloadMOfile($locale_new, $path_new, $domain_new); - } else { - $ret_status = $l10n->l10nReloadMOfile($locale_new, $path_new, $domain_new, $legacy_new); - } - // status check - $this->assertEquals( - $load_error_new, - $l10n->getLoadError(), - 'Legacy method load error change check' - ); - // retun status check is inverted to load error check - $this->assertEquals( - $load_error_new ? false : true, - $ret_status, - 'Legacy return load error change check' - ); + // switch + if ($locale_new === null) { + $translator = $l10n->getTranslator(); + } elseif ($domain_new === null) { + $translator = $l10n->getTranslator($locale_new); + } elseif ($path_new === null) { + $translator = $l10n->getTranslator($locale_new, $domain_new); } else { - if ($locale_new === null) { - $translator = $l10n->getTranslator(); - } elseif ($path_new === null) { - $translator = $l10n->getTranslator($locale_new); - } elseif ($domain_new === null) { - $translator = $l10n->getTranslator($locale_new, $path_new); - } elseif ($legacy_new === null) { - $translator = $l10n->getTranslator($locale_new, $path_new, $domain_new); - } else { - $translator = $l10n->getTranslator($locale_new, $path_new, $domain_new, $legacy_new); - } - // status check - $this->assertEquals( - $load_error_new, - $l10n->getLoadError(), - 'Translate method load error change check' - ); - // check that returned is class GetTextReader and object - $this->assertIsObject( - $translator, - 'translater class is object assert failed' - ); - $this->assertInstanceOf( - '\CoreLibs\Language\Core\GetTextReader', - $translator, - 'translator class is correct instance assert failed' - ); - // translator class - $this->assertEquals( - $translated_b, - $translator->gettext($original), - 'Translated string change assert failed from returned class' - ); + $translator = $l10n->getTranslator($locale_new, $domain_new, $path_new); } + // status check + $this->assertEquals( + $load_error_new, + $l10n->getLoadError(), + 'Translate method load error change check' + ); + // check that returned is class GetTextReader and object + $this->assertIsObject( + $translator, + 'translater class is object assert failed' + ); + $this->assertInstanceOf( + '\CoreLibs\Language\Core\GetTextReader', + $translator, + 'translator class is correct instance assert failed' + ); + + // translator class + $this->assertEquals( + $translated_b, + $translator->gettext($original), + 'Translated string change assert failed from returned class' + ); // new set check $this->assertEquals( $locale_expected_b, @@ -520,16 +429,14 @@ final class CoreLibsLanguageL10nTest extends TestCase ); } - // TODO: test all translation types - // __/gettext - // __n/ngettext + // TODO: domain based // ->dgettext // ->dngettext // ->dpgettext // ->dpngettext /** - * Undocumented function + * for plural and plural context * * @return array */ @@ -579,9 +486,10 @@ final class CoreLibsLanguageL10nTest extends TestCase } /** - * Undocumented function + * plural and plural context * * @covers ::__n + * @covers ::__pn * @dataProvider ngettextProvider * @testdox plural string test for locale $locale and domain $domain with $context [$_dataName] * @@ -640,21 +548,39 @@ final class CoreLibsLanguageL10nTest extends TestCase 'en', [ 'en', - ] + ], + [ + 'lang' => 'en', + 'country' => null, + 'charset' => null, + 'modifier' => null, + ], ], 'en.UTF-8' => [ 'en.UTF-8', [ 'en.UTF-8', 'en', - ] + ], + [ + 'lang' => 'en', + 'country' => null, + 'charset' => 'UTF-8', + 'modifier' => null, + ], ], 'en_US' => [ 'en_US', [ 'en_US', 'en', - ] + ], + [ + 'lang' => 'en', + 'country' => 'US', + 'charset' => null, + 'modifier' => null, + ], ], 'en_US.UTF-8' => [ 'en_US.UTF-8', @@ -662,7 +588,13 @@ final class CoreLibsLanguageL10nTest extends TestCase 'en_US.UTF-8', 'en_US', 'en', - ] + ], + [ + 'lang' => 'en', + 'country' => 'US', + 'charset' => 'UTF-8', + 'modifier' => null, + ], ], 'en_US@subtext' => [ 'en_US@subtext', @@ -671,7 +603,13 @@ final class CoreLibsLanguageL10nTest extends TestCase 'en@subtext', 'en_US', 'en', - ] + ], + [ + 'lang' => 'en', + 'country' => 'US', + 'charset' => null, + 'modifier' => 'subtext', + ], ], 'en_US.UTF-8@subtext' => [ 'en_US.UTF-8@subtext', @@ -682,7 +620,13 @@ final class CoreLibsLanguageL10nTest extends TestCase 'en_US.UTF-8', 'en_US', 'en', - ] + ], + [ + 'lang' => 'en', + 'country' => 'US', + 'charset' => 'UTF-8', + 'modifier' => 'subtext', + ], ] ]; } @@ -695,16 +639,24 @@ final class CoreLibsLanguageL10nTest extends TestCase * @testdox check $locale [$_dataName] * * @param string $locale - * @param array $expected + * @param array $expected_list + * @param array $expected_detail * @return void */ - public function testListLocales(string $locale, array $expected): void + public function testListLocales(string $locale, array $expected_list, array $expected_detail): void { + $locale_detail = \CoreLibs\Language\L10n::parseLocale($locale); + $this->assertEquals( + $expected_detail, + $locale_detail, + 'Parse local assert failed' + ); $locale_list = \CoreLibs\Language\L10n::listLocales($locale); // print "LOCALES: " . print_r($locale_list, true) . "\n"; $this->assertEquals( - $expected, - $locale_list + $expected_list, + $locale_list, + 'List locale assert failed' ); } @@ -971,23 +923,23 @@ final class CoreLibsLanguageL10nTest extends TestCase { return [ // 0: lang/locale - // 1: path - // 2: domain + // 1: domain + // 2: path // 3: encoding // 4: string // 5: translated string 'standard en' => [ 'en_US.UTF-8', - __DIR__ . 'includes/locale/', 'frontend', + __DIR__ . 'includes/locale/', 'UTF-8', 'Original', 'Translated frontend en_US', ], 'standard ja' => [ 'ja_JP.UTF-8', - __DIR__ . 'includes/locale/', 'admin', + __DIR__ . 'includes/locale/', 'UTF-8', 'Original', 'Translated admin ja_JP', @@ -1008,8 +960,8 @@ final class CoreLibsLanguageL10nTest extends TestCase * @dataProvider functionsProvider * @testdox check functions with locale $locale and domain $domain [$_dataName] * @param string $locale - * @param string $path * @param string $domain + * @param string $path * @param string $encoding * @param string $original * @param string $translated @@ -1017,8 +969,8 @@ final class CoreLibsLanguageL10nTest extends TestCase */ public function testFunctions( string $locale, - string $path, string $domain, + string $path, string $encoding, string $original, string $translated diff --git a/4dev/tests/includes/lang/admin/en_utf8.mo b/4dev/tests/includes/lang/admin/en_utf8.mo deleted file mode 120000 index d3db0998..00000000 --- a/4dev/tests/includes/lang/admin/en_utf8.mo +++ /dev/null @@ -1 +0,0 @@ -../../locale/en_US/LC_MESSAGES/admin.mo \ No newline at end of file diff --git a/4dev/tests/includes/lang/admin/ja_utf8.mo b/4dev/tests/includes/lang/admin/ja_utf8.mo deleted file mode 120000 index 1da0d2df..00000000 --- a/4dev/tests/includes/lang/admin/ja_utf8.mo +++ /dev/null @@ -1 +0,0 @@ -../../locale/ja_JP/LC_MESSAGES/admin.mo \ No newline at end of file diff --git a/4dev/tests/includes/lang/frontend/en_utf8.mo b/4dev/tests/includes/lang/frontend/en_utf8.mo deleted file mode 120000 index 0cc45273..00000000 --- a/4dev/tests/includes/lang/frontend/en_utf8.mo +++ /dev/null @@ -1 +0,0 @@ -../../locale/en_US/LC_MESSAGES/frontend.mo \ No newline at end of file diff --git a/4dev/tests/includes/lang/frontend/ja_utf8.mo b/4dev/tests/includes/lang/frontend/ja_utf8.mo deleted file mode 120000 index 872a56bc..00000000 --- a/4dev/tests/includes/lang/frontend/ja_utf8.mo +++ /dev/null @@ -1 +0,0 @@ -../../locale/ja_JP/LC_MESSAGES/frontend.mo \ No newline at end of file diff --git a/www/admin/class_test.admin.backend.php b/www/admin/class_test.admin.backend.php index cac3c501..0cb82b66 100644 --- a/www/admin/class_test.admin.backend.php +++ b/www/admin/class_test.admin.backend.php @@ -43,7 +43,13 @@ $log = new CoreLibs\Debug\Logging([ ]); // db config with logger $db = new CoreLibs\DB\IO(DB_CONFIG, $log); -$backend = new CoreLibs\Admin\Backend($db, $log); +$locale = \CoreLibs\Language\GetLocale::setLocale(); +$l10n = new \CoreLibs\Language\L10n( + $locale['locale'], + $locale['domain'], + $locale['path'], +); +$backend = new CoreLibs\Admin\Backend($db, $log, $l10n, $locale); print ""; print "TEST CLASS: ADMIN BACKEND"; @@ -51,7 +57,7 @@ print ""; print '
Class Test Master
'; // set acl, from eg login acl -print "SETACL[]: " . $backend->setACL([]) . "
"; +print "SETACL[]: " . $backend->setACL(['EMPTY' => 'EMPTY']) . "
"; print "ADBEDITLOG: " . $backend->adbEditLog('CLASSTEST-ADMIN', 'Some info stirng') . "
"; print "ADBTOPMENU(0): " . \CoreLibs\Debug\Support::printAr($backend->adbTopMenu()) . "
"; print "ADBMSG: " . $backend->adbMsg('info', 'Message: %1$d', [1]) . "
"; diff --git a/www/admin/class_test.lang.php b/www/admin/class_test.lang.php index b672478c..5e9ee78c 100644 --- a/www/admin/class_test.lang.php +++ b/www/admin/class_test.lang.php @@ -19,8 +19,6 @@ ob_start(); // basic class test file define('USE_DATABASE', false); -// init language -$lang = 'en_utf8'; // sample config require 'config.php'; // set session name @@ -37,69 +35,43 @@ print ""; print '
Class Test Master
'; use CoreLibs\Language\L10n; - -$string = 'INPUT TEST'; - -echo "
LEGACY TEST
"; - -$lang = 'en_utf8'; -$l = new CoreLibs\Language\L10n($lang); -echo "*
"; -echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "
"; -echo "LANGUAGE FILE: " . $l->getMoFile() . "
"; -echo "LOAD ERROR: " . $l->getLoadError() . "
"; -echo "INPUT TEST: " . $string . " => " . $l->__($string) . "
"; -$single_string = 'single'; -$multi_string = 'multi'; -for ($n = 0; $n <= 3; $n++) { - echo "MULTI TEST $n: " . $single_string . "/" . $multi_string . " => " - . $l->__n($single_string, $multi_string, $n) . "
"; -} -$context = "month name"; -$context_string = "May"; -echo "CONTEXT TRANSLATION: " . $context_string . " => " . $l->__p($context, $context_string) . "
"; -$single_string = 'single'; -$multi_string = 'multi'; -for ($n = 0; $n <= 3; $n++) { - echo "CONTEXT MULTI TEST $n: " . $single_string . "/" . $multi_string . " => " - . $l->__pn($context, $single_string, $multi_string, $n) . "
"; -} - -// switch to other language -$lang = 'ja_utf8'; -$l->l10nReloadMOfile($lang); -echo "*
"; -echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "
"; -echo "LANGUAGE FILE: " . $l->getMoFile() . "
"; -echo "LOAD ERROR: " . $l->getLoadError() . "
"; -echo "INPUT TEST: " . $string . " => " . $l->__($string) . "
"; -// switch to non existing language -$lang = 'tr_utf8'; -$l->l10nReloadMOfile($lang); -echo "*
"; -echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "
"; -echo "LANGUAGE FILE: " . $l->getMoFile() . "
"; -echo "LOAD ERROR: " . $l->getLoadError() . "
"; -echo "INPUT TEST: " . $string . " => " . $l->__($string) . "
"; +use CoreLibs\Debug\Support; echo "
LIST LOCALES
"; $locale = 'en_US.UTF-8'; $locales = CoreLibs\Language\L10n::listLocales($locale); -print "[" . $locale . "] LOCALES: " . CoreLibs\Debug\Support::printAr($locales) . "
"; +print "[" . $locale . "] LOCALES: " . Support::printAr($locales) . "
"; $locale = 'en.UTF-8'; $locales = CoreLibs\Language\L10n::listLocales($locale); -print "[" . $locale . "] LOCALES: " . CoreLibs\Debug\Support::printAr($locales) . "
"; +print "[" . $locale . "] LOCALES: " . Support::printAr($locales) . "
"; + +echo "
LOCALE INFO
"; +$locale = 'en_US.UTF-8'; +$locale_info = CoreLibs\Language\L10n::parseLocale($locale); +print "[" . $locale . "] INFO: " . Support::printAr($locale_info) . "
"; +$locale = 'en.UTF-8'; +$locale_info = CoreLibs\Language\L10n::parseLocale($locale); +print "[" . $locale . "] INFO: " . Support::printAr($locale_info) . "
"; + +echo "
AUTO DETECT
"; + +$get_locale = \CoreLibs\Language\GetLocale::setLocale(); +print "[AUTO]: " . Support::printAr($get_locale) . "
"; +$get_locale = \CoreLibs\Language\GetLocale::setLocale('en', 'foo', 'ISO-8895'); +print "[OVERRIDE]: " . Support::printAr($get_locale) . "
"; // try to load non existing echo "
NEW TYPE
"; +// translate string +$string = 'INPUT TEST'; // new path test $lang = 'ja'; $domain = 'admin'; $encoding = 'UTF-8'; $path = BASE . INCLUDES . LOCALE; -$l = new CoreLibs\Language\L10n($lang, $path, $domain, false); - +// load direct +$l = new CoreLibs\Language\L10n($lang, $domain, $path); echo "*
"; echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "
"; echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "
"; @@ -116,9 +88,45 @@ for ($n = 0; $n <= 3; $n++) { echo "MULTI TEST $n: " . $single_string . "/" . $multi_string . " => " . $l->__n($single_string, $multi_string, $n) . "
"; } - +$context = "month name"; +$context_string = "May"; +echo "CONTEXT TRANSLATION: " . $context_string . " => " . $l->__p($context, $context_string) . "
"; +$single_string = 'single'; +$multi_string = 'multi'; +for ($n = 0; $n <= 3; $n++) { + echo "CONTEXT MULTI TEST $n: " . $single_string . "/" . $multi_string . " => " + . $l->__pn($context, $single_string, $multi_string, $n) . "
"; +} +// change domain $domain = 'frontend'; -$l->getTranslator('', $path, $domain); +$l->getTranslator('', $domain, $path); +echo "*
"; +echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "
"; +echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "
"; +echo "LANGUAGE FILE: " . $l->getMoFile() . "
"; +echo "CONTENT PATH: " . $l->getBaseContentPath() . "
"; +echo "DOMAIN PATH: " . $l->getTextDomain($domain) . "
"; +echo "BASE PATH: " . $l->getBaseLocalePath() . "
"; +echo "LOAD ERROR: " . $l->getLoadError() . "
"; +echo "INPUT TEST: " . $string . " => " . $l->__($string) . "
"; +echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "
"; +// change language short type +$lang = 'en'; +$domain = 'admin'; +$l->getTranslator($lang, $domain, $path); +echo "*
"; +echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "
"; +echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "
"; +echo "LANGUAGE FILE: " . $l->getMoFile() . "
"; +echo "CONTENT PATH: " . $l->getBaseContentPath() . "
"; +echo "DOMAIN PATH: " . $l->getTextDomain($domain) . "
"; +echo "BASE PATH: " . $l->getBaseLocalePath() . "
"; +echo "LOAD ERROR: " . $l->getLoadError() . "
"; +echo "INPUT TEST: " . $string . " => " . $l->__($string) . "
"; +echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "
"; +// chang to wrong language +$lang = 'tr'; +$l->getTranslator($lang, $domain, $path); echo "*
"; echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "
"; echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "
"; diff --git a/www/admin/class_test.php b/www/admin/class_test.php index 24b27ff9..206921c6 100644 --- a/www/admin/class_test.php +++ b/www/admin/class_test.php @@ -41,7 +41,13 @@ $log = new CoreLibs\Debug\Logging([ ]); $db = new CoreLibs\DB\IO(DB_CONFIG, $log); $login = new CoreLibs\ACL\Login($db, $log); -$backend = new CoreLibs\Admin\Backend($db, $log); +$locale = \CoreLibs\Language\GetLocale::setLocale(); +$l10n = new \CoreLibs\Language\L10n( + $locale['locale'], + $locale['domain'], + $locale['path'], +); +$backend = new CoreLibs\Admin\Backend($db, $log, $l10n, $locale); $backend->db->dbInfo(true); ob_end_flush(); @@ -79,9 +85,10 @@ print '
Class Test: SMARTY
'; print '
Class Test: AUTOLOADER
'; print "
"; +print "L: " . CoreLibs\Debug\Support::printAr($locale) . "
"; // print all _ENV vars set print "
READ _ENV ARRAY:
"; -print "
" . print_r(array_map('htmlentities', $_ENV), true) . "
"; +print CoreLibs\Debug\Support::printAr(array_map('htmlentities', $_ENV)); // set + check edit access id $edit_access_id = 3; if (is_object($login) && isset($login->acl['unit'])) { diff --git a/www/admin/class_test.smarty.php b/www/admin/class_test.smarty.php index f1cf2df0..95fd065f 100644 --- a/www/admin/class_test.smarty.php +++ b/www/admin/class_test.smarty.php @@ -19,8 +19,6 @@ ob_start(); // basic class test file define('USE_DATABASE', true); -// set language -$lang = 'en_utf8'; // sample config require 'config.php'; // override ECHO ALL FALSE @@ -43,8 +41,13 @@ $log = new CoreLibs\Debug\Logging([ 'echo_all' => $ECHO_ALL ?? false, 'print_all' => $PRINT_ALL ?? false, ]); -$smarty = new CoreLibs\Template\SmartyExtend(); -$l = new CoreLibs\Language\L10n($lang); +$locale = \CoreLibs\Language\GetLocale::setLocale(); +$l10n = new \CoreLibs\Language\L10n( + $locale['locale'], + $locale['domain'], + $locale['path'], +); +$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale); print ""; print "TEST CLASS: SMARTY"; @@ -70,7 +73,7 @@ $smarty->setSmartyPaths(); // smarty test $smarty->DATA['SMARTY_TEST'] = 'Test Data'; -$smarty->DATA['TRANSLATE_TEST'] = $l->__('Are we translated?'); +$smarty->DATA['TRANSLATE_TEST'] = $l10n->__('Are we translated?'); $smarty->DATA['TRANSLATE_TEST_SMARTY'] = $smarty->l10n->__('Are we translated?'); $smarty->DATA['replace'] = 'Replaced'; // variable variables diff --git a/www/includes/Date.Vars.php b/www/includes/Date.Vars.php deleted file mode 100644 index 1da8c113..00000000 --- a/www/includes/Date.Vars.php +++ /dev/null @@ -1,77 +0,0 @@ - 'Mon', - 2 => 'Tue', - 3 => 'Wed', - 4 => 'Thu', - 5 => 'Fri', - 6 => 'Sat', - 7 => 'Sun' -]; - -$day_long = [ - 1 => 'Monday', - 2 => 'Tuesday', - 3 => 'Wednesday', - 4 => 'Thursday', - 5 => 'Friday', - 6 => 'Saturday', - 7 => 'Sunday' -]; - -// months -$month_long = [ - 1 => 'January', - 2 => 'February', - 3 => 'March', - 4 => 'April', - 5 => 'May', - 6 => 'June', - 7 => 'July', - 8 => 'August', - 9 => 'September', - 10 => 'October', - 11 => 'November', - 12 => 'December' -]; - -$month_short = [ - 1 => 'Jan', - 2 => 'Feb', - 3 => 'Mar', - 4 => 'Apr', - 5 => 'May', - 6 => 'Jun', - 7 => 'Jul', - 8 => 'Aug', - 9 => 'Sep', - 10 => 'Oct', - 11 => 'Nov', - 12 => 'Dec' -]; - -// __END__ diff --git a/www/includes/admin_header.php b/www/includes/admin_header.php index e694fb55..0ae033c6 100644 --- a/www/includes/admin_header.php +++ b/www/includes/admin_header.php @@ -72,10 +72,19 @@ if ( $db = new CoreLibs\DB\IO(DB_CONFIG, $log); // login & page access check $login = new CoreLibs\ACL\Login($db, $log); +// lang, path, domain +// pre auto detect language after login +$locale = \CoreLibs\Language\GetLocale::setLocale(); +// set lang and pass to smarty/backend +$l10n = new \CoreLibs\Language\L10n( + $locale['locale'], + $locale['domain'], + $locale['path'], +); // create smarty object -$smarty = new CoreLibs\Template\SmartyExtend(); +$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale); // create new Backend class with db and loger attached -$cms = new CoreLibs\Admin\Backend($db, $log); +$cms = new CoreLibs\Admin\Backend($db, $log, $l10n, $locale); // the menu show flag (what menu to show) $cms->menu_show_flag = 'main'; // db info diff --git a/www/includes/admin_set_paths.php b/www/includes/admin_set_paths.php deleted file mode 100644 index 9ebc58ff..00000000 --- a/www/includes/admin_set_paths.php +++ /dev/null @@ -1,22 +0,0 @@ -setSmartyPaths();', E_USER_DEPRECATED); -if ($smarty) { - $smarty->setSmartyPaths(); -} - -// __END__ diff --git a/www/includes/admin_smarty.php b/www/includes/admin_smarty.php deleted file mode 100644 index a0d13bcd..00000000 --- a/www/includes/admin_smarty.php +++ /dev/null @@ -1,23 +0,0 @@ -setSmartyVarsAdmin(); or setSmartyVarsFrontend();', - E_USER_DEPRECATED -); -$smarty->setSmartyVarsAdmin(); - -// __END__ diff --git a/www/includes/edit_base.php b/www/includes/edit_base.php index c0c21b6d..7439658d 100644 --- a/www/includes/edit_base.php +++ b/www/includes/edit_base.php @@ -61,18 +61,27 @@ $log = new CoreLibs\Debug\Logging([ $db = new CoreLibs\DB\IO(DB_CONFIG, $log); // login page $login = new CoreLibs\ACL\Login($db, $log); +// lang, path, domain +// pre auto detect language after login +$locale = \CoreLibs\Language\GetLocale::setLocale(); +// set lang and pass to smarty/backend +$l10n = new \CoreLibs\Language\L10n( + $locale['locale'], + $locale['domain'], + $locale['path'], +); // flush and start ob_end_flush(); // turn off set log per class $log->setLogPer('class', false); // create form class -$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $log); +$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $log, $l10n, $locale); if ($form->mobile_phone) { echo "I am sorry, but this page cannot be viewed by a mobile phone"; exit; } // smarty template engine (extended Translation version) -$smarty = new CoreLibs\Template\SmartyExtend(); +$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale); // $form->log->debug('POST', $form->log->prAr($_POST)); diff --git a/www/includes/lang/admin/en_utf8.mo b/www/includes/lang/admin/en_utf8.mo deleted file mode 120000 index d3db0998..00000000 --- a/www/includes/lang/admin/en_utf8.mo +++ /dev/null @@ -1 +0,0 @@ -../../locale/en_US/LC_MESSAGES/admin.mo \ No newline at end of file diff --git a/www/includes/lang/admin/ja_utf8.mo b/www/includes/lang/admin/ja_utf8.mo deleted file mode 120000 index a4aff9e3..00000000 --- a/www/includes/lang/admin/ja_utf8.mo +++ /dev/null @@ -1 +0,0 @@ -../../locale/ja/LC_MESSAGES/admin.mo \ No newline at end of file diff --git a/www/includes/lang/frontend/en_utf8.mo b/www/includes/lang/frontend/en_utf8.mo deleted file mode 120000 index 0cc45273..00000000 --- a/www/includes/lang/frontend/en_utf8.mo +++ /dev/null @@ -1 +0,0 @@ -../../locale/en_US/LC_MESSAGES/frontend.mo \ No newline at end of file diff --git a/www/includes/lang/frontend/ja_utf8.mo b/www/includes/lang/frontend/ja_utf8.mo deleted file mode 120000 index b5d54477..00000000 --- a/www/includes/lang/frontend/ja_utf8.mo +++ /dev/null @@ -1 +0,0 @@ -../../locale/ja/LC_MESSAGES/frontend.mo \ No newline at end of file diff --git a/www/includes/locale/en_US/LC_MESSAGES/admin.mo b/www/includes/locale/en/LC_MESSAGES/admin.mo similarity index 61% rename from www/includes/locale/en_US/LC_MESSAGES/admin.mo rename to www/includes/locale/en/LC_MESSAGES/admin.mo index 6407f2e0..90187b14 100644 Binary files a/www/includes/locale/en_US/LC_MESSAGES/admin.mo and b/www/includes/locale/en/LC_MESSAGES/admin.mo differ diff --git a/www/includes/locale/en/LC_MESSAGES/frontend.mo b/www/includes/locale/en/LC_MESSAGES/frontend.mo new file mode 100644 index 00000000..341f41c5 Binary files /dev/null and b/www/includes/locale/en/LC_MESSAGES/frontend.mo differ diff --git a/www/includes/locale/en_US/LC_MESSAGES/frontend.mo b/www/includes/locale/en_US/LC_MESSAGES/frontend.mo deleted file mode 100644 index 5e0a6ebd..00000000 Binary files a/www/includes/locale/en_US/LC_MESSAGES/frontend.mo and /dev/null differ diff --git a/www/includes/locale/ja/LC_MESSAGES/admin.mo b/www/includes/locale/ja/LC_MESSAGES/admin.mo index 76cd4a38..f78e374b 100644 Binary files a/www/includes/locale/ja/LC_MESSAGES/admin.mo and b/www/includes/locale/ja/LC_MESSAGES/admin.mo differ diff --git a/www/includes/locale/ja/LC_MESSAGES/frontend.mo b/www/includes/locale/ja/LC_MESSAGES/frontend.mo index 07971795..74a71d74 100644 Binary files a/www/includes/locale/ja/LC_MESSAGES/frontend.mo and b/www/includes/locale/ja/LC_MESSAGES/frontend.mo differ diff --git a/www/lib/CoreLibs/ACL/Login.php b/www/lib/CoreLibs/ACL/Login.php index 740db599..0cec702f 100644 --- a/www/lib/CoreLibs/ACL/Login.php +++ b/www/lib/CoreLibs/ACL/Login.php @@ -167,13 +167,10 @@ class Login * constructor, does ALL, opens db, works through connection checks, closes itself * @param \CoreLibs\DB\IO $db Database connection class * @param \CoreLibs\Debug\Logging $log Logging class - * @param \CoreLibs\Language\L10n|null $l10n l10n language class - * if null, auto set */ public function __construct( \CoreLibs\DB\IO $db, - \CoreLibs\Debug\Logging $log, - ?\CoreLibs\Language\L10n $l10n = null + \CoreLibs\Debug\Logging $log ) { // log login data for this class only $log->setLogPer('class', true); @@ -215,19 +212,6 @@ class Login // or need to pass it back // to the continue AJAX class for output back to the user $this->login_is_ajax_page = isset($GLOBALS['AJAX_PAGE']) && $GLOBALS['AJAX_PAGE'] ? true : false; - // set the default lang - $locale = 'en_US.UTF-8'; - $lang = 'en_utf8'; - if (Session::getSessionId() !== false && !empty($_SESSION['DEFAULT_LANG'])) { - $lang = $_SESSION['DEFAULT_LANG']; - $locale = $_SESSION['DEFAULT_LOCALE']; - } else { - $lang = defined('SITE_LANG') && !empty(SITE_LANG) ? - SITE_LANG : DEFAULT_LANG; - $locale = defined('SITE_LOCALE') && !empty(SITE_LOCALE) ? - SITE_LOCALE : DEFAULT_LOCALE; - } - $this->l = $l10n ?? new \CoreLibs\Language\L10n($lang); // if we have a search path we need to set it, to use the correct DB to login // check what schema to use. if there is a login schema use this, else check @@ -300,6 +284,24 @@ class Login $this->loginCheckPermissions(); // logsout user $this->loginLogoutUser(); + // ** LANGUAGE SET AFTER LOGIN ** + // set the locale + if (Session::getSessionId() !== false && !empty($_SESSION['DEFAULT_LANG'])) { + $locale = $_SESSION['DEFAULT_LOCALE'] ?? ''; + } else { + $locale = defined('SITE_LOCALE') && !empty(SITE_LOCALE) ? + SITE_LOCALE : + /** @phpstan-ignore-next-line DEFAULT_LOCALE could be empty */ + (defined('DEFAULT_LOCALE') && !empty(DEFAULT_LOCALE) ? + DEFAULT_LOCALE : 'en.UTF-8'); + } + // set domain + if (defined('CONTENT_PATH') && !empty(CONTENT_PATH)) { + $domain = str_replace('/', '', CONTENT_PATH); + } else { + $domain = 'admin'; + } + $this->l = new \CoreLibs\Language\L10n($locale, $domain); // if the password change flag is okay, run the password change method if ($this->password_change) { $this->loginPasswordChange(); diff --git a/www/lib/CoreLibs/Admin/Backend.php b/www/lib/CoreLibs/Admin/Backend.php index af17c418..a691c41e 100644 --- a/www/lib/CoreLibs/Admin/Backend.php +++ b/www/lib/CoreLibs/Admin/Backend.php @@ -114,15 +114,16 @@ class Backend // CONSTRUCTOR / DECONSTRUCTOR |====================================> /** * main class constructor - * @param \CoreLibs\DB\IO $db Database connection class - * @param \CoreLibs\Debug\Logging $log Logging class - * @param \CoreLibs\Language\L10n|null $l10n l10n language class - * if null, auto set + * @param \CoreLibs\DB\IO $db Database connection class + * @param \CoreLibs\Debug\Logging $log Logging class + * @param \CoreLibs\Language\L10n $l10n l10n language class + * @param array $locale locale data read from setLocale */ public function __construct( \CoreLibs\DB\IO $db, \CoreLibs\Debug\Logging $log, - ?\CoreLibs\Language\L10n $l10n = null + \CoreLibs\Language\L10n $l10n, + array $locale ) { // set to log not per class $log->setLogPer('class', false); @@ -130,10 +131,15 @@ class Backend $this->log = $log; // attach db class $this->db = $db; - // TODO lang create outside of class - $this->setLangEncoding(); // get the language sub class & init it - $this->l = $l10n ?? new \CoreLibs\Language\L10n($this->lang); + $this->l = $l10n; + // parse and read, legacy stuff + $this->encoding = $locale['encoding']; + $this->lang = $locale['lang']; + // get first part from lang + $this->lang_short = explode('_', $locale['lang'])[0]; + $this->domain = $this->l->getDomain(); + $this->lang_dir = $this->l->getBaseLocalePath(); // set the page name $this->page_name = \CoreLibs\Get\System::getPageName(); @@ -159,29 +165,6 @@ class Backend // NO OP } - // INTERNAL METHODS |===============================================> - - /** - * set the language encoding and language settings - * use $OVERRIDE_LANG to override all language settings - * the default charset from _SESSION login or from - * config DEFAULT ENCODING - * the lang full name for mo loading from _SESSION login - * or SITE LANG or DEFAULT LANG from config - * creates short lang (only first two chars) from the lang - * @return void - */ - private function setLangEncoding(): void - { - list ( - $this->encoding, - $this->lang, - $this->lang_short, - $this->domain, - $this->lang_dir - ) = \CoreLibs\Language\GetSettings::setLangEncoding(); - } - // PUBLIC METHODS |=================================================> /** diff --git a/www/lib/CoreLibs/Language/GetLocale.php b/www/lib/CoreLibs/Language/GetLocale.php new file mode 100644 index 00000000..11242508 --- /dev/null +++ b/www/lib/CoreLibs/Language/GetLocale.php @@ -0,0 +1,117 @@ + locale, domain, encoding, path + */ + public static function setLocale( + ?string $locale = null, + ?string $domain = null, + ?string $encoding = null, + ?string $path = null + ): array { + // locale must match at least basic rules + if ( + empty($locale) || + !preg_match("/^[-A-Za-z0-9_.@]+$/", $locale) + ) { + if (!empty($_SESSION['DEFAULT_LOCALE'])) { + // parse from session (logged in) + $locale = $_SESSION['DEFAULT_LOCALE']; + } else { + // else parse from site locale + $locale = defined('SITE_LOCALE') && !empty(SITE_LOCALE) ? + SITE_LOCALE : + // else parse from default, if not 'en' + /** @phpstan-ignore-next-line DEFAULT_LOCALE could be empty */ + (defined('DEFAULT_LOCALE') && !empty(DEFAULT_LOCALE) ? + DEFAULT_LOCALE : 'en'); + } + } + // if domain is set, must be alphanumeric, if not unset + if ( + empty($domain) || + !preg_match("/^\w+$/", $domain) + ) { + // if no domain is set, fall back to content path + $domain = str_replace('/', '', CONTENT_PATH); + } + // check that override encoding matches locale encoding + // if locale encoding is set + preg_match('/(?:\\.(?P[-A-Za-z0-9_]+))/', $locale, $matches); + $locale_encoding = $matches['charset'] ?? null; + if ( + // empty encoding + empty($encoding) || + // not valid encoding + !preg_match("/^[-A-Za-z0-9_]+$/", $encoding) || + // locale encoding set and not matching to encoding + (!empty($locale_encoding) && $encoding != $locale_encoding) + ) { + if (!empty($locale_encoding)) { + $encoding = strtoupper($locale_encoding); + } elseif (!empty($_SESSION['DEFAULT_CHARSET'])) { + // else set from session + $encoding = $_SESSION['DEFAULT_CHARSET']; + } else { + // else set from site encoding + $encoding = defined('SITE_ENCODING') && !empty(SITE_ENCODING) ? + SITE_ENCODING : + // or default encoding, if not 'UTF-8' + /** @phpstan-ignore-next-line DEFAULT_LOCALE could be empty */ + (defined('DEFAULT_ENCODING') && !empty(DEFAULT_ENCODING) ? + DEFAULT_ENCODING : 'UTF-8'); + } + } + // path checks if set, if not valid path unset to default BASE path + if ( + empty($path) || + !is_dir($path) + ) { + $path = BASE . INCLUDES . LOCALE; + } + // extract lang & country from locale string, else set to en + if ( + preg_match( + // lang + '/^(?P[a-z]{2,3})' + // country code + . '(?:_(?P[A-Z]{2}))?/', + $locale, + $matches + ) + ) { + $lang = ($matches['lang'] ?? 'en') + // add country only if set + . (!empty($matches['country']) ? '_' . $matches['country'] : ''); + } else { + $lang = 'en'; + } + return [ + 'locale' => $locale, + 'lang' => $lang, + 'domain' => $domain, + 'encoding' => $encoding, + 'path' => $path, + ]; + } +} + +// __END__ diff --git a/www/lib/CoreLibs/Language/GetSettings.php b/www/lib/CoreLibs/Language/GetSettings.php index 1543ad01..c73598b1 100644 --- a/www/lib/CoreLibs/Language/GetSettings.php +++ b/www/lib/CoreLibs/Language/GetSettings.php @@ -30,6 +30,7 @@ class GetSettings * @param string|null $locale A valid locale name * @param string|null $path A valid path where the mo files will be based * @return array Settings as array/dictionary + * @deprecated Use CoreLibs\Language\GetLocale::setLocale() */ public static function setLangEncoding( ?string $locale = null, diff --git a/www/lib/CoreLibs/Language/L10n.php b/www/lib/CoreLibs/Language/L10n.php index 6b37ab86..f3d48a1e 100644 --- a/www/lib/CoreLibs/Language/L10n.php +++ b/www/lib/CoreLibs/Language/L10n.php @@ -3,34 +3,26 @@ /********************************************************************* * AUTHOR: Clemens Schwaighofer * CREATED: 2004/11/18 -* VERSION: 1.0.0 +* VERSION: 3.0.0 * RELEASED LICENSE: GNU GPL 3 * SHORT DESCRIPTION: -* init class for gettext. Original was just a function & var setting include for wordpress. +* init class for gettext. Original was just a function & +* var setting include for wordpress. * I changed that to a class to be more portable with my style of coding -* -* PUBLIC VARIABLES -* -* PRIVATE VARIABLES -* +* VERSION 3.0 (2022/4) removes all old folder layout and uses standard gettext * PUBLIC METHODS -* __: returns string (translated or original if not found) -* __e: echos out string (translated or original if not found) -* __n: should return plural. never tested this. -* -* PRIVATE METHODS +* __ : returns string (translated or original if not found) +* __n : plural string +* __p : string with context +* __pb: string with context and plural * * HISTORY: +* 2022/4/15 (cs) drop all old folder layout support, new folder base +* in locale with standard gettext layout of +* locale/LC_MESSAGES/domain.mo * 2005/10/17 (cs) made an on the fly switch method (reload of lang) *********************************************************************/ -// TODO: default path change to /lang/LC_MESSAGES/domain.encoding.mo -// for example: lang: ja_JP.UTF-8, domain: admin -// /ja_JP/LC_MESSAGES/admin.UTF-8.mo -// OLD: includes/lang/admin/ja_utf8.mo -// NEW: includes/lang/ja_JP/LC_MESSAGES/admin.UTF-8.mo -// or fallback: includes/lang/ja/LC_MESSAGES/admin.UTF-8.mo - declare(strict_types=1); namespace CoreLibs\Language; @@ -48,15 +40,20 @@ class L10n private $domains = []; /** @var array bound paths for domains */ private $paths = ['' => './']; + + // files /** @var string the full path to the mo file to loaded */ private $mofile = ''; /** @var string base path to search level */ private $base_locale_path = ''; /** @var string dynamic set path to where the mo file is actually */ private $base_content_path = ''; + + // errors /** @var bool if load of mo file was unsuccessful */ private $load_failure = false; + // object holders /** @var FileReader|bool reader class for file reading, false for short circuit */ private $input = false; /** @var GetTextReader reader class for MO data */ @@ -74,20 +71,24 @@ class L10n * * @param string $locale language name, default empty string * will return self instance - * @param string $path path, if empty fallback on default internal path * @param string $domain override CONTENT_PATH . $encoding name for mo file - * @param bool $legacy default true, if set to true, will look in the old - * folder format lang/ CONTENT_PATH / $lang . mo + * @param string $path path, if empty fallback on default internal path */ public function __construct( string $locale = '', - string $path = '', string $domain = '', - bool $legacy = true + string $path = '', ) { - // load the mo file if locale is not empty - if (!empty($locale)) { - $this->getTranslator($locale, $path, $domain, $legacy); + // auto load language only if at least locale and domain is set + if (!empty($locale) && !empty($domain)) { + // check hack if domain and path is switched + // Note this can be removed in future versions + if (strstr($domain, DIRECTORY_SEPARATOR) !== false) { + $_domain = $path; + $path = $domain; + $domain = $_domain; + } + $this->getTranslator($locale, $domain, $path); } } @@ -116,43 +117,18 @@ class L10n require_once __DIR__ . '/l10n_functions.php'; } - /** - * legacy loader name for getTranslator - * instead of returning the GetTextReader object it returns - * true or false for successful load. - * NOTE: some time down the road this will be deprecated - * - * @param string $locale - * @param string $path - * @param string $domain - * @param bool $legacy - * @return bool Returns true for successfull load, false for error - */ - public function l10nReloadMOfile( - string $locale, - string $path = '', - string $domain = '', - bool $legacy = true - ): bool { - $this->getTranslator($locale, $path, $domain, $legacy); - return $this->load_failure ? false : true; - } - /** * loads the mo file base on path, locale and domain set * * @param string $locale language name (optional), fallback is en - * @param string $path path, if empty fallback on default internal path * @param string $domain override CONTENT_PATH . $encoding name for mo file - * @param bool $legacy default true, if set to true, will look in the old - * folder format lang/ CONTENT_PATH / $lang . mo + * @param string $path path, if empty fallback on default internal path * @return GetTextReader the main gettext reader object */ public function getTranslator( string $locale = '', - string $path = '', string $domain = '', - bool $legacy = false + string $path = '' ): GetTextReader { // set local if not from parameter if (empty($locale)) { @@ -169,48 +145,34 @@ class L10n $old_base_locale_path = $this->base_locale_path; $old_base_content_path = $this->base_content_path; - // legacy or new type - // legacy will use the old lang/content/file.mo type as default - // if path is not set, also locale is the file name - // for new type it follows the gettext spec and path is just the - // base folder where the mo files will be searched - if ($legacy === true) { - if (!is_dir($path)) { - $this->base_locale_path = BASE . INCLUDES . LANG; - $this->base_content_path = CONTENT_PATH; - $path = $this->base_locale_path . $this->base_content_path; - } - $this->mofile = $path . $locale . ".mo"; + // if path is a dir + // 1) from a previous set domain + // 2) from method option as is + // 3) fallback if BASE/INCLUDES/LOCALE set + // 4) current dir + if (!empty($this->paths[$domain]) && is_dir($this->paths[$domain])) { + $this->base_locale_path = $this->paths[$domain]; + } elseif (is_dir($path)) { + $this->base_locale_path = $path; + } elseif ( + defined('BASE') && defined('INCLUDES') && defined('LOCALE') + ) { + // set fallback base path if constant set + $this->base_locale_path = BASE . INCLUDES . LOCALE; } else { - // if new path is a dir - // 1) from a previous set domain - // 2) from method option as is - // 3) fallback if BASE/INCLUDES/LOCALE set - // 4) current dir - if (!empty($this->paths[$domain]) && is_dir($this->paths[$domain])) { - $this->base_locale_path = $this->paths[$domain]; - } elseif (is_dir($path)) { - $this->base_locale_path = $path; - } elseif ( - defined('BASE') && defined('INCLUDES') && defined('LOCALE') - ) { - // set fallback base path if constant set - $this->base_locale_path = BASE . INCLUDES . LOCALE; - } else { - $this->base_locale_path = './'; - } - // now we loop over lang compositions to get the base path - // then we check - $locales = $this->listLocales($locale); - foreach ($locales as $_locale) { - $this->base_content_path = $_locale . DIRECTORY_SEPARATOR - . 'LC_MESSAGES' . DIRECTORY_SEPARATOR; - $this->mofile = $this->base_locale_path - . $this->base_content_path - . $domain . '.mo'; - if (file_exists($this->mofile)) { - break; - } + $this->base_locale_path = './'; + } + // now we loop over lang compositions to get the base path + // then we check + $locales = $this->listLocales($locale); + foreach ($locales as $_locale) { + $this->base_content_path = $_locale . DIRECTORY_SEPARATOR + . 'LC_MESSAGES' . DIRECTORY_SEPARATOR; + $this->mofile = $this->base_locale_path + . $this->base_content_path + . $domain . '.mo'; + if (file_exists($this->mofile)) { + break; } } @@ -273,6 +235,34 @@ class L10n return $this->l10n; } + /** + * parse the locale string for further processing + * + * @param string $locale Locale to parse + * @return array array with lang, country, charset, modifier + */ + public static function parseLocale(string $locale = ''): array + { + preg_match( + // language code + '/^(?P[a-z]{2,3})' + // country code + . '(?:_(?P[A-Z]{2}))?' + // charset + . '(?:\\.(?P[-A-Za-z0-9_]+))?' + // @ modifier + . '(?:@(?P[-A-Za-z0-9_]+))?$/', + $locale, + $matches + ); + return [ + 'lang' => $matches['lang'] ?? null, + 'country' => $matches['country'] ?? null, + 'charset' => $matches['charset'] ?? null, + 'modifier' => $matches['modifier'] ?? null, + ]; + } + /** * original: * vendor/phpmyadmin/motranslator/src/Loader.php @@ -294,28 +284,16 @@ class L10n return $locale_list; } // is matching regex - if ( - !preg_match( - // language code - '/^(?P[a-z]{2,3})' - // country code - . '(?:_(?P[A-Z]{2}))?' - // charset - . '(?:\\.(?P[-A-Za-z0-9_]+))?' - // @ modifier - . '(?:@(?P[-A-Za-z0-9_]+))?$/', - $locale, - $matches - ) - ) { - // not matching, return as is + $locale_detail = L10n::parseLocale($locale); + // all null = nothing mached, return locale as is + if ($locale_detail === array_filter($locale_detail, 'is_null')) { return [$locale]; } - // do matching run - $lang = $matches['lang'] ?? null; - $country = $matches['country'] ?? null; - $charset = $matches['charset'] ?? null; - $modifier = $matches['modifier'] ?? null; + // write to innteral vars + $lang = $locale_detail['lang']; + $country = $locale_detail['country']; + $charset = $locale_detail['charset']; + $modifier = $locale_detail['modifier']; // we need to add all possible cominations from not null set // entries to the list, from longest to shortest // %s_%s.%s@%s (lang _ country . encoding @ suffix) diff --git a/www/lib/CoreLibs/Output/Form/Generate.php b/www/lib/CoreLibs/Output/Form/Generate.php index ab4643ab..bbab7181 100644 --- a/www/lib/CoreLibs/Output/Form/Generate.php +++ b/www/lib/CoreLibs/Output/Form/Generate.php @@ -299,23 +299,39 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO /** * construct form generator - * @param array $db_config db config array - * @param \CoreLibs\Debug\Logging|null $log Logging class - * @param \CoreLibs\Language\L10n|null $l10n l10n language class - * if null, auto set + * @param array $db_config db config array, mandatory + * @param \CoreLibs\Debug\Logging|null $log Logging class, null auto set + * @param \CoreLibs\Language\L10n|null $l10n l10n language class, null auto set + * @param array|null $locale locale array from ::setLocale, + * null auto set */ public function __construct( array $db_config, - \CoreLibs\Debug\Logging $log = null, - ?\CoreLibs\Language\L10n $l10n = null + ?\CoreLibs\Debug\Logging $log = null, + ?\CoreLibs\Language\L10n $l10n = null, + ?array $locale = null ) { global $table_arrays; // replace any non valid variable names // TODO extract only alphanumeric and _ after . to _ replacement $this->my_page_name = str_replace(['.'], '_', System::getPageName(System::NO_EXTENSION)); - $this->setLangEncoding(); + // if pass on locale is null + if ($locale === null) { + $locale = \CoreLibs\Language\GetLocale::setLocale(); + } // init the language class - $this->l = $l10n ?? new \CoreLibs\Language\L10n($this->lang); + $this->l = $l10n ?? new \CoreLibs\Language\L10n( + $locale['locale'], + $locale['domain'], + $locale['path'], + ); + // legacy lang vars set + $this->encoding = $locale['encoding']; + $this->lang = $locale['lang']; + // get first part from lang + $this->lang_short = explode('_', $locale['lang'])[0]; + $this->domain = $this->l->getDomain(); + $this->lang_dir = $this->l->getBaseLocalePath(); // load config array // get table array definitions for current page name @@ -443,29 +459,6 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO parent::__destruct(); } - // INTERNAL METHODS |===============================================> - - /** - * ORIGINAL in \CoreLibs\Admin\Backend - * set the language encoding and language settings - * the default charset from _SESSION login or from - * config DEFAULT ENCODING - * the lang full name for mo loading from _SESSION login - * or SITE LANG or DEFAULT LANG from config - * creates short lang (only first two chars) from the lang - * @return void - */ - private function setLangEncoding(): void - { - list ( - $this->encoding, - $this->lang, - $this->lang_short, - $this->domain, - $this->lang_dir - ) = \CoreLibs\Language\GetSettings::setLangEncoding(); - } - // PUBLIC METHODS |=================================================> /** diff --git a/www/lib/CoreLibs/Template/SmartyExtend.php b/www/lib/CoreLibs/Template/SmartyExtend.php index 935222d0..b692791a 100644 --- a/www/lib/CoreLibs/Template/SmartyExtend.php +++ b/www/lib/CoreLibs/Template/SmartyExtend.php @@ -154,50 +154,36 @@ class SmartyExtend extends \Smarty * constructor class, just sets the language stuff * calls L10 for pass on internaly in smarty * also registers the getvar caller plugin - * @param \CoreLibs\Language\L10n|null $l10n l10n language class - * if null, auto set + * @param \CoreLibs\Language\L10n $l10n l10n language class + * @param array $locale locale data read from setLocale */ - public function __construct(?\CoreLibs\Language\L10n $l10n = null) + public function __construct(\CoreLibs\Language\L10n $l10n, array $locale) { // call basic smarty // or Smarty::__construct(); parent::__construct(); - // set lang vars - $this->setLangEncoding(); // iinit lang - $this->l10n = $l10n ?? new \CoreLibs\Language\L10n($this->lang); - // Smarty 3.x - // $this->registerPlugin('modifier', 'getvar', [&$this, 'get_template_vars']); + $this->l10n = $l10n; + // opt load functions so we can use legacy init for smarty run perhaps + $this->l10n->loadFunctions(); + // parse and read, legacy stuff + $this->encoding = $locale['encoding']; + $this->lang = $locale['lang']; + // get first part from lang + $this->lang_short = explode('_', $locale['lang'])[0]; + $this->domain = $this->l10n->getDomain(); + $this->lang_dir = $this->l10n->getBaseLocalePath(); + + // register smarty variable $this->registerPlugin('modifier', 'getvar', [&$this, 'getTemplateVars']); - $this->page_name = pathinfo($_SERVER["PHP_SELF"])['basename']; + $this->page_name = \CoreLibs\Get\System::getPageName(); // set internal settings $this->CACHE_ID = defined('CACHE_ID') ? CACHE_ID : ''; $this->COMPILE_ID = defined('COMPILE_ID') ? COMPILE_ID : ''; } - /** - * ORIGINAL in \CoreLibs\Admin\Backend - * set the language encoding and language settings - * the default charset from _SESSION login or from - * config DEFAULT ENCODING - * the lang full name for mo loading from _SESSION login - * or SITE LANG or DEFAULT LANG from config - * creates short lang (only first two chars) from the lang - * @return void - */ - private function setLangEncoding(): void - { - list ( - $this->encoding, - $this->lang, - $this->lang_short, - $this->domain, - $this->lang_dir - ) = \CoreLibs\Language\GetSettings::setLangEncoding(); - } - /** * @return void */ diff --git a/www/vendor/composer/autoload_classmap.php b/www/vendor/composer/autoload_classmap.php index bc4fe6da..f3c1d817 100644 --- a/www/vendor/composer/autoload_classmap.php +++ b/www/vendor/composer/autoload_classmap.php @@ -47,6 +47,7 @@ return array( 'CoreLibs\\Language\\Core\\StreamReader' => $baseDir . '/lib/CoreLibs/Language/Core/StreamReader.php', 'CoreLibs\\Language\\Core\\StringReader' => $baseDir . '/lib/CoreLibs/Language/Core/StringReader.php', 'CoreLibs\\Language\\Encoding' => $baseDir . '/lib/CoreLibs/Language/Encoding.php', + 'CoreLibs\\Language\\GetLocale' => $baseDir . '/lib/CoreLibs/Language/GetLocale.php', 'CoreLibs\\Language\\GetSettings' => $baseDir . '/lib/CoreLibs/Language/GetSettings.php', 'CoreLibs\\Language\\L10n' => $baseDir . '/lib/CoreLibs/Language/L10n.php', 'CoreLibs\\Output\\Form\\Elements' => $baseDir . '/lib/CoreLibs/Output/Form/Elements.php', diff --git a/www/vendor/composer/autoload_static.php b/www/vendor/composer/autoload_static.php index b50b4093..c8a8776c 100644 --- a/www/vendor/composer/autoload_static.php +++ b/www/vendor/composer/autoload_static.php @@ -112,6 +112,7 @@ class ComposerStaticInit10fe8fe2ec4017b8644d2b64bcf398b9 'CoreLibs\\Language\\Core\\StreamReader' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/Core/StreamReader.php', 'CoreLibs\\Language\\Core\\StringReader' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/Core/StringReader.php', 'CoreLibs\\Language\\Encoding' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/Encoding.php', + 'CoreLibs\\Language\\GetLocale' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/GetLocale.php', 'CoreLibs\\Language\\GetSettings' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/GetSettings.php', 'CoreLibs\\Language\\L10n' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/L10n.php', 'CoreLibs\\Output\\Form\\Elements' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/Form/Elements.php',