Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
43b51895f0 | ||
|
|
d0e294ecf5 | ||
|
|
3c35341e8b | ||
|
|
daf1f9263c | ||
|
|
805c695d68 | ||
|
|
ffdd45e32a | ||
|
|
316ca106fd | ||
|
|
fd9b201346 | ||
|
|
667dc4de8e | ||
|
|
fed67e990d | ||
|
|
c181a83b48 | ||
|
|
c830a32962 |
@@ -13,6 +13,7 @@ en_US@latin -> en_US -> en
|
|||||||
|
|
||||||
* en
|
* en
|
||||||
* en_US
|
* en_US
|
||||||
|
* en_US.UTF-8
|
||||||
* en_US@latin
|
* en_US@latin
|
||||||
|
|
||||||
### Domain
|
### Domain
|
||||||
@@ -32,7 +33,9 @@ if not set UTF-8 is assumed. Any other utf8 encoding is changed to UTF-8
|
|||||||
|
|
||||||
## File name example source
|
## File name example source
|
||||||
|
|
||||||
`ja_US.admin.UTF-8.po`
|
`ja-admin.po`
|
||||||
|
|
||||||
|
First part is LOCALE, second part is domain. Separator is `-`
|
||||||
|
|
||||||
## Folder layout
|
## Folder layout
|
||||||
|
|
||||||
@@ -49,4 +52,4 @@ frontend: dmain (CONTENT_PATH)
|
|||||||
|
|
||||||
## command
|
## command
|
||||||
|
|
||||||
`msgfmt -o www/includes/locale/ja_JP/LC_MESSAGES/frontend.UTF-8.mo 4dev/lang/ja_US.admin.UTF-8.po`
|
`msgfmt -o www/includes/locale/ja/LC_MESSAGES/frontend.mo 4dev/lang/ja.admin.po`
|
||||||
|
|||||||
@@ -8,13 +8,13 @@
|
|||||||
|
|
||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
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"
|
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
|
||||||
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: clemens.schwaighofer@egplusww.co\n"
|
"Last-Translator: clemens.schwaighofer@egplusww.co\n"
|
||||||
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
|
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
|
||||||
"Language: en_US\n"
|
"Language: en\n"
|
||||||
"MIME-Version: 1.0\n"
|
"MIME-Version: 1.0\n"
|
||||||
"Content-Type: text/plain; charset=UTF-8\n"
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
@@ -32,20 +32,20 @@ msgstr "OUTPUT TEST ADMIN EN"
|
|||||||
# testing multi
|
# testing multi
|
||||||
msgid "single"
|
msgid "single"
|
||||||
msgid_plural "multi"
|
msgid_plural "multi"
|
||||||
msgstr[0] "Multi Admin en_US 0"
|
msgstr[0] "Multi Admin en 0"
|
||||||
msgstr[1] "Multi Admin en_US 1"
|
msgstr[1] "Multi Admin en 1"
|
||||||
msgstr[2] "Multi Admin en_US 2"
|
msgstr[2] "Multi Admin en 2"
|
||||||
|
|
||||||
msgctxt "month name"
|
msgctxt "month name"
|
||||||
msgid "May"
|
msgid "May"
|
||||||
msgstr "May Admin en_US"
|
msgstr "May Admin en"
|
||||||
|
|
||||||
msgctxt "month name"
|
msgctxt "month name"
|
||||||
msgid "single"
|
msgid "single"
|
||||||
msgid_plural "multi"
|
msgid_plural "multi"
|
||||||
msgstr[0] "Multi Admin month en_US 0"
|
msgstr[0] "Multi Admin month en 0"
|
||||||
msgstr[1] "Multi Admin month en_US 1"
|
msgstr[1] "Multi Admin month en 1"
|
||||||
msgstr[2] "Multi Admin month en_US 2"
|
msgstr[2] "Multi Admin month en 2"
|
||||||
|
|
||||||
msgid "I should be translated"
|
msgid "I should be translated"
|
||||||
msgstr "I should be translated: I WAS TRANSLATED"
|
msgstr "I should be translated: I WAS TRANSLATED"
|
||||||
@@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
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"
|
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
|
||||||
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: clemens.schwaighofer@egplusww.co\n"
|
"Last-Translator: clemens.schwaighofer@egplusww.co\n"
|
||||||
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
|
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
|
||||||
"Language: en_US\n"
|
"Language: en\n"
|
||||||
"MIME-Version: 1.0\n"
|
"MIME-Version: 1.0\n"
|
||||||
"Content-Type: text/plain; charset=UTF-8\n"
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
@@ -19,6 +19,6 @@ msgstr "OUTPUT TEST FRONTEND EN"
|
|||||||
|
|
||||||
msgid "single"
|
msgid "single"
|
||||||
msgid_plural "multi"
|
msgid_plural "multi"
|
||||||
msgstr[0] "Multi frontend en_US 0"
|
msgstr[0] "Multi frontend en 0"
|
||||||
msgstr[1] "Multi frontend en_US 1"
|
msgstr[1] "Multi frontend en 1"
|
||||||
msgstr[2] "Multi frontend en_US 2"
|
msgstr[2] "Multi frontend en 2"
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
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"
|
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
|
||||||
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
@@ -69,9 +69,20 @@ msgstr "OUTPUT TEST ADMIN JA"
|
|||||||
# testing multi
|
# testing multi
|
||||||
msgid "single"
|
msgid "single"
|
||||||
msgid_plural "multi"
|
msgid_plural "multi"
|
||||||
msgstr[0] "Multi Admin ja_JP 0"
|
msgstr[0] "Multi Admin ja 0"
|
||||||
msgstr[1] "Multi Admin ja_JP 1"
|
msgstr[1] "Multi Admin ja 1"
|
||||||
msgstr[2] "Multi Admin ja_JP 2"
|
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
|
# login string
|
||||||
msgid "Hello %s"
|
msgid "Hello %s"
|
||||||
24
4dev/locale/ja-frontend.po
Normal file
24
4dev/locale/ja-frontend.po
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# to craete: msgfmt -o <output.po> <input.mo>
|
||||||
|
|
||||||
|
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 <info.jp@egplusww.com>\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"
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
# to craete: msgfmt -o <output.po> <input.mo>
|
|
||||||
|
|
||||||
msgid ""
|
|
||||||
msgstr ""
|
|
||||||
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
|
|
||||||
|
|
||||||
msgid "INPUT TEST"
|
|
||||||
msgstr "OUTPUT TEST FRONTEND JA"
|
|
||||||
@@ -7,6 +7,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace tests;
|
namespace tests;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -274,7 +275,6 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: create provider for n array merge
|
|
||||||
* provides array listing for the merge test
|
* provides array listing for the merge test
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
@@ -282,6 +282,61 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
|||||||
public function arrayMergeRecursiveProvider(): array
|
public function arrayMergeRecursiveProvider(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
// 0: expected
|
||||||
|
// 1..n: to merge arrays
|
||||||
|
// n+1: trigger for handle keys as string
|
||||||
|
'two arrays' => [
|
||||||
|
['a' => 1, 'b' => 2, 'c' => 3],
|
||||||
|
['a' => 1, 'b' => 2],
|
||||||
|
['b' => 2, 'c' => 3],
|
||||||
|
],
|
||||||
|
'two arrays, string flag' => [
|
||||||
|
['a' => 1, 'b' => 2, 'c' => 3],
|
||||||
|
['a' => 1, 'b' => 2],
|
||||||
|
['b' => 2, 'c' => 3],
|
||||||
|
true,
|
||||||
|
],
|
||||||
|
// non hash arrays
|
||||||
|
'non hash array merge, no string flag' => [
|
||||||
|
[3, 4, 5],
|
||||||
|
[1, 2, 3],
|
||||||
|
[3, 4, 5],
|
||||||
|
],
|
||||||
|
'non hash array merge, string flag' => [
|
||||||
|
[1, 2, 3, 3, 4, 5],
|
||||||
|
[1, 2, 3],
|
||||||
|
[3, 4, 5],
|
||||||
|
true
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* for warning checks
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function arrayMergeRecursiveProviderWarning(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// error <2 arguments
|
||||||
|
'too view arguments' => [
|
||||||
|
'arrayMergeRecursive needs two or more array arguments',
|
||||||
|
[1]
|
||||||
|
],
|
||||||
|
// error <2 arrays
|
||||||
|
'only one array' => [
|
||||||
|
'arrayMergeRecursive needs two or more array arguments',
|
||||||
|
[1],
|
||||||
|
true,
|
||||||
|
],
|
||||||
|
// error element is not array
|
||||||
|
'non array between array' => [
|
||||||
|
'arrayMergeRecursive encountered a non array argument',
|
||||||
|
[1],
|
||||||
|
'string',
|
||||||
|
[2]
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -626,21 +681,43 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
|||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @covers ::arrayMergeRecursive
|
* @covers ::arrayMergeRecursive
|
||||||
* @#dataProvider arrayMergeRecursiveProvider
|
* @dataProvider arrayMergeRecursiveProvider
|
||||||
* @testdox arrayMergeRecursive ... will be $expected [$_dataName]
|
* @testdox arrayMergeRecursive ... [$_dataName]
|
||||||
*
|
*
|
||||||
* @param array $input nested array set as each parameter
|
|
||||||
* @param bool $flag
|
|
||||||
* @param bool|array $expected
|
|
||||||
* @return void
|
* @return void
|
||||||
* array $input, bool $flag, $expected
|
*
|
||||||
*/
|
*/
|
||||||
public function testArrayMergeRecursive(): void
|
public function testArrayMergeRecursive(): void
|
||||||
{
|
{
|
||||||
$this->assertTrue(true, 'Implement proper test run');
|
$arrays = func_get_args();
|
||||||
$this->markTestIncomplete(
|
// first is expected array, always
|
||||||
'testArrayMergeRecursive has not been implemented yet.'
|
$expected = array_shift($arrays);
|
||||||
|
$output = \CoreLibs\Combined\ArrayHandler::arrayMergeRecursive(
|
||||||
|
...$arrays
|
||||||
);
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$output
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::arrayMergeRecursive
|
||||||
|
* @dataProvider arrayMergeRecursiveProviderWarning
|
||||||
|
* @testdox arrayMergeRecursive with E_USER_WARNING [$_dataName]
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testArrayMergeRecursiveWarningA(): void
|
||||||
|
{
|
||||||
|
$arrays = func_get_args();
|
||||||
|
// first is expected warning
|
||||||
|
$warning = array_shift($arrays);
|
||||||
|
$this->expectWarning();
|
||||||
|
$this->expectWarningMessage($warning);
|
||||||
|
\CoreLibs\Combined\ArrayHandler::arrayMergeRecursive(...$arrays);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testStartSession(string $input, string $type, $expected_n, $expected_i): void
|
public function testStartSession(string $input, string $type, $expected_n, $expected_i): void
|
||||||
{
|
{
|
||||||
|
// NEEDS MOCKING
|
||||||
/* $session_id = '';
|
/* $session_id = '';
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'p':
|
case 'p':
|
||||||
@@ -97,7 +98,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
|||||||
if ($type == 'g') {
|
if ($type == 'g') {
|
||||||
unset($GLOBALS['SET_SESSION_NAME']);
|
unset($GLOBALS['SET_SESSION_NAME']);
|
||||||
} */
|
} */
|
||||||
$this->markTestSkipped('No implementation for Create\Session. Cannot run session_start in CLI');
|
$this->markTestSkipped('[CoreLibsCreateSessionTest] No implementation '
|
||||||
|
. 'for Create\Session. Cannot run session_start in CLI');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2709,7 +2709,8 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
// comarep all, except timestamp that is a regex
|
// comarep all, except timestamp that is a regex
|
||||||
foreach ($expected_history as $key => $value) {
|
foreach ($expected_history as $key => $value) {
|
||||||
// check if starts with / because this is regex (timestamp)
|
// check if starts with / because this is regex (timestamp)
|
||||||
if (strpos($value, "/") === 0) {
|
// if (substr($expected_2, 0, 1) == '/) {
|
||||||
|
if (strpos($value, '/') === 0) {
|
||||||
// this is regex
|
// this is regex
|
||||||
$this->assertMatchesRegularExpression(
|
$this->assertMatchesRegularExpression(
|
||||||
$value,
|
$value,
|
||||||
|
|||||||
@@ -54,14 +54,16 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
|||||||
'no options set, constant set' => [
|
'no options set, constant set' => [
|
||||||
null,
|
null,
|
||||||
[
|
[
|
||||||
'log_folder' => '/tmp/',
|
'log_folder' => str_replace('/configs', '', __DIR__)
|
||||||
|
. DIRECTORY_SEPARATOR . 'log/',
|
||||||
'debug_all' => false,
|
'debug_all' => false,
|
||||||
'print_all' => false,
|
'print_all' => false,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'constant' => [
|
'constant' => [
|
||||||
'BASE' => '/tmp',
|
'BASE' => str_replace('/configs', '', __DIR__)
|
||||||
'LOG' => '/'
|
. DIRECTORY_SEPARATOR,
|
||||||
|
'LOG' => 'log/'
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -90,11 +90,16 @@ final class CoreLibsGetSystemTest extends TestCase
|
|||||||
public function getPageNameProvider(): array
|
public function getPageNameProvider(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
// 0: input
|
||||||
|
// 1: expected default/WITH_EXTENSION
|
||||||
|
// 2: expected NO_EXTENSION
|
||||||
|
// 3: expected FULL_PATH, if first and last character are / use regex
|
||||||
'original set' => [
|
'original set' => [
|
||||||
0 => null, // input
|
0 => null,
|
||||||
1 => 'phpunit',
|
1 => 'phpunit',
|
||||||
2 => 'phpunit',
|
2 => 'phpunit',
|
||||||
3 => 'www/vendor/bin/phpunit', // NOTE: this can change
|
// NOTE: this can change, so it is a regex check
|
||||||
|
3 => "/^(\/?.*\/?)?www\/vendor\/bin\/phpunit$/",
|
||||||
],
|
],
|
||||||
'some path with extension' => [
|
'some path with extension' => [
|
||||||
0 => '/some/path/to/file.txt',
|
0 => '/some/path/to/file.txt',
|
||||||
@@ -147,11 +152,13 @@ final class CoreLibsGetSystemTest extends TestCase
|
|||||||
list ($host, $port) = \CoreLibs\Get\System::getHostName();
|
list ($host, $port) = \CoreLibs\Get\System::getHostName();
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected_host,
|
$expected_host,
|
||||||
$host
|
$host,
|
||||||
|
'failed expected host assert'
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected_port,
|
$expected_port,
|
||||||
$port
|
$port,
|
||||||
|
'faile expected port assert'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,20 +183,38 @@ final class CoreLibsGetSystemTest extends TestCase
|
|||||||
// default 0,
|
// default 0,
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected_0,
|
$expected_0,
|
||||||
\CoreLibs\Get\System::getPageName()
|
\CoreLibs\Get\System::getPageName(),
|
||||||
|
'failed default assert'
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected_0,
|
$expected_0,
|
||||||
\CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::WITH_EXTENSION)
|
\CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::WITH_EXTENSION),
|
||||||
|
'failed WITH_EXTESION assert'
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected_1,
|
$expected_1,
|
||||||
\CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::NO_EXTENSION)
|
\CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::NO_EXTENSION),
|
||||||
);
|
'failed NO_EXTENSION assert'
|
||||||
$this->assertEquals(
|
|
||||||
$expected_2,
|
|
||||||
\CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::FULL_PATH)
|
|
||||||
);
|
);
|
||||||
|
// FULL PATH check can be equals or regex
|
||||||
|
$page_name_full_path = \CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::FULL_PATH);
|
||||||
|
if (
|
||||||
|
substr($expected_2, 0, 1) == '/' &&
|
||||||
|
substr($expected_2, -1, 1) == '/'
|
||||||
|
) {
|
||||||
|
// this is regex
|
||||||
|
$this->assertMatchesRegularExpression(
|
||||||
|
$expected_2,
|
||||||
|
$page_name_full_path,
|
||||||
|
'failed FULL_PATH assert regex'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_2,
|
||||||
|
$page_name_full_path,
|
||||||
|
'failed FULL_PATH assert equals'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
310
4dev/tests/CoreLibsLanguageGetLocaleTest.php
Normal file
310
4dev/tests/CoreLibsLanguageGetLocaleTest.php
Normal file
@@ -0,0 +1,310 @@
|
|||||||
|
<?php // phpcs:disable Generic.Files.LineLength
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace tests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for Language\GetLocale
|
||||||
|
*
|
||||||
|
* @coversDefaultClass \CoreLibs\Language\GetLocale
|
||||||
|
* @testdox \CoreLibs\Language\GetLocale method tests
|
||||||
|
*/
|
||||||
|
final class CoreLibsLanguageGetLocaleTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* set all constant variables that must be set before call
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function setUpBeforeClass(): void
|
||||||
|
{
|
||||||
|
// default web page encoding setting
|
||||||
|
if (!defined('DEFAULT_ENCODING')) {
|
||||||
|
define('DEFAULT_ENCODING', 'UTF-8');
|
||||||
|
}
|
||||||
|
if (!defined('DEFAULT_LOCALE')) {
|
||||||
|
// default lang + encoding
|
||||||
|
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||||
|
}
|
||||||
|
// site
|
||||||
|
if (!defined('SITE_ENCODING')) {
|
||||||
|
define('SITE_ENCODING', DEFAULT_ENCODING);
|
||||||
|
}
|
||||||
|
if (!defined('SITE_LOCALE')) {
|
||||||
|
define('SITE_LOCALE', DEFAULT_LOCALE);
|
||||||
|
}
|
||||||
|
// just set
|
||||||
|
if (!defined('BASE')) {
|
||||||
|
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||||
|
}
|
||||||
|
if (!defined('INCLUDES')) {
|
||||||
|
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
||||||
|
}
|
||||||
|
if (!defined('LANG')) {
|
||||||
|
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
||||||
|
}
|
||||||
|
if (!defined('LOCALE')) {
|
||||||
|
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||||
|
}
|
||||||
|
if (!defined('CONTENT_PATH')) {
|
||||||
|
define('CONTENT_PATH', 'frontend' . DIRECTORY_SEPARATOR);
|
||||||
|
}
|
||||||
|
// array session
|
||||||
|
$_SESSION = [];
|
||||||
|
global $_SESSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* all the test data
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function setLocaleProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// 0: locale
|
||||||
|
// 1: domain
|
||||||
|
// 2: encoding
|
||||||
|
// 3: path
|
||||||
|
// 4: SESSION: DEFAULT_LOCALE
|
||||||
|
// 5: SESSION: DEFAULT_CHARSET
|
||||||
|
// 6: expected array
|
||||||
|
'no params, all default constants' => [
|
||||||
|
// 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__
|
||||||
@@ -1,325 +0,0 @@
|
|||||||
<?php // phpcs:disable Generic.Files.LineLength
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace tests;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test class for Language\GetSettings
|
|
||||||
*
|
|
||||||
* @coversDefaultClass \CoreLibs\Language\GetSettings
|
|
||||||
* @testdox \CoreLibs\Language\GetSettings method tests
|
|
||||||
*/
|
|
||||||
final class CoreLibsLanguageGetSettingsTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* set all constant variables that must be set before call
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function setUpBeforeClass(): void
|
|
||||||
{
|
|
||||||
define('DEFAULT_LANG', 'en_US');
|
|
||||||
// default web page encoding setting
|
|
||||||
define('DEFAULT_ENCODING', 'UTF-8');
|
|
||||||
// default lang + encoding
|
|
||||||
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
|
||||||
// site
|
|
||||||
define('SITE_LANG', DEFAULT_LANG);
|
|
||||||
// just set
|
|
||||||
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
|
||||||
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
|
||||||
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
|
||||||
define('CONTENT_PATH', 'frontend' . DIRECTORY_SEPARATOR);
|
|
||||||
// array session
|
|
||||||
$_SESSION = [];
|
|
||||||
global $_SESSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* all the test data
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function setLangEncodingProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
// 0: locale/lang
|
|
||||||
// 1: domain
|
|
||||||
// 2: path
|
|
||||||
// 3: SESSION DEFAULT_CHARSE
|
|
||||||
// 4: GLOBALS: OVERRIDE_LANG
|
|
||||||
// 5: SESSION: DEFAULT_LANG
|
|
||||||
// 6: expected array
|
|
||||||
'no params, all default constants' => [
|
|
||||||
// lang, domain, path
|
|
||||||
null, null, null,
|
|
||||||
// global set no session
|
|
||||||
// SESSION: DEFAULT_CHARSET, GLOBALS: OVERRIDE_LANG, SESSION: DEFAULT_LANG
|
|
||||||
null, null, null,
|
|
||||||
// return array
|
|
||||||
[
|
|
||||||
0 => 'UTF-8',
|
|
||||||
1 => 'en_US',
|
|
||||||
2 => 'en',
|
|
||||||
3 => 'frontend',
|
|
||||||
4 => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
|
||||||
'encoding' => 'UTF-8',
|
|
||||||
'lang' => 'en_US',
|
|
||||||
'lang_short' => 'en',
|
|
||||||
'domain' => 'frontend',
|
|
||||||
'path' => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'no params, session charset and lang' => [
|
|
||||||
// lang, domain, path
|
|
||||||
null, null, null,
|
|
||||||
// global set no session
|
|
||||||
// SESSION: DEFAULT_CHARSET, GLOBALS: OVERRIDE_LANG, SESSION: DEFAULT_LANG
|
|
||||||
'UTF-8', null, 'ja_JP',
|
|
||||||
// return array
|
|
||||||
[
|
|
||||||
0 => 'UTF-8',
|
|
||||||
1 => 'ja_JP',
|
|
||||||
2 => 'ja',
|
|
||||||
3 => 'frontend',
|
|
||||||
4 => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
|
||||||
'encoding' => 'UTF-8',
|
|
||||||
'lang' => 'ja_JP',
|
|
||||||
'lang_short' => 'ja',
|
|
||||||
'domain' => 'frontend',
|
|
||||||
'path' => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'no params, session charset and lang short' => [
|
|
||||||
// lang, domain, path
|
|
||||||
null, null, null,
|
|
||||||
// global set no session
|
|
||||||
// SESSION: DEFAULT_CHARSET, GLOBALS: OVERRIDE_LANG, SESSION: DEFAULT_LANG
|
|
||||||
'UTF-8', null, 'ja',
|
|
||||||
// return array
|
|
||||||
[
|
|
||||||
0 => 'UTF-8',
|
|
||||||
1 => 'ja',
|
|
||||||
2 => 'ja',
|
|
||||||
3 => 'frontend',
|
|
||||||
4 => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
|
||||||
'encoding' => 'UTF-8',
|
|
||||||
'lang' => 'ja',
|
|
||||||
'lang_short' => 'ja',
|
|
||||||
'domain' => 'frontend',
|
|
||||||
'path' => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
|
||||||
],
|
|
||||||
],
|
|
||||||
// globals override lang
|
|
||||||
'no params, session charset and lang, default lang override' => [
|
|
||||||
// lang, domain, path
|
|
||||||
null, null, null,
|
|
||||||
// global set no session
|
|
||||||
// SESSION: DEFAULT_CHARSET, GLOBALS: OVERRIDE_LANG, SESSION: DEFAULT_LANG
|
|
||||||
'UTF-8', 'en_US', 'ja_JP',
|
|
||||||
// return array
|
|
||||||
[
|
|
||||||
0 => 'UTF-8',
|
|
||||||
1 => 'en_US',
|
|
||||||
2 => 'en',
|
|
||||||
3 => 'frontend',
|
|
||||||
4 => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
|
||||||
'encoding' => 'UTF-8',
|
|
||||||
'lang' => 'en_US',
|
|
||||||
'lang_short' => 'en',
|
|
||||||
'domain' => 'frontend',
|
|
||||||
'path' => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
|
||||||
],
|
|
||||||
],
|
|
||||||
// globals override lang short
|
|
||||||
'no params, session charset and lang, default lang short override' => [
|
|
||||||
// lang, domain, path
|
|
||||||
null, null, null,
|
|
||||||
// global set no session
|
|
||||||
// SESSION: DEFAULT_CHARSET, GLOBALS: OVERRIDE_LANG, SESSION: DEFAULT_LANG
|
|
||||||
'UTF-8', 'en', 'ja_JP',
|
|
||||||
// return array
|
|
||||||
[
|
|
||||||
0 => 'UTF-8',
|
|
||||||
1 => 'en',
|
|
||||||
2 => 'en',
|
|
||||||
3 => 'frontend',
|
|
||||||
4 => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
|
||||||
'encoding' => 'UTF-8',
|
|
||||||
'lang' => 'en',
|
|
||||||
'lang_short' => 'en',
|
|
||||||
'domain' => 'frontend',
|
|
||||||
'path' => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
|
||||||
],
|
|
||||||
],
|
|
||||||
// param lang (no override)
|
|
||||||
'locale param only, no override' => [
|
|
||||||
// lang, domain, path
|
|
||||||
'ja.UTF-8', null, null,
|
|
||||||
// global set no session
|
|
||||||
// SESSION: DEFAULT_CHARSET, GLOBALS: OVERRIDE_LANG, SESSION: DEFAULT_LANG
|
|
||||||
null, null, null,
|
|
||||||
// return array
|
|
||||||
[
|
|
||||||
0 => 'UTF-8',
|
|
||||||
1 => 'ja',
|
|
||||||
2 => 'ja',
|
|
||||||
3 => 'frontend',
|
|
||||||
4 => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
|
||||||
'encoding' => 'UTF-8',
|
|
||||||
'lang' => 'ja',
|
|
||||||
'lang_short' => 'ja',
|
|
||||||
'domain' => 'frontend',
|
|
||||||
'path' => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
|
||||||
],
|
|
||||||
],
|
|
||||||
// different locale setting
|
|
||||||
'locale complex param only, no override' => [
|
|
||||||
// lang, domain, path
|
|
||||||
'ja_JP.SJIS', null, null,
|
|
||||||
// global set no session
|
|
||||||
// SESSION: DEFAULT_CHARSET, GLOBALS: OVERRIDE_LANG, SESSION: DEFAULT_LANG
|
|
||||||
null, null, null,
|
|
||||||
// return array
|
|
||||||
[
|
|
||||||
0 => 'SJIS',
|
|
||||||
1 => 'ja_JP',
|
|
||||||
2 => 'ja',
|
|
||||||
3 => 'frontend',
|
|
||||||
4 => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
|
||||||
'encoding' => 'SJIS',
|
|
||||||
'lang' => 'ja_JP',
|
|
||||||
'lang_short' => 'ja',
|
|
||||||
'domain' => 'frontend',
|
|
||||||
'path' => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
|
||||||
],
|
|
||||||
],
|
|
||||||
// param lang and domain (no override)
|
|
||||||
'locale, domain params, no override' => [
|
|
||||||
// lang, domain, path
|
|
||||||
'ja.UTF-8', 'admin', null,
|
|
||||||
// global set no session
|
|
||||||
// SESSION: DEFAULT_CHARSET, GLOBALS: OVERRIDE_LANG, SESSION: DEFAULT_LANG
|
|
||||||
null, null, null,
|
|
||||||
// return array
|
|
||||||
[
|
|
||||||
0 => 'UTF-8',
|
|
||||||
1 => 'ja',
|
|
||||||
2 => 'ja',
|
|
||||||
3 => 'admin',
|
|
||||||
4 => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
|
||||||
'encoding' => 'UTF-8',
|
|
||||||
'lang' => 'ja',
|
|
||||||
'lang_short' => 'ja',
|
|
||||||
'domain' => 'admin',
|
|
||||||
'path' => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
|
||||||
],
|
|
||||||
],
|
|
||||||
// all params set (no override)
|
|
||||||
'all params, no override' => [
|
|
||||||
// lang, domain, path
|
|
||||||
'ja.UTF-8', 'admin', __DIR__ . '/locale_other/',
|
|
||||||
// global set no session
|
|
||||||
// SESSION: DEFAULT_CHARSET, GLOBALS: OVERRIDE_LANG, SESSION: DEFAULT_LANG
|
|
||||||
null, null, null,
|
|
||||||
// return array
|
|
||||||
[
|
|
||||||
0 => 'UTF-8',
|
|
||||||
1 => 'ja',
|
|
||||||
2 => 'ja',
|
|
||||||
3 => 'admin',
|
|
||||||
4 => "/^\/(.*\/)?locale_other\/$/",
|
|
||||||
'encoding' => 'UTF-8',
|
|
||||||
'lang' => 'ja',
|
|
||||||
'lang_short' => 'ja',
|
|
||||||
'domain' => 'admin',
|
|
||||||
'path' => "/^\/(.*\/)?locale_other\/$/",
|
|
||||||
],
|
|
||||||
],
|
|
||||||
// TODO invalid params (bad path) (no override)
|
|
||||||
// TODO param calls, but with override set
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @covers ::setLangEncoding
|
|
||||||
* @dataProvider setLangEncodingProvider
|
|
||||||
* @testdox lang settings lang $language, domain $domain, path $path; null session char: $SESSION_DEFAULT_CHARSET, null global lang: $GLOBAL_OVERRIDE_LANG, null session lang: $SESSION_DEFAULT_LANG [$_dataName]
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testSetLangEncoding(
|
|
||||||
?string $language,
|
|
||||||
?string $domain,
|
|
||||||
?string $path,
|
|
||||||
?string $SESSION_DEFAULT_CHARSET,
|
|
||||||
?string $GLOBAL_OVERRIDE_LANG,
|
|
||||||
?string $SESSION_DEFAULT_LANG,
|
|
||||||
array $expected,
|
|
||||||
): void {
|
|
||||||
$return_lang_settings = [];
|
|
||||||
global $_SESSION;
|
|
||||||
// set override
|
|
||||||
if ($SESSION_DEFAULT_CHARSET !== null) {
|
|
||||||
$_SESSION['DEFAULT_CHARSET'] = $SESSION_DEFAULT_CHARSET;
|
|
||||||
}
|
|
||||||
if ($GLOBAL_OVERRIDE_LANG !== null) {
|
|
||||||
$GLOBALS['OVERRIDE_LANG'] = $GLOBAL_OVERRIDE_LANG;
|
|
||||||
}
|
|
||||||
if ($SESSION_DEFAULT_LANG !== null) {
|
|
||||||
$_SESSION['DEFAULT_LANG'] = $SESSION_DEFAULT_LANG;
|
|
||||||
}
|
|
||||||
// function call
|
|
||||||
if ($language === null && $domain === null && $path === null) {
|
|
||||||
$return_lang_settings = \CoreLibs\Language\GetSettings::setLangEncoding();
|
|
||||||
} elseif ($language !== null && $domain === null && $path === null) {
|
|
||||||
$return_lang_settings = \CoreLibs\Language\GetSettings::setLangEncoding(
|
|
||||||
$language
|
|
||||||
);
|
|
||||||
} elseif ($language !== null && $domain !== null && $path === null) {
|
|
||||||
$return_lang_settings = \CoreLibs\Language\GetSettings::setLangEncoding(
|
|
||||||
$language,
|
|
||||||
$domain
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$return_lang_settings = \CoreLibs\Language\GetSettings::setLangEncoding(
|
|
||||||
$language,
|
|
||||||
$domain,
|
|
||||||
$path
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// print "RETURN: " . print_r($return_lang_settings, true) . "\n";
|
|
||||||
|
|
||||||
foreach (
|
|
||||||
[
|
|
||||||
0, 1, 2, 3, 4,
|
|
||||||
'encoding', 'lang', 'lang_short', 'domain', 'path'
|
|
||||||
] as $key
|
|
||||||
) {
|
|
||||||
$value = $expected[$key];
|
|
||||||
if (strpos($value, "/") === 0) {
|
|
||||||
// this is regex
|
|
||||||
$this->assertMatchesRegularExpression(
|
|
||||||
$value,
|
|
||||||
$return_lang_settings[$key]
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// assert equal
|
|
||||||
$this->assertEquals(
|
|
||||||
$value,
|
|
||||||
$return_lang_settings[$key],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// unset all vars
|
|
||||||
$_SESSION = [];
|
|
||||||
unset($GLOBALS['OVERRIDE_LANG']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// __END__
|
|
||||||
@@ -22,19 +22,37 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public static function setUpBeforeClass(): void
|
public static function setUpBeforeClass(): void
|
||||||
{
|
{
|
||||||
define('DEFAULT_LANG', 'en_US');
|
|
||||||
// default web page encoding setting
|
// default web page encoding setting
|
||||||
define('DEFAULT_ENCODING', 'UTF-8');
|
if (!defined('DEFAULT_ENCODING')) {
|
||||||
// default lang + encoding
|
define('DEFAULT_ENCODING', 'UTF-8');
|
||||||
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
}
|
||||||
|
if (!defined('DEFAULT_LOCALE')) {
|
||||||
|
// default lang + encoding
|
||||||
|
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||||
|
}
|
||||||
// site
|
// site
|
||||||
define('SITE_LANG', DEFAULT_LANG);
|
if (!defined('SITE_ENCODING')) {
|
||||||
|
define('SITE_ENCODING', DEFAULT_ENCODING);
|
||||||
|
}
|
||||||
|
if (!defined('SITE_LOCALE')) {
|
||||||
|
define('SITE_LOCALE', DEFAULT_LOCALE);
|
||||||
|
}
|
||||||
// just set
|
// just set
|
||||||
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
if (!defined('BASE')) {
|
||||||
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||||
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
}
|
||||||
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
if (!defined('INCLUDES')) {
|
||||||
define('CONTENT_PATH', 'frontend' . DIRECTORY_SEPARATOR);
|
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
||||||
|
}
|
||||||
|
if (!defined('LANG')) {
|
||||||
|
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
||||||
|
}
|
||||||
|
if (!defined('LOCALE')) {
|
||||||
|
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||||
|
}
|
||||||
|
if (!defined('CONTENT_PATH')) {
|
||||||
|
define('CONTENT_PATH', 'frontend' . DIRECTORY_SEPARATOR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,44 +105,20 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
// 0: locale
|
// 0: locale
|
||||||
// 1: path
|
// 1: domain
|
||||||
// 2: domain
|
// 2: encoding
|
||||||
// 3: legacy load (Default true)
|
// 3: path
|
||||||
// 4: locale expected
|
// 4: locale expected
|
||||||
// 5: domain exepcted
|
// 5: domain exepcted
|
||||||
// 6: context (null for none)
|
// 6: context (null for none)
|
||||||
// 7: test string in
|
// 7: test string in
|
||||||
// 8: test translated
|
// 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
|
// new style load
|
||||||
'gettext load en' => [
|
'gettext load en' => [
|
||||||
'en_US.UTF-8',
|
'en_US.UTF-8',
|
||||||
__DIR__ . 'includes/locale/',
|
|
||||||
'frontend',
|
'frontend',
|
||||||
false,
|
__DIR__ . 'includes/locale/',
|
||||||
|
//
|
||||||
'en_US.UTF-8',
|
'en_US.UTF-8',
|
||||||
'frontend',
|
'frontend',
|
||||||
null,
|
null,
|
||||||
@@ -133,9 +127,9 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
],
|
],
|
||||||
'gettext load en' => [
|
'gettext load en' => [
|
||||||
'en_US.UTF-8',
|
'en_US.UTF-8',
|
||||||
__DIR__ . 'includes/locale/',
|
|
||||||
'frontend',
|
'frontend',
|
||||||
false,
|
__DIR__ . 'includes/locale/',
|
||||||
|
//
|
||||||
'en_US.UTF-8',
|
'en_US.UTF-8',
|
||||||
'frontend',
|
'frontend',
|
||||||
'context',
|
'context',
|
||||||
@@ -144,32 +138,33 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
],
|
],
|
||||||
'gettext load ja' => [
|
'gettext load ja' => [
|
||||||
'ja_JP.UTF-8',
|
'ja_JP.UTF-8',
|
||||||
__DIR__ . 'includes/locale/',
|
|
||||||
'admin',
|
'admin',
|
||||||
false,
|
__DIR__ . 'includes/locale/',
|
||||||
|
//
|
||||||
'ja_JP.UTF-8',
|
'ja_JP.UTF-8',
|
||||||
'admin',
|
'admin',
|
||||||
null,
|
null,
|
||||||
'Original',
|
'Original',
|
||||||
'Translated admin ja_JP',
|
'Translated admin ja_JP',
|
||||||
],
|
],
|
||||||
// null set locale legacy
|
// mixed path and domain
|
||||||
'empty load legacy' => [
|
'mixed path and domain' => [
|
||||||
null,
|
'en_US.UTF-8',
|
||||||
null,
|
__DIR__ . 'includes/locale/',
|
||||||
null,
|
'frontend',
|
||||||
null,
|
//
|
||||||
'',
|
'en_US.UTF-8',
|
||||||
'',
|
'frontend',
|
||||||
null,
|
'context',
|
||||||
'Original',
|
|
||||||
'Original',
|
'Original',
|
||||||
|
'Original context frontend en_US',
|
||||||
],
|
],
|
||||||
|
// null set
|
||||||
'empty load new ' => [
|
'empty load new ' => [
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
false,
|
//
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
null,
|
null,
|
||||||
@@ -187,9 +182,8 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
* @testdox check l10n init with Locale $locale, Path $path, Domain $domain, Legacy: $legacy with $context [$_dataName]
|
* @testdox check l10n init with Locale $locale, Path $path, Domain $domain, Legacy: $legacy with $context [$_dataName]
|
||||||
*
|
*
|
||||||
* @param string|null $locale
|
* @param string|null $locale
|
||||||
* @param string|null $path
|
|
||||||
* @param string|null $domain
|
* @param string|null $domain
|
||||||
* @param bool|null $legacy
|
* @param string|null $path
|
||||||
* @param string $locale_expected
|
* @param string $locale_expected
|
||||||
* @param string $domain_expected
|
* @param string $domain_expected
|
||||||
* @param ?string $context
|
* @param ?string $context
|
||||||
@@ -199,9 +193,8 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testL10nObject(
|
public function testL10nObject(
|
||||||
?string $locale,
|
?string $locale,
|
||||||
?string $path,
|
|
||||||
?string $domain,
|
?string $domain,
|
||||||
?bool $legacy,
|
?string $path,
|
||||||
string $locale_expected,
|
string $locale_expected,
|
||||||
string $domain_expected,
|
string $domain_expected,
|
||||||
?string $context,
|
?string $context,
|
||||||
@@ -210,14 +203,12 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
): void {
|
): void {
|
||||||
if ($locale === null) {
|
if ($locale === null) {
|
||||||
$l10n = new \CoreLibs\Language\L10n();
|
$l10n = new \CoreLibs\Language\L10n();
|
||||||
} elseif ($path === null) {
|
|
||||||
$l10n = new \CoreLibs\Language\L10n($locale);
|
|
||||||
} elseif ($domain === null) {
|
} elseif ($domain === null) {
|
||||||
$l10n = new \CoreLibs\Language\L10n($locale, $path);
|
$l10n = new \CoreLibs\Language\L10n($locale);
|
||||||
} elseif ($legacy === null) {
|
} elseif ($path === null) {
|
||||||
$l10n = new \CoreLibs\Language\L10n($locale, $path, $domain);
|
$l10n = new \CoreLibs\Language\L10n($locale, $domain);
|
||||||
} else {
|
} 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 "LOC: " . $locale . ", " . $l10n->getLocale() . ", " . $locale_expected . "\n";
|
||||||
// print "MO: " . $l10n->getMoFile() . "\n";
|
// print "MO: " . $l10n->getMoFile() . "\n";
|
||||||
@@ -259,94 +250,64 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
// 0: locale
|
// 0: locale
|
||||||
// 1: path
|
// 1: domain
|
||||||
// 2: domain
|
// 2: path
|
||||||
// 3: legacy flag
|
// 3: load error
|
||||||
// 4: input string to translated
|
// 4: input string to translated
|
||||||
// 5: expected locale
|
// 5: expected locale
|
||||||
// 6: expected domain
|
// 6: expected domain
|
||||||
// 7: expected translation
|
// 7: expected translation
|
||||||
// 8: change locale
|
// 8: change locale
|
||||||
// 9: change path
|
// 9: change domain
|
||||||
// 10: change domain
|
// 10: change path
|
||||||
// 11: legacy flag
|
// 11: change load error
|
||||||
// 12: expected locale
|
// 12: expected locale
|
||||||
// 13: expected domain
|
// 13: expected domain
|
||||||
// 14: expected translation
|
// 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)' => [
|
'load and change (en->ja)' => [
|
||||||
// set 0-3
|
// set 0-2
|
||||||
'en_US.UTF-8',
|
'en_US.UTF-8',
|
||||||
__DIR__ . 'includes/locale/',
|
|
||||||
'frontend',
|
'frontend',
|
||||||
|
__DIR__ . 'includes/locale/',
|
||||||
|
// status 3
|
||||||
false,
|
false,
|
||||||
// status 4
|
// to translate 4
|
||||||
false,
|
|
||||||
// to translate 5
|
|
||||||
'Original',
|
'Original',
|
||||||
// check setter 6-8
|
// check setter 5-7
|
||||||
'en_US.UTF-8',
|
'en_US.UTF-8',
|
||||||
'frontend',
|
'frontend',
|
||||||
'Translated frontend en_US',
|
'Translated frontend en_US',
|
||||||
// set new 9-12
|
// set new 8-10
|
||||||
'ja_JP.UTF-8',
|
'ja_JP.UTF-8',
|
||||||
__DIR__ . 'includes/locale/',
|
|
||||||
'frontend',
|
'frontend',
|
||||||
|
__DIR__ . 'includes/locale/',
|
||||||
|
// status new 11
|
||||||
false,
|
false,
|
||||||
// status new 13
|
// check new setter 12-14
|
||||||
false,
|
|
||||||
// check new setter 14-16
|
|
||||||
'ja_JP.UTF-8',
|
'ja_JP.UTF-8',
|
||||||
'frontend',
|
'frontend',
|
||||||
'Translated frontend ja_JP',
|
'Translated frontend ja_JP',
|
||||||
],
|
],
|
||||||
'empty load and change to en' => [
|
'empty load and change to en' => [
|
||||||
// set 0-3
|
// set 0-2
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
|
// status 3
|
||||||
false,
|
false,
|
||||||
// status 4
|
// to translate 4
|
||||||
false,
|
|
||||||
// to translate 5
|
|
||||||
'Original',
|
'Original',
|
||||||
// check setter 6-8
|
// check setter 5-7
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
'Original',
|
'Original',
|
||||||
// set new 9-12
|
// set new 8-10
|
||||||
'en_US.UTF-8',
|
'en_US.UTF-8',
|
||||||
__DIR__ . 'includes/locale/',
|
|
||||||
'frontend',
|
'frontend',
|
||||||
|
__DIR__ . 'includes/locale/',
|
||||||
|
// status new 11
|
||||||
false,
|
false,
|
||||||
// status new 13
|
// check new setter 12-14
|
||||||
false,
|
|
||||||
// check new setter 14-16
|
|
||||||
'en_US.UTF-8',
|
'en_US.UTF-8',
|
||||||
'frontend',
|
'frontend',
|
||||||
'Translated frontend en_US',
|
'Translated frontend en_US',
|
||||||
@@ -363,18 +324,16 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
* @testdox change locale from $locale and domain $domain to locale $locale_new and domain $domain_new [$_dataName]
|
* @testdox change locale from $locale and domain $domain to locale $locale_new and domain $domain_new [$_dataName]
|
||||||
*
|
*
|
||||||
* @param string|null $locale
|
* @param string|null $locale
|
||||||
* @param string|null $path
|
|
||||||
* @param string|null $domain
|
* @param string|null $domain
|
||||||
* @param bool|null $legacy
|
* @param string|null $path
|
||||||
* @param bool $load_error
|
* @param bool $load_error
|
||||||
* @param string $original
|
* @param string $original
|
||||||
* @param string $locale_expected_a
|
* @param string $locale_expected_a
|
||||||
* @param string $domain_expected_a
|
* @param string $domain_expected_a
|
||||||
* @param string $translated_a
|
* @param string $translated_a
|
||||||
* @param string|null $locale_new
|
* @param string|null $locale_new
|
||||||
* @param string|null $path_new
|
|
||||||
* @param string|null $domain_new
|
* @param string|null $domain_new
|
||||||
* @param bool|null $legacy_new
|
* @param string|null $path_new
|
||||||
* @param bool $load_error_new
|
* @param bool $load_error_new
|
||||||
* @param string $locale_expected_b
|
* @param string $locale_expected_b
|
||||||
* @param string $domain_expected_b
|
* @param string $domain_expected_b
|
||||||
@@ -382,41 +341,37 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testGetTranslator(
|
public function testGetTranslator(
|
||||||
// 0-3
|
// 0-2
|
||||||
?string $locale,
|
?string $locale,
|
||||||
?string $path,
|
|
||||||
?string $domain,
|
?string $domain,
|
||||||
?bool $legacy,
|
?string $path,
|
||||||
// 4
|
// 3
|
||||||
bool $load_error,
|
bool $load_error,
|
||||||
// 5
|
// 4
|
||||||
string $original,
|
string $original,
|
||||||
// 6-8
|
// 5-7
|
||||||
string $locale_expected_a,
|
string $locale_expected_a,
|
||||||
string $domain_expected_a,
|
string $domain_expected_a,
|
||||||
string $translated_a,
|
string $translated_a,
|
||||||
// 9-12
|
// 8-10
|
||||||
?string $locale_new,
|
?string $locale_new,
|
||||||
?string $path_new,
|
|
||||||
?string $domain_new,
|
?string $domain_new,
|
||||||
?bool $legacy_new,
|
?string $path_new,
|
||||||
// 13
|
// 11
|
||||||
bool $load_error_new,
|
bool $load_error_new,
|
||||||
// 14-16
|
// 12-14
|
||||||
string $locale_expected_b,
|
string $locale_expected_b,
|
||||||
string $domain_expected_b,
|
string $domain_expected_b,
|
||||||
string $translated_b,
|
string $translated_b,
|
||||||
): void {
|
): void {
|
||||||
if ($locale === null) {
|
if ($locale === null) {
|
||||||
$l10n = new \CoreLibs\Language\L10n();
|
$l10n = new \CoreLibs\Language\L10n();
|
||||||
} elseif ($path === null) {
|
|
||||||
$l10n = new \CoreLibs\Language\L10n($locale);
|
|
||||||
} elseif ($domain === null) {
|
} elseif ($domain === null) {
|
||||||
$l10n = new \CoreLibs\Language\L10n($locale, $path);
|
$l10n = new \CoreLibs\Language\L10n($locale);
|
||||||
} elseif ($legacy === null) {
|
} elseif ($path === null) {
|
||||||
$l10n = new \CoreLibs\Language\L10n($locale, $path, $domain);
|
$l10n = new \CoreLibs\Language\L10n($locale, $domain);
|
||||||
} else {
|
} 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 "LOC: " . $locale . ", " . $l10n->getLocale() . ", " . $locale_expected . "\n";
|
||||||
// status check
|
// status check
|
||||||
@@ -441,67 +396,39 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
'Translated string init assert failed'
|
'Translated string init assert failed'
|
||||||
);
|
);
|
||||||
|
|
||||||
// do reload with legacy l10nReloadMOfile IF legacy is null or true
|
// switch
|
||||||
// use getTranslator if legacy is false
|
if ($locale_new === null) {
|
||||||
if ($legacy === null || $legacy === true) {
|
$translator = $l10n->getTranslator();
|
||||||
// there is no null/empty locale allowed directly
|
} elseif ($domain_new === null) {
|
||||||
// if empty will set previous one
|
$translator = $l10n->getTranslator($locale_new);
|
||||||
if ($path_new === null) {
|
} elseif ($path_new === null) {
|
||||||
$ret_status = $l10n->l10nReloadMOfile($locale_new);
|
$translator = $l10n->getTranslator($locale_new, $domain_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'
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
if ($locale_new === null) {
|
$translator = $l10n->getTranslator($locale_new, $domain_new, $path_new);
|
||||||
$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'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
// 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
|
// new set check
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$locale_expected_b,
|
$locale_expected_b,
|
||||||
@@ -520,16 +447,14 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: test all translation types
|
// TODO: domain based
|
||||||
// __/gettext
|
|
||||||
// __n/ngettext
|
|
||||||
// ->dgettext
|
// ->dgettext
|
||||||
// ->dngettext
|
// ->dngettext
|
||||||
// ->dpgettext
|
// ->dpgettext
|
||||||
// ->dpngettext
|
// ->dpngettext
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* for plural and plural context
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@@ -579,9 +504,10 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* plural and plural context
|
||||||
*
|
*
|
||||||
* @covers ::__n
|
* @covers ::__n
|
||||||
|
* @covers ::__pn
|
||||||
* @dataProvider ngettextProvider
|
* @dataProvider ngettextProvider
|
||||||
* @testdox plural string test for locale $locale and domain $domain with $context [$_dataName]
|
* @testdox plural string test for locale $locale and domain $domain with $context [$_dataName]
|
||||||
*
|
*
|
||||||
@@ -619,7 +545,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
} else {
|
} else {
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
$l10n->__pn($context, $original_single, $original_plural, $n),
|
$l10n->__np($context, $original_single, $original_plural, $n),
|
||||||
'assert failed for plural: ' . $n . ' in context: ' . $context
|
'assert failed for plural: ' . $n . ' in context: ' . $context
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -640,21 +566,39 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
'en',
|
'en',
|
||||||
[
|
[
|
||||||
'en',
|
'en',
|
||||||
]
|
],
|
||||||
|
[
|
||||||
|
'lang' => 'en',
|
||||||
|
'country' => null,
|
||||||
|
'charset' => null,
|
||||||
|
'modifier' => null,
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'en.UTF-8' => [
|
'en.UTF-8' => [
|
||||||
'en.UTF-8',
|
'en.UTF-8',
|
||||||
[
|
[
|
||||||
'en.UTF-8',
|
'en.UTF-8',
|
||||||
'en',
|
'en',
|
||||||
]
|
],
|
||||||
|
[
|
||||||
|
'lang' => 'en',
|
||||||
|
'country' => null,
|
||||||
|
'charset' => 'UTF-8',
|
||||||
|
'modifier' => null,
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'en_US' => [
|
'en_US' => [
|
||||||
'en_US',
|
'en_US',
|
||||||
[
|
[
|
||||||
'en_US',
|
'en_US',
|
||||||
'en',
|
'en',
|
||||||
]
|
],
|
||||||
|
[
|
||||||
|
'lang' => 'en',
|
||||||
|
'country' => 'US',
|
||||||
|
'charset' => null,
|
||||||
|
'modifier' => null,
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'en_US.UTF-8' => [
|
'en_US.UTF-8' => [
|
||||||
'en_US.UTF-8',
|
'en_US.UTF-8',
|
||||||
@@ -662,7 +606,13 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
'en_US.UTF-8',
|
'en_US.UTF-8',
|
||||||
'en_US',
|
'en_US',
|
||||||
'en',
|
'en',
|
||||||
]
|
],
|
||||||
|
[
|
||||||
|
'lang' => 'en',
|
||||||
|
'country' => 'US',
|
||||||
|
'charset' => 'UTF-8',
|
||||||
|
'modifier' => null,
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'en_US@subtext' => [
|
'en_US@subtext' => [
|
||||||
'en_US@subtext',
|
'en_US@subtext',
|
||||||
@@ -671,7 +621,13 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
'en@subtext',
|
'en@subtext',
|
||||||
'en_US',
|
'en_US',
|
||||||
'en',
|
'en',
|
||||||
]
|
],
|
||||||
|
[
|
||||||
|
'lang' => 'en',
|
||||||
|
'country' => 'US',
|
||||||
|
'charset' => null,
|
||||||
|
'modifier' => 'subtext',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'en_US.UTF-8@subtext' => [
|
'en_US.UTF-8@subtext' => [
|
||||||
'en_US.UTF-8@subtext',
|
'en_US.UTF-8@subtext',
|
||||||
@@ -682,7 +638,13 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
'en_US.UTF-8',
|
'en_US.UTF-8',
|
||||||
'en_US',
|
'en_US',
|
||||||
'en',
|
'en',
|
||||||
]
|
],
|
||||||
|
[
|
||||||
|
'lang' => 'en',
|
||||||
|
'country' => 'US',
|
||||||
|
'charset' => 'UTF-8',
|
||||||
|
'modifier' => 'subtext',
|
||||||
|
],
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -695,16 +657,24 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
* @testdox check $locale [$_dataName]
|
* @testdox check $locale [$_dataName]
|
||||||
*
|
*
|
||||||
* @param string $locale
|
* @param string $locale
|
||||||
* @param array $expected
|
* @param array $expected_list
|
||||||
|
* @param array $expected_detail
|
||||||
* @return void
|
* @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);
|
$locale_list = \CoreLibs\Language\L10n::listLocales($locale);
|
||||||
// print "LOCALES: " . print_r($locale_list, true) . "\n";
|
// print "LOCALES: " . print_r($locale_list, true) . "\n";
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected_list,
|
||||||
$locale_list
|
$locale_list,
|
||||||
|
'List locale assert failed'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -971,23 +941,23 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
// 0: lang/locale
|
// 0: lang/locale
|
||||||
// 1: path
|
// 1: domain
|
||||||
// 2: domain
|
// 2: path
|
||||||
// 3: encoding
|
// 3: encoding
|
||||||
// 4: string
|
// 4: string
|
||||||
// 5: translated string
|
// 5: translated string
|
||||||
'standard en' => [
|
'standard en' => [
|
||||||
'en_US.UTF-8',
|
'en_US.UTF-8',
|
||||||
__DIR__ . 'includes/locale/',
|
|
||||||
'frontend',
|
'frontend',
|
||||||
|
__DIR__ . 'includes/locale/',
|
||||||
'UTF-8',
|
'UTF-8',
|
||||||
'Original',
|
'Original',
|
||||||
'Translated frontend en_US',
|
'Translated frontend en_US',
|
||||||
],
|
],
|
||||||
'standard ja' => [
|
'standard ja' => [
|
||||||
'ja_JP.UTF-8',
|
'ja_JP.UTF-8',
|
||||||
__DIR__ . 'includes/locale/',
|
|
||||||
'admin',
|
'admin',
|
||||||
|
__DIR__ . 'includes/locale/',
|
||||||
'UTF-8',
|
'UTF-8',
|
||||||
'Original',
|
'Original',
|
||||||
'Translated admin ja_JP',
|
'Translated admin ja_JP',
|
||||||
@@ -997,7 +967,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* fuctions check
|
* fuctions check
|
||||||
* TODO: others d/dn/dp/dpn gettext functions
|
* TODO: others d/dn/dp/dnp gettext functions
|
||||||
*
|
*
|
||||||
* @covers __setlocale
|
* @covers __setlocale
|
||||||
* @covers __bindtextdomain
|
* @covers __bindtextdomain
|
||||||
@@ -1008,8 +978,8 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
* @dataProvider functionsProvider
|
* @dataProvider functionsProvider
|
||||||
* @testdox check functions with locale $locale and domain $domain [$_dataName]
|
* @testdox check functions with locale $locale and domain $domain [$_dataName]
|
||||||
* @param string $locale
|
* @param string $locale
|
||||||
* @param string $path
|
|
||||||
* @param string $domain
|
* @param string $domain
|
||||||
|
* @param string $path
|
||||||
* @param string $encoding
|
* @param string $encoding
|
||||||
* @param string $original
|
* @param string $original
|
||||||
* @param string $translated
|
* @param string $translated
|
||||||
@@ -1017,17 +987,17 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testFunctions(
|
public function testFunctions(
|
||||||
string $locale,
|
string $locale,
|
||||||
string $path,
|
|
||||||
string $domain,
|
string $domain,
|
||||||
|
string $path,
|
||||||
string $encoding,
|
string $encoding,
|
||||||
string $original,
|
string $original,
|
||||||
string $translated
|
string $translated
|
||||||
): void {
|
): void {
|
||||||
\CoreLibs\Language\L10n::loadFunctions();
|
\CoreLibs\Language\L10n::loadFunctions();
|
||||||
__setlocale(LC_MESSAGES, $locale);
|
_setlocale(LC_MESSAGES, $locale);
|
||||||
__textdomain($domain);
|
_textdomain($domain);
|
||||||
__bindtextdomain($domain, $path);
|
_bindtextdomain($domain, $path);
|
||||||
__bind_textdomain_codeset($domain, $encoding);
|
_bind_textdomain_codeset($domain, $encoding);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$translated,
|
$translated,
|
||||||
__($original),
|
__($original),
|
||||||
@@ -1035,7 +1005,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
|||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$translated,
|
$translated,
|
||||||
__gettext($original),
|
_gettext($original),
|
||||||
'function gettext assert failed'
|
'function gettext assert failed'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ if [ ! -f "locale/en_US/LC_MESSAGES/admin.mo" ]; then
|
|||||||
exit;
|
exit;
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
msgfmt -o locale/en_US/LC_MESSAGES/admin.mo locale/en_US.admin.UTF-8.po
|
for file in $(ls -1 locale/*.po); do
|
||||||
msgfmt -o locale/en_US/LC_MESSAGES/frontend.mo locale/en_US.frontend.UTF-8.po
|
echo $file;
|
||||||
msgfmt -o locale/ja_JP/LC_MESSAGES/admin.mo locale/ja_JP.admin.UTF-8.po
|
file=$(basename $file .po);
|
||||||
msgfmt -o locale/ja_JP/LC_MESSAGES/frontend.mo locale/ja_JP.frontend.UTF-8.po
|
locale=$(echo "${file}" | cut -d "-" -f 1);
|
||||||
|
domain=$(echo "${file}" | cut -d "-" -f 2);
|
||||||
|
msgfmt -o locale/${locale}/LC_MESSAGES/${domain}.mo locale/${locale}-${domain}.po;
|
||||||
|
done;
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../../locale/en_US/LC_MESSAGES/admin.mo
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../locale/ja_JP/LC_MESSAGES/admin.mo
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../locale/en_US/LC_MESSAGES/frontend.mo
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../locale/ja_JP/LC_MESSAGES/frontend.mo
|
|
||||||
@@ -44,9 +44,24 @@ $db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
|||||||
// login & page access check
|
// login & page access check
|
||||||
$login = new CoreLibs\ACL\Login($db, $log);
|
$login = new CoreLibs\ACL\Login($db, $log);
|
||||||
```
|
```
|
||||||
|
* update language class
|
||||||
|
```php
|
||||||
|
// 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'],
|
||||||
|
);
|
||||||
|
```
|
||||||
|
* smarty needs language
|
||||||
|
```php
|
||||||
|
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
|
||||||
|
```
|
||||||
* admin backend also needs logger
|
* admin backend also needs logger
|
||||||
```php
|
```php
|
||||||
$cms = new CoreLibs\Admin\Backend($db, $log);
|
$cms = new CoreLibs\Admin\Backend($db, $log, $l10n, $locale);
|
||||||
```
|
```
|
||||||
* update and `$cms` or similar calls so db is in `$cms->db->...` and log are in `$cms->log->...`
|
* update and `$cms` or similar calls so db is in `$cms->db->...` and log are in `$cms->log->...`
|
||||||
* update all `config.*.php` files where needed
|
* update all `config.*.php` files where needed
|
||||||
@@ -60,6 +75,12 @@ require BASE . LIB . 'autoloader.php';
|
|||||||
```
|
```
|
||||||
**UPDATE:**
|
**UPDATE:**
|
||||||
```php
|
```php
|
||||||
|
// po langs [DEPRECAED: use LOCALE]
|
||||||
|
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
||||||
|
// po locale file
|
||||||
|
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||||
|
```
|
||||||
|
```php
|
||||||
// SSL host name
|
// SSL host name
|
||||||
// define('SSL_HOST', $_ENV['SSL_HOST'] ?? '');
|
// define('SSL_HOST', $_ENV['SSL_HOST'] ?? '');
|
||||||
```
|
```
|
||||||
@@ -85,6 +106,13 @@ define('CONTENT_WIDTH', '100%');
|
|||||||
define('BASE_NAME', preg_replace('/[^A-Za-z0-9]/', '', $_ENV['BASE_NAME'] ?? ''));
|
define('BASE_NAME', preg_replace('/[^A-Za-z0-9]/', '', $_ENV['BASE_NAME'] ?? ''));
|
||||||
```
|
```
|
||||||
```php
|
```php
|
||||||
|
/************* LANGUAGE / ENCODING *******/
|
||||||
|
// default lang + encoding
|
||||||
|
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||||
|
// default web page encoding setting
|
||||||
|
define('DEFAULT_ENCODING', 'UTF-8');
|
||||||
|
```
|
||||||
|
```php
|
||||||
// BAIL ON MISSING DB CONFIG:
|
// BAIL ON MISSING DB CONFIG:
|
||||||
// we have either no db selction for this host but have db config entries
|
// we have either no db selction for this host but have db config entries
|
||||||
// or we have a db selection but no db config as array or empty
|
// or we have a db selection but no db config as array or empty
|
||||||
@@ -104,6 +132,10 @@ if (
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
```php
|
```php
|
||||||
|
// remove SITE_LANG
|
||||||
|
define('SITE_LOCALE', $SITE_CONFIG[HOST_NAME]['site_locale'] ?? DEFAULT_LOCALE);
|
||||||
|
define('SITE_ENCODING', $SITE_CONFIG[HOST_NAME]['site_encoding'] ?? DEFAULT_ENCODING);
|
||||||
|
```
|
||||||
```php
|
```php
|
||||||
/************* GENERAL PAGE TITLE ********/
|
/************* GENERAL PAGE TITLE ********/
|
||||||
define('G_TITLE', $_ENV['G_TITLE'] ?? '');
|
define('G_TITLE', $_ENV['G_TITLE'] ?? '');
|
||||||
@@ -118,6 +150,15 @@ In the config then
|
|||||||
```php
|
```php
|
||||||
'db_name' => $_ENV['DB_NAME.TEST'] ?? '',
|
'db_name' => $_ENV['DB_NAME.TEST'] ?? '',
|
||||||
```
|
```
|
||||||
|
* config.host.php update
|
||||||
|
must add site_locale (site_lang + site_encoding)
|
||||||
|
remove site_lang
|
||||||
|
```php
|
||||||
|
// lang + encoding
|
||||||
|
'site_locale' => 'en_US.UTF-8',
|
||||||
|
// site language
|
||||||
|
'site_encoding' => 'UTF-8',
|
||||||
|
```
|
||||||
* copy `layout/admin/javascript/edit.jq.js`
|
* copy `layout/admin/javascript/edit.jq.js`
|
||||||
* check other javacsript files if needed (`edit.jq.js`)
|
* check other javacsript files if needed (`edit.jq.js`)
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,13 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
]);
|
]);
|
||||||
// db config with logger
|
// db config with logger
|
||||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
$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 "<!DOCTYPE html>";
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: ADMIN BACKEND</title><head>";
|
print "<html><head><title>TEST CLASS: ADMIN BACKEND</title><head>";
|
||||||
@@ -51,7 +57,7 @@ print "<body>";
|
|||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|
||||||
// set acl, from eg login acl
|
// set acl, from eg login acl
|
||||||
print "SETACL[]: " . $backend->setACL([]) . "<br>";
|
print "SETACL[]: " . $backend->setACL(['EMPTY' => 'EMPTY']) . "<br>";
|
||||||
print "ADBEDITLOG: " . $backend->adbEditLog('CLASSTEST-ADMIN', 'Some info stirng') . "<br>";
|
print "ADBEDITLOG: " . $backend->adbEditLog('CLASSTEST-ADMIN', 'Some info stirng') . "<br>";
|
||||||
print "ADBTOPMENU(0): " . \CoreLibs\Debug\Support::printAr($backend->adbTopMenu()) . "<br>";
|
print "ADBTOPMENU(0): " . \CoreLibs\Debug\Support::printAr($backend->adbTopMenu()) . "<br>";
|
||||||
print "ADBMSG: " . $backend->adbMsg('info', 'Message: %1$d', [1]) . "<br>";
|
print "ADBMSG: " . $backend->adbMsg('info', 'Message: %1$d', [1]) . "<br>";
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ ob_start();
|
|||||||
|
|
||||||
// basic class test file
|
// basic class test file
|
||||||
define('USE_DATABASE', false);
|
define('USE_DATABASE', false);
|
||||||
// init language
|
|
||||||
$lang = 'en_utf8';
|
|
||||||
// sample config
|
// sample config
|
||||||
require 'config.php';
|
require 'config.php';
|
||||||
// set session name
|
// set session name
|
||||||
@@ -37,18 +35,53 @@ print "<body>";
|
|||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|
||||||
use CoreLibs\Language\L10n;
|
use CoreLibs\Language\L10n;
|
||||||
|
use CoreLibs\Debug\Support;
|
||||||
|
|
||||||
|
echo "<br><b>LIST LOCALES</b><br>";
|
||||||
|
|
||||||
|
$locale = 'en_US.UTF-8';
|
||||||
|
$locales = CoreLibs\Language\L10n::listLocales($locale);
|
||||||
|
print "[" . $locale . "] LOCALES: " . Support::printAr($locales) . "<br>";
|
||||||
|
$locale = 'en.UTF-8';
|
||||||
|
$locales = CoreLibs\Language\L10n::listLocales($locale);
|
||||||
|
print "[" . $locale . "] LOCALES: " . Support::printAr($locales) . "<br>";
|
||||||
|
|
||||||
|
echo "<br><b>LOCALE INFO</b><br>";
|
||||||
|
$locale = 'en_US.UTF-8';
|
||||||
|
$locale_info = CoreLibs\Language\L10n::parseLocale($locale);
|
||||||
|
print "[" . $locale . "] INFO: " . Support::printAr($locale_info) . "<br>";
|
||||||
|
$locale = 'en.UTF-8';
|
||||||
|
$locale_info = CoreLibs\Language\L10n::parseLocale($locale);
|
||||||
|
print "[" . $locale . "] INFO: " . Support::printAr($locale_info) . "<br>";
|
||||||
|
|
||||||
|
echo "<br><b>AUTO DETECT</b><br>";
|
||||||
|
|
||||||
|
$get_locale = \CoreLibs\Language\GetLocale::setLocale();
|
||||||
|
print "[AUTO]: " . Support::printAr($get_locale) . "<br>";
|
||||||
|
$get_locale = \CoreLibs\Language\GetLocale::setLocale('en', 'foo', 'ISO-8895');
|
||||||
|
print "[OVERRIDE]: " . Support::printAr($get_locale) . "<br>";
|
||||||
|
|
||||||
|
// try to load non existing
|
||||||
|
echo "<br><b>NEW TYPE</b><br>";
|
||||||
|
// translate string
|
||||||
$string = 'INPUT TEST';
|
$string = 'INPUT TEST';
|
||||||
|
// new path test
|
||||||
echo "<br><b>LEGACY TEST</b><br>";
|
$lang = 'ja';
|
||||||
|
$domain = 'admin';
|
||||||
$lang = 'en_utf8';
|
$encoding = 'UTF-8';
|
||||||
$l = new CoreLibs\Language\L10n($lang);
|
$path = BASE . INCLUDES . LOCALE;
|
||||||
|
// load direct
|
||||||
|
$l = new CoreLibs\Language\L10n($lang, $domain, $path);
|
||||||
echo "*<br>";
|
echo "*<br>";
|
||||||
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
|
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
|
||||||
|
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
|
||||||
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
|
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
|
||||||
|
echo "CONTENT PATH: " . $l->getBaseContentPath() . "<br>";
|
||||||
|
echo "DOMAIN PATH: " . $l->getTextDomain($domain) . "<br>";
|
||||||
|
echo "BASE PATH: " . $l->getBaseLocalePath() . "<br>";
|
||||||
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
|
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
|
||||||
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
|
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
|
||||||
|
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
|
||||||
$single_string = 'single';
|
$single_string = 'single';
|
||||||
$multi_string = 'multi';
|
$multi_string = 'multi';
|
||||||
for ($n = 0; $n <= 3; $n++) {
|
for ($n = 0; $n <= 3; $n++) {
|
||||||
@@ -62,63 +95,38 @@ $single_string = 'single';
|
|||||||
$multi_string = 'multi';
|
$multi_string = 'multi';
|
||||||
for ($n = 0; $n <= 3; $n++) {
|
for ($n = 0; $n <= 3; $n++) {
|
||||||
echo "CONTEXT MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
|
echo "CONTEXT MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
|
||||||
. $l->__pn($context, $single_string, $multi_string, $n) . "<br>";
|
. $l->__np($context, $single_string, $multi_string, $n) . "<br>";
|
||||||
}
|
}
|
||||||
|
// change domain
|
||||||
// switch to other language
|
|
||||||
$lang = 'ja_utf8';
|
|
||||||
$l->l10nReloadMOfile($lang);
|
|
||||||
echo "*<br>";
|
|
||||||
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
|
|
||||||
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
|
|
||||||
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
|
|
||||||
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
|
|
||||||
// switch to non existing language
|
|
||||||
$lang = 'tr_utf8';
|
|
||||||
$l->l10nReloadMOfile($lang);
|
|
||||||
echo "*<br>";
|
|
||||||
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
|
|
||||||
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
|
|
||||||
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
|
|
||||||
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
|
|
||||||
|
|
||||||
echo "<br><b>LIST LOCALES</b><br>";
|
|
||||||
|
|
||||||
$locale = 'en_US.UTF-8';
|
|
||||||
$locales = CoreLibs\Language\L10n::listLocales($locale);
|
|
||||||
print "[" . $locale . "] LOCALES: " . CoreLibs\Debug\Support::printAr($locales) . "<br>";
|
|
||||||
$locale = 'en.UTF-8';
|
|
||||||
$locales = CoreLibs\Language\L10n::listLocales($locale);
|
|
||||||
print "[" . $locale . "] LOCALES: " . CoreLibs\Debug\Support::printAr($locales) . "<br>";
|
|
||||||
|
|
||||||
// try to load non existing
|
|
||||||
echo "<br><b>NEW TYPE</b><br>";
|
|
||||||
// new path test
|
|
||||||
$lang = 'ja';
|
|
||||||
$domain = 'admin';
|
|
||||||
$encoding = 'UTF-8';
|
|
||||||
$path = BASE . INCLUDES . LOCALE;
|
|
||||||
$l = new CoreLibs\Language\L10n($lang, $path, $domain, false);
|
|
||||||
|
|
||||||
echo "*<br>";
|
|
||||||
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
|
|
||||||
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
|
|
||||||
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
|
|
||||||
echo "CONTENT PATH: " . $l->getBaseContentPath() . "<br>";
|
|
||||||
echo "DOMAIN PATH: " . $l->getTextDomain($domain) . "<br>";
|
|
||||||
echo "BASE PATH: " . $l->getBaseLocalePath() . "<br>";
|
|
||||||
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
|
|
||||||
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
|
|
||||||
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
|
|
||||||
$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) . "<br>";
|
|
||||||
}
|
|
||||||
|
|
||||||
$domain = 'frontend';
|
$domain = 'frontend';
|
||||||
$l->getTranslator('', $path, $domain);
|
$l->getTranslator('', $domain, $path);
|
||||||
|
echo "*<br>";
|
||||||
|
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
|
||||||
|
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
|
||||||
|
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
|
||||||
|
echo "CONTENT PATH: " . $l->getBaseContentPath() . "<br>";
|
||||||
|
echo "DOMAIN PATH: " . $l->getTextDomain($domain) . "<br>";
|
||||||
|
echo "BASE PATH: " . $l->getBaseLocalePath() . "<br>";
|
||||||
|
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
|
||||||
|
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
|
||||||
|
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
|
||||||
|
// change language short type
|
||||||
|
$lang = 'en';
|
||||||
|
$domain = 'admin';
|
||||||
|
$l->getTranslator($lang, $domain, $path);
|
||||||
|
echo "*<br>";
|
||||||
|
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
|
||||||
|
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
|
||||||
|
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
|
||||||
|
echo "CONTENT PATH: " . $l->getBaseContentPath() . "<br>";
|
||||||
|
echo "DOMAIN PATH: " . $l->getTextDomain($domain) . "<br>";
|
||||||
|
echo "BASE PATH: " . $l->getBaseLocalePath() . "<br>";
|
||||||
|
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
|
||||||
|
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
|
||||||
|
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
|
||||||
|
// chang to wrong language
|
||||||
|
$lang = 'tr';
|
||||||
|
$l->getTranslator($lang, $domain, $path);
|
||||||
echo "*<br>";
|
echo "*<br>";
|
||||||
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
|
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
|
||||||
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
|
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
|
||||||
@@ -130,6 +138,7 @@ echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
|
|||||||
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
|
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
|
||||||
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
|
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
|
||||||
|
|
||||||
|
$lang = 'en';
|
||||||
$domain = 'admin';
|
$domain = 'admin';
|
||||||
echo "<br><b>STATIC TYPE TEST</b><br>";
|
echo "<br><b>STATIC TYPE TEST</b><br>";
|
||||||
// static tests from l10n_load
|
// static tests from l10n_load
|
||||||
@@ -146,18 +155,30 @@ echo "<br><b>FUNCTIONS</b><br>";
|
|||||||
// real statisc test
|
// real statisc test
|
||||||
L10n::loadFunctions();
|
L10n::loadFunctions();
|
||||||
$locale = 'ja';
|
$locale = 'ja';
|
||||||
__setlocale(LC_MESSAGES, $locale);
|
_setlocale(LC_MESSAGES, $locale);
|
||||||
__textdomain($domain);
|
_textdomain($domain);
|
||||||
__bindtextdomain($domain, $path);
|
_bindtextdomain($domain, $path);
|
||||||
__bind_textdomain_codeset($domain, $encoding);
|
_bind_textdomain_codeset($domain, $encoding);
|
||||||
echo "INPUT TEST $locale: " . $string . " => " . __($string) . "<br>";
|
echo "INPUT TEST $locale: " . $string . " => " . __($string) . "<br>";
|
||||||
|
$single_string = 'single';
|
||||||
|
$multi_string = 'multi';
|
||||||
|
for ($n = 0; $n <= 3; $n++) {
|
||||||
|
echo "MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
|
||||||
|
. _ngettext($single_string, $multi_string, $n) . "<br>";
|
||||||
|
}
|
||||||
|
|
||||||
$locale = 'en_US.UTF-8';
|
$locale = 'en_US.UTF-8';
|
||||||
__setlocale(LC_MESSAGES, $locale);
|
_setlocale(LC_MESSAGES, $locale);
|
||||||
__textdomain($domain);
|
_textdomain($domain);
|
||||||
__bindtextdomain($domain, $path);
|
_bindtextdomain($domain, $path);
|
||||||
__bind_textdomain_codeset($domain, $encoding);
|
_bind_textdomain_codeset($domain, $encoding);
|
||||||
echo "INPUT TEST $locale: " . $string . " => " . __($string) . "<br>";
|
echo "INPUT TEST $locale: " . $string . " => " . __($string) . "<br>";
|
||||||
|
$single_string = 'single';
|
||||||
|
$multi_string = 'multi';
|
||||||
|
for ($n = 0; $n <= 3; $n++) {
|
||||||
|
echo "MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
|
||||||
|
. _ngettext($single_string, $multi_string, $n) . "<br>";
|
||||||
|
}
|
||||||
|
|
||||||
print "</body></html>";
|
print "</body></html>";
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,13 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
]);
|
]);
|
||||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||||
$login = new CoreLibs\ACL\Login($db, $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);
|
$backend->db->dbInfo(true);
|
||||||
ob_end_flush();
|
ob_end_flush();
|
||||||
|
|
||||||
@@ -79,9 +85,10 @@ print '<div><a href="class_test.smarty.php">Class Test: SMARTY</a></div>';
|
|||||||
print '<div><a href="class_test.autoloader.php">Class Test: AUTOLOADER</a></div>';
|
print '<div><a href="class_test.autoloader.php">Class Test: AUTOLOADER</a></div>';
|
||||||
|
|
||||||
print "<hr>";
|
print "<hr>";
|
||||||
|
print "L: " . CoreLibs\Debug\Support::printAr($locale) . "<br>";
|
||||||
// print all _ENV vars set
|
// print all _ENV vars set
|
||||||
print "<div>READ _ENV ARRAY:</div>";
|
print "<div>READ _ENV ARRAY:</div>";
|
||||||
print "<pre>" . print_r(array_map('htmlentities', $_ENV), true) . "</pre>";
|
print CoreLibs\Debug\Support::printAr(array_map('htmlentities', $_ENV));
|
||||||
// set + check edit access id
|
// set + check edit access id
|
||||||
$edit_access_id = 3;
|
$edit_access_id = 3;
|
||||||
if (is_object($login) && isset($login->acl['unit'])) {
|
if (is_object($login) && isset($login->acl['unit'])) {
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ ob_start();
|
|||||||
|
|
||||||
// basic class test file
|
// basic class test file
|
||||||
define('USE_DATABASE', true);
|
define('USE_DATABASE', true);
|
||||||
// set language
|
|
||||||
$lang = 'en_utf8';
|
|
||||||
// sample config
|
// sample config
|
||||||
require 'config.php';
|
require 'config.php';
|
||||||
// override ECHO ALL FALSE
|
// override ECHO ALL FALSE
|
||||||
@@ -43,8 +41,13 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
'echo_all' => $ECHO_ALL ?? false,
|
'echo_all' => $ECHO_ALL ?? false,
|
||||||
'print_all' => $PRINT_ALL ?? false,
|
'print_all' => $PRINT_ALL ?? false,
|
||||||
]);
|
]);
|
||||||
$smarty = new CoreLibs\Template\SmartyExtend();
|
$locale = \CoreLibs\Language\GetLocale::setLocale();
|
||||||
$l = new CoreLibs\Language\L10n($lang);
|
$l10n = new \CoreLibs\Language\L10n(
|
||||||
|
$locale['locale'],
|
||||||
|
$locale['domain'],
|
||||||
|
$locale['path'],
|
||||||
|
);
|
||||||
|
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
|
||||||
|
|
||||||
print "<!DOCTYPE html>";
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: SMARTY</title><head>";
|
print "<html><head><title>TEST CLASS: SMARTY</title><head>";
|
||||||
@@ -70,7 +73,8 @@ $smarty->setSmartyPaths();
|
|||||||
|
|
||||||
// smarty test
|
// smarty test
|
||||||
$smarty->DATA['SMARTY_TEST'] = 'Test Data';
|
$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_FUNCTION'] = _gettext('Are we translated?');
|
||||||
$smarty->DATA['TRANSLATE_TEST_SMARTY'] = $smarty->l10n->__('Are we translated?');
|
$smarty->DATA['TRANSLATE_TEST_SMARTY'] = $smarty->l10n->__('Are we translated?');
|
||||||
$smarty->DATA['replace'] = 'Replaced';
|
$smarty->DATA['replace'] = 'Replaced';
|
||||||
// variable variables
|
// variable variables
|
||||||
|
|||||||
@@ -27,9 +27,8 @@ $__LOCAL_CONFIG = [
|
|||||||
'db_host' => 'test',
|
'db_host' => 'test',
|
||||||
'location' => 'test',
|
'location' => 'test',
|
||||||
'debug_flag' => true,
|
'debug_flag' => true,
|
||||||
'site_lang' => 'en_US',
|
|
||||||
'site_encoding' => 'UTF-8',
|
|
||||||
'site_locale' => 'en_US.UTF-8',
|
'site_locale' => 'en_US.UTF-8',
|
||||||
|
'site_encoding' => 'UTF-8',
|
||||||
'login_enabled' => true
|
'login_enabled' => true
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -46,11 +45,10 @@ $SITE_CONFIG = [
|
|||||||
'location' => 'test',
|
'location' => 'test',
|
||||||
// show DEBUG override
|
// show DEBUG override
|
||||||
'debug_flag' => true,
|
'debug_flag' => true,
|
||||||
// site language
|
// site locale
|
||||||
'site_lang' => 'en_US',
|
|
||||||
'site_encoding' => 'UTF-8',
|
|
||||||
// lang + encoding
|
|
||||||
'site_locale' => 'en_US.UTF-8',
|
'site_locale' => 'en_US.UTF-8',
|
||||||
|
// site encoding
|
||||||
|
'site_encoding' => 'UTF-8',
|
||||||
// enable/disable login override
|
// enable/disable login override
|
||||||
'login_enabled' => true
|
'login_enabled' => true
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -65,8 +65,6 @@ define('JS', 'javascript' . DIRECTORY_SEPARATOR);
|
|||||||
define('TABLE_ARRAYS', 'table_arrays' . DIRECTORY_SEPARATOR);
|
define('TABLE_ARRAYS', 'table_arrays' . DIRECTORY_SEPARATOR);
|
||||||
// smarty libs path
|
// smarty libs path
|
||||||
define('SMARTY', 'Smarty' . DIRECTORY_SEPARATOR);
|
define('SMARTY', 'Smarty' . DIRECTORY_SEPARATOR);
|
||||||
// po langs [DEPRECAED: use LOCALE]
|
|
||||||
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
|
||||||
// po locale file
|
// po locale file
|
||||||
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||||
// cache path
|
// cache path
|
||||||
@@ -160,11 +158,10 @@ define('CACHE_ID', 'CACHE_' . BASE_NAME . '_' . SERVER_NAME_HASH);
|
|||||||
define('COMPILE_ID', 'COMPILE_' . BASE_NAME . '_' . SERVER_NAME_HASH);
|
define('COMPILE_ID', 'COMPILE_' . BASE_NAME . '_' . SERVER_NAME_HASH);
|
||||||
|
|
||||||
/************* LANGUAGE / ENCODING *******/
|
/************* LANGUAGE / ENCODING *******/
|
||||||
define('DEFAULT_LANG', 'en_US');
|
|
||||||
// default web page encoding setting
|
|
||||||
define('DEFAULT_ENCODING', 'UTF-8');
|
|
||||||
// default lang + encoding
|
// default lang + encoding
|
||||||
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||||
|
// default web page encoding setting
|
||||||
|
define('DEFAULT_ENCODING', 'UTF-8');
|
||||||
|
|
||||||
/************* LOGGING *******************/
|
/************* LOGGING *******************/
|
||||||
// below two can be defined here, but they should be
|
// below two can be defined here, but they should be
|
||||||
@@ -262,9 +259,8 @@ $GLOBALS['DB_CONFIG'] = DB_CONFIG;
|
|||||||
// debug settings, site lang, etc
|
// debug settings, site lang, etc
|
||||||
define('TARGET', $SITE_CONFIG[HOST_NAME]['location'] ?? 'test');
|
define('TARGET', $SITE_CONFIG[HOST_NAME]['location'] ?? 'test');
|
||||||
define('DEBUG', $SITE_CONFIG[HOST_NAME]['debug_flag'] ?? false);
|
define('DEBUG', $SITE_CONFIG[HOST_NAME]['debug_flag'] ?? false);
|
||||||
define('SITE_LANG', $SITE_CONFIG[HOST_NAME]['site_lang'] ?? DEFAULT_LANG);
|
|
||||||
define('SITE_ENCODING', $SITE_CONFIG[HOST_NAME]['site_encoding'] ?? DEFAULT_ENCODING);
|
|
||||||
define('SITE_LOCALE', $SITE_CONFIG[HOST_NAME]['site_locale'] ?? DEFAULT_LOCALE);
|
define('SITE_LOCALE', $SITE_CONFIG[HOST_NAME]['site_locale'] ?? DEFAULT_LOCALE);
|
||||||
|
define('SITE_ENCODING', $SITE_CONFIG[HOST_NAME]['site_encoding'] ?? DEFAULT_ENCODING);
|
||||||
define('LOGIN_ENABLED', $SITE_CONFIG[HOST_NAME]['login_enabled'] ?? false);
|
define('LOGIN_ENABLED', $SITE_CONFIG[HOST_NAME]['login_enabled'] ?? false);
|
||||||
define('AUTH', $SITE_CONFIG[HOST_NAME]['auth'] ?? false);
|
define('AUTH', $SITE_CONFIG[HOST_NAME]['auth'] ?? false);
|
||||||
// paths
|
// paths
|
||||||
|
|||||||
@@ -53,9 +53,14 @@ if (!defined('DIR')) {
|
|||||||
// find trigger name "admin/" or "frontend/" in the getcwd() folder
|
// find trigger name "admin/" or "frontend/" in the getcwd() folder
|
||||||
foreach (['admin', 'frontend'] as $folder) {
|
foreach (['admin', 'frontend'] as $folder) {
|
||||||
if (strstr(getcwd() ?: '', DIRECTORY_SEPARATOR . $folder)) {
|
if (strstr(getcwd() ?: '', DIRECTORY_SEPARATOR . $folder)) {
|
||||||
define('CONTENT_PATH', $folder . DIRECTORY_SEPARATOR);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// if content path is empty, fallback is default
|
||||||
|
/** @phpstan-ignore-next-line can be empty */
|
||||||
|
if (empty($folder)) {
|
||||||
|
$folder = 'default';
|
||||||
|
}
|
||||||
|
define('CONTENT_PATH', $folder . DIRECTORY_SEPARATOR);
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/********************************************************************
|
|
||||||
* AUTHOR: Clemens Schwaighofer
|
|
||||||
* CREATED: 2005/07/19
|
|
||||||
* SHORT DESCRIPTION:
|
|
||||||
* preset date variables
|
|
||||||
* HISTORY:
|
|
||||||
*********************************************************************/
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
/******
|
|
||||||
All moved to CoreLibs\Combined\DateTime
|
|
||||||
DAY_SHORT
|
|
||||||
DAY_LONG
|
|
||||||
MONTH_LONG
|
|
||||||
MONTH_SHORT
|
|
||||||
*******/
|
|
||||||
trigger_error(
|
|
||||||
'Date.VArs.php is deprecated. '
|
|
||||||
. 'Use CoreLibs\Combined\DateTime:: with upper case old variable name',
|
|
||||||
E_USER_DEPRECATED
|
|
||||||
);
|
|
||||||
|
|
||||||
$day_short = [
|
|
||||||
1 => '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__
|
|
||||||
@@ -72,10 +72,19 @@ if (
|
|||||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||||
// login & page access check
|
// login & page access check
|
||||||
$login = new CoreLibs\ACL\Login($db, $log);
|
$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
|
// create smarty object
|
||||||
$smarty = new CoreLibs\Template\SmartyExtend();
|
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
|
||||||
// create new Backend class with db and loger attached
|
// 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)
|
// the menu show flag (what menu to show)
|
||||||
$cms->menu_show_flag = 'main';
|
$cms->menu_show_flag = 'main';
|
||||||
// db info
|
// db info
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/********************************************************************
|
|
||||||
* AUTHOR: Clemens Schwaighofer
|
|
||||||
* CREATED: 2007/09/03
|
|
||||||
* SHORT DESCRIPTION:
|
|
||||||
* set paths & language variables
|
|
||||||
* HISTORY:
|
|
||||||
*********************************************************************/
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
/******
|
|
||||||
NOTE THAT THIS INCLUDE IS OBSOLETE
|
|
||||||
USE THE BELOW FUNCTION CALL IN THE SCRIPT ITSELF
|
|
||||||
*******/
|
|
||||||
trigger_error('admin_set_paths.php is deprecated. Use SmartyExtended->setSmartyPaths();', E_USER_DEPRECATED);
|
|
||||||
if ($smarty) {
|
|
||||||
$smarty->setSmartyPaths();
|
|
||||||
}
|
|
||||||
|
|
||||||
// __END__
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/********************************************************************
|
|
||||||
* AUTHOR: Clemens Schwaighofer
|
|
||||||
* CREATED: 2005/07/12
|
|
||||||
* SHORT DESCRIPTION:
|
|
||||||
* default smarty vars, and create output template for smarty
|
|
||||||
* HISTORY:
|
|
||||||
*********************************************************************/
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
/******
|
|
||||||
NOTE THAT THIS INCLUDE IS OBSOLETE
|
|
||||||
USE THE BELOW FUNCTION CALL IN THE SCRIPT ITSELF
|
|
||||||
*******/
|
|
||||||
trigger_error(
|
|
||||||
'admin_smarty.php is deprecated. Use SmartyExtended->setSmartyVarsAdmin(); or setSmartyVarsFrontend();',
|
|
||||||
E_USER_DEPRECATED
|
|
||||||
);
|
|
||||||
$smarty->setSmartyVarsAdmin();
|
|
||||||
|
|
||||||
// __END__
|
|
||||||
@@ -61,18 +61,27 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||||
// login page
|
// login page
|
||||||
$login = new CoreLibs\ACL\Login($db, $log);
|
$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
|
// flush and start
|
||||||
ob_end_flush();
|
ob_end_flush();
|
||||||
// turn off set log per class
|
// turn off set log per class
|
||||||
$log->setLogPer('class', false);
|
$log->setLogPer('class', false);
|
||||||
// create form class
|
// 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) {
|
if ($form->mobile_phone) {
|
||||||
echo "I am sorry, but this page cannot be viewed by a mobile phone";
|
echo "I am sorry, but this page cannot be viewed by a mobile phone";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
// smarty template engine (extended Translation version)
|
// 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));
|
// $form->log->debug('POST', $form->log->prAr($_POST));
|
||||||
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../../locale/en_US/LC_MESSAGES/admin.mo
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../locale/ja/LC_MESSAGES/admin.mo
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../locale/en_US/LC_MESSAGES/frontend.mo
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../locale/ja/LC_MESSAGES/frontend.mo
|
|
||||||
Binary file not shown.
BIN
www/includes/locale/en/LC_MESSAGES/frontend.mo
Normal file
BIN
www/includes/locale/en/LC_MESSAGES/frontend.mo
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -7,13 +7,19 @@
|
|||||||
<div>
|
<div>
|
||||||
<b>Outside translation test</b><br>
|
<b>Outside translation test</b><br>
|
||||||
TRANSLATION CLASS (OUT): {$TRANSLATE_TEST}<br>
|
TRANSLATION CLASS (OUT): {$TRANSLATE_TEST}<br>
|
||||||
TRANSLATION CLASS (SMARTY): {$TRANSLATE_TEST_SMARTY}
|
TRANSLATION CLASS (OUT FUNCTION): {$TRANSLATE_TEST_FUNCTION}<br>
|
||||||
|
TRANSLATION CLASS (SMARTY): {$TRANSLATE_TEST_SMARTY}<br>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<b>Translate Test with replace:</b><br>
|
<b>Translate Test with replace:</b><br>
|
||||||
ORIGINAL: Original with string: %1 ({$replace})<br>
|
ORIGINAL: Original with string: %1 ({$replace})<br>
|
||||||
TRANSLATED: {t 1=$replace}Original with string: %1{/t}<br>
|
TRANSLATED: {t 1=$replace}Original with string: %1{/t}<br>
|
||||||
TRANSLATED (escape): {t escape=on 1=$replace}Original with string: %1{/t}
|
TRANSLATED (escape): {t escape=on 1=$replace}Original with string: %1{/t}<br>
|
||||||
|
{capture assign="extra_title"}{t}INPUT TEST{/t}{/capture}
|
||||||
|
Capture test: {$extra_title}<br>
|
||||||
|
{section name=plural_test start=0 loop=3}
|
||||||
|
Plural test {$smarty.section.plural_test.index}: {t count=$smarty.section.plural_test.index plural="multi"}single{/t}<br>
|
||||||
|
{/section}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<b>Variable variables:</b><br>
|
<b>Variable variables:</b><br>
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
<div>
|
|
||||||
{$SMARTY_TEST}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
TRANSLATION CLASS (OUT): {$TRANSLATE_TEST}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
TRANSLATION CLASS (SMARTY): {$TRANSLATE_TEST_SMARTY}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<select id="drop_down_test" name="drop_down_test">
|
|
||||||
{html_options options=$drop_down_test selected=$drop_down_test_selected}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="jq-container">
|
|
||||||
<div id="jq-test" class="jp-test">
|
|
||||||
<div id="test-div" class="test-div">
|
|
||||||
Some content here or asdfasdfasf
|
|
||||||
</div>
|
|
||||||
<div id="translate-div">
|
|
||||||
{* TRANSLATION SMARTY: {t}I should be translated{/t} *}
|
|
||||||
TRANSLATION SMARTY: I should be translated
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="loop-test">
|
|
||||||
<div>LOOP TEST</div>
|
|
||||||
{section name=page_list start=1 loop=$loop_start+1}
|
|
||||||
<div>LOOP OUTPUT: {$smarty.section.page_list.index}</div>
|
|
||||||
{/section}
|
|
||||||
</div>
|
|
||||||
{* progresss indicator *}
|
|
||||||
<div id="indicator"></div>
|
|
||||||
{* the action confirm box *}
|
|
||||||
<div id="actionBox" class="actionBoxElement"></div>
|
|
||||||
{* The Overlay box *}
|
|
||||||
<div id="overlayBox" class="overlayBoxElement"></div>
|
|
||||||
@@ -167,13 +167,10 @@ class Login
|
|||||||
* constructor, does ALL, opens db, works through connection checks, closes itself
|
* constructor, does ALL, opens db, works through connection checks, closes itself
|
||||||
* @param \CoreLibs\DB\IO $db Database connection class
|
* @param \CoreLibs\DB\IO $db Database connection class
|
||||||
* @param \CoreLibs\Debug\Logging $log Logging class
|
* @param \CoreLibs\Debug\Logging $log Logging class
|
||||||
* @param \CoreLibs\Language\L10n|null $l10n l10n language class
|
|
||||||
* if null, auto set
|
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
\CoreLibs\DB\IO $db,
|
\CoreLibs\DB\IO $db,
|
||||||
\CoreLibs\Debug\Logging $log,
|
\CoreLibs\Debug\Logging $log
|
||||||
?\CoreLibs\Language\L10n $l10n = null
|
|
||||||
) {
|
) {
|
||||||
// log login data for this class only
|
// log login data for this class only
|
||||||
$log->setLogPer('class', true);
|
$log->setLogPer('class', true);
|
||||||
@@ -215,19 +212,6 @@ class Login
|
|||||||
// or need to pass it back
|
// or need to pass it back
|
||||||
// to the continue AJAX class for output back to the user
|
// 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;
|
$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
|
// 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
|
// check what schema to use. if there is a login schema use this, else check
|
||||||
@@ -300,6 +284,24 @@ class Login
|
|||||||
$this->loginCheckPermissions();
|
$this->loginCheckPermissions();
|
||||||
// logsout user
|
// logsout user
|
||||||
$this->loginLogoutUser();
|
$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 the password change flag is okay, run the password change method
|
||||||
if ($this->password_change) {
|
if ($this->password_change) {
|
||||||
$this->loginPasswordChange();
|
$this->loginPasswordChange();
|
||||||
@@ -883,13 +885,13 @@ class Login
|
|||||||
$this->acl['show_ea_extra'] = false;
|
$this->acl['show_ea_extra'] = false;
|
||||||
}
|
}
|
||||||
// set the default edit access
|
// set the default edit access
|
||||||
$this->acl['default_edit_access'] = $_SESSION['UNIT_DEFAULT'];
|
$this->acl['default_edit_access'] = $_SESSION['UNIT_DEFAULT'] ?? null;
|
||||||
// integrate the type acl list, but only for the keyword -> level
|
// integrate the type acl list, but only for the keyword -> level
|
||||||
foreach ($this->default_acl_list as $level => $data) {
|
foreach ($this->default_acl_list as $level => $data) {
|
||||||
$this->acl['min'][$data['type']] = $level;
|
$this->acl['min'][$data['type']] = $level;
|
||||||
}
|
}
|
||||||
// set the full acl list too
|
// set the full acl list too
|
||||||
$this->acl['acl_list'] = $_SESSION['DEFAULT_ACL_LIST'];
|
$this->acl['acl_list'] = $_SESSION['DEFAULT_ACL_LIST'] ?? [];
|
||||||
// debug
|
// debug
|
||||||
// $this->debug('ACL', $this->print_ar($this->acl));
|
// $this->debug('ACL', $this->print_ar($this->acl));
|
||||||
}
|
}
|
||||||
@@ -1451,7 +1453,8 @@ EOM;
|
|||||||
* checks that the given edit access id is valid for this user
|
* checks that the given edit access id is valid for this user
|
||||||
* @param int|null $edit_access_id edit access id to check
|
* @param int|null $edit_access_id edit access id to check
|
||||||
* @return int|null same edit access id if ok
|
* @return int|null same edit access id if ok
|
||||||
* or the default edit access id if given one is not valid
|
* or the default edit access id
|
||||||
|
* if given one is not valid
|
||||||
*/
|
*/
|
||||||
public function loginCheckEditAccessId(?int $edit_access_id): ?int
|
public function loginCheckEditAccessId(?int $edit_access_id): ?int
|
||||||
{
|
{
|
||||||
@@ -1461,7 +1464,7 @@ EOM;
|
|||||||
is_array($_SESSION['UNIT']) &&
|
is_array($_SESSION['UNIT']) &&
|
||||||
!array_key_exists($edit_access_id, $_SESSION['UNIT'])
|
!array_key_exists($edit_access_id, $_SESSION['UNIT'])
|
||||||
) {
|
) {
|
||||||
return (int)$_SESSION['UNIT_DEFAULT'];
|
return $_SESSION['UNIT_DEFAULT'] ?? null;
|
||||||
} else {
|
} else {
|
||||||
return $edit_access_id;
|
return $edit_access_id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,15 +114,16 @@ class Backend
|
|||||||
// CONSTRUCTOR / DECONSTRUCTOR |====================================>
|
// CONSTRUCTOR / DECONSTRUCTOR |====================================>
|
||||||
/**
|
/**
|
||||||
* main class constructor
|
* main class constructor
|
||||||
* @param \CoreLibs\DB\IO $db Database connection class
|
* @param \CoreLibs\DB\IO $db Database connection class
|
||||||
* @param \CoreLibs\Debug\Logging $log Logging class
|
* @param \CoreLibs\Debug\Logging $log Logging class
|
||||||
* @param \CoreLibs\Language\L10n|null $l10n l10n language class
|
* @param \CoreLibs\Language\L10n $l10n l10n language class
|
||||||
* if null, auto set
|
* @param array<string,string> $locale locale data read from setLocale
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
\CoreLibs\DB\IO $db,
|
\CoreLibs\DB\IO $db,
|
||||||
\CoreLibs\Debug\Logging $log,
|
\CoreLibs\Debug\Logging $log,
|
||||||
?\CoreLibs\Language\L10n $l10n = null
|
\CoreLibs\Language\L10n $l10n,
|
||||||
|
array $locale
|
||||||
) {
|
) {
|
||||||
// set to log not per class
|
// set to log not per class
|
||||||
$log->setLogPer('class', false);
|
$log->setLogPer('class', false);
|
||||||
@@ -130,10 +131,15 @@ class Backend
|
|||||||
$this->log = $log;
|
$this->log = $log;
|
||||||
// attach db class
|
// attach db class
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
// TODO lang create outside of class
|
|
||||||
$this->setLangEncoding();
|
|
||||||
// get the language sub class & init it
|
// 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
|
// set the page name
|
||||||
$this->page_name = \CoreLibs\Get\System::getPageName();
|
$this->page_name = \CoreLibs\Get\System::getPageName();
|
||||||
@@ -159,29 +165,6 @@ class Backend
|
|||||||
// NO OP
|
// 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 |=================================================>
|
// PUBLIC METHODS |=================================================>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -218,7 +218,8 @@ class ArrayHandler
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
foreach ($array as $key => $value) {
|
foreach ($array as $key => $value) {
|
||||||
// if string or if key is assumed to be string do key match else add new entry
|
// if string or if key is assumed to be string do key match
|
||||||
|
// else add new entry
|
||||||
if (is_string($key) || $key_is_string === false) {
|
if (is_string($key) || $key_is_string === false) {
|
||||||
if (is_array($value) && array_key_exists($key, $merged) && is_array($merged[$key])) {
|
if (is_array($value) && array_key_exists($key, $merged) && is_array($merged[$key])) {
|
||||||
// $merged[$key] = call_user_func(__METHOD__, $merged[$key], $value, $key_is_string);
|
// $merged[$key] = call_user_func(__METHOD__, $merged[$key], $value, $key_is_string);
|
||||||
|
|||||||
@@ -503,7 +503,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
// max id, falls INSERT
|
// max id, falls INSERT
|
||||||
$q = 'SELECT MAX(' . $this->pk_name . ') + 1 AS pk_id FROM ' . $this->table_name;
|
$q = 'SELECT MAX(' . $this->pk_name . ') + 1 AS pk_id FROM ' . $this->table_name;
|
||||||
if (is_array($res = $this->dbReturnRow($q))) {
|
if (is_array($res = $this->dbReturnRow($q))) {
|
||||||
$pk_id = $res['pkd_id'];
|
$pk_id = $res['pk_id'];
|
||||||
} else {
|
} else {
|
||||||
$pk_id = 1;
|
$pk_id = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -353,7 +353,8 @@ class GetTextReader
|
|||||||
$expr .= ';';
|
$expr .= ';';
|
||||||
$res = '';
|
$res = '';
|
||||||
$p = 0;
|
$p = 0;
|
||||||
for ($i = 0; $i < strlen($expr); $i++) {
|
$expr_len = strlen($expr);
|
||||||
|
for ($i = 0; $i < $expr_len; $i++) {
|
||||||
$ch = $expr[$i];
|
$ch = $expr[$i];
|
||||||
switch ($ch) {
|
switch ($ch) {
|
||||||
case '?':
|
case '?':
|
||||||
@@ -433,6 +434,7 @@ class GetTextReader
|
|||||||
$total = 0;
|
$total = 0;
|
||||||
$plural = 0;
|
$plural = 0;
|
||||||
|
|
||||||
|
// FIXME use Symfony\Component\ExpressionLanguage\ExpressionLanguage or similar
|
||||||
eval("$string");
|
eval("$string");
|
||||||
/** @phpstan-ignore-next-line 0 >= 0 is always true*/
|
/** @phpstan-ignore-next-line 0 >= 0 is always true*/
|
||||||
if ($plural >= $total) {
|
if ($plural >= $total) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* Language\Encoding::__mbMimeEncode -> Convert\MimeEncode::__mbMimeEncode
|
* Language\Encoding::__mbMimeEncode -> Convert\MimeEncode::__mbMimeEncode
|
||||||
* Langauge\Encoding::checkConvertEncoding -> Check\Encoding::checkConvertEncoding
|
* Langauge\Encoding::checkConvertEncoding -> Check\Encoding::checkConvertEncoding
|
||||||
* Langauge\Encoding::setErrorChar -> Check\Encoding::setErrorChar
|
* Langauge\Encoding::setErrorChar -> Check\Encoding::setErrorChar
|
||||||
* Langauge\Encoding::getErrorChar -> Encoding::getErrorChar
|
* Langauge\Encoding::getErrorChar -> Check\Encoding::getErrorChar
|
||||||
* Langauge\Encoding::convertEncoding -> Convert\Encoding::convertEncoding
|
* Langauge\Encoding::convertEncoding -> Convert\Encoding::convertEncoding
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
117
www/lib/CoreLibs/Language/GetLocale.php
Normal file
117
www/lib/CoreLibs/Language/GetLocale.php
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Internal function for getting locale and encodig settings
|
||||||
|
* used for new locale layout
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Language;
|
||||||
|
|
||||||
|
class GetLocale
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* returns locale, lang, domain, encoding, path
|
||||||
|
* from either parameter set or from sessions/config variables
|
||||||
|
*
|
||||||
|
* @param string|null $locale override auto detect
|
||||||
|
* @param string|null $domain override domain
|
||||||
|
* @param string|null $encoding override encoding
|
||||||
|
* @param string|null $path override path
|
||||||
|
* @return array<string,string> 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<charset>[-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<lang>[a-z]{2,3})'
|
||||||
|
// country code
|
||||||
|
. '(?:_(?P<country>[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__
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Internal function for getting languange and encodig settings
|
|
||||||
*/
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace CoreLibs\Language;
|
|
||||||
|
|
||||||
class GetSettings
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Sets encoding and language
|
|
||||||
* Can be overridden with language + path to mo file
|
|
||||||
* If locale is set it must be in the format of:
|
|
||||||
* <lang>.<encoding>
|
|
||||||
* <lang>_<country>.<encoding>
|
|
||||||
* <lang>_<country>.<encoding>@<subset>
|
|
||||||
* If no encoding is set in the is, UTF-8 is assumed
|
|
||||||
*
|
|
||||||
* Returned is an array with array indes and dictionary index
|
|
||||||
* 0~4 array are
|
|
||||||
* encoding: 0
|
|
||||||
* lang: 1
|
|
||||||
* lang_short: 2
|
|
||||||
* domain: 3
|
|
||||||
* path: 4
|
|
||||||
*
|
|
||||||
* @param string|null $locale A valid locale name
|
|
||||||
* @param string|null $path A valid path where the mo files will be based
|
|
||||||
* @return array<int|string,string> Settings as array/dictionary
|
|
||||||
*/
|
|
||||||
public static function setLangEncoding(
|
|
||||||
?string $locale = null,
|
|
||||||
?string $domain = null,
|
|
||||||
?string $path = null
|
|
||||||
): array {
|
|
||||||
$lang = '';
|
|
||||||
$lang_short = '';
|
|
||||||
$encoding = '';
|
|
||||||
// if is is set, extract
|
|
||||||
if (!empty($locale)) {
|
|
||||||
preg_match(
|
|
||||||
// language code
|
|
||||||
'/^(?P<lang>[a-z]{2,3})'
|
|
||||||
// _ country code
|
|
||||||
. '(?:_(?P<country>[A-Z]{2}))?'
|
|
||||||
// . charset
|
|
||||||
. '(?:\\.(?P<charset>[-A-Za-z0-9_]+))?'
|
|
||||||
// @ modifier
|
|
||||||
. '(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/',
|
|
||||||
$locale,
|
|
||||||
$matches
|
|
||||||
);
|
|
||||||
// lang short part
|
|
||||||
$lang_short = $matches['lang'] ?? '';
|
|
||||||
$lang = $lang_short;
|
|
||||||
// lang + country if country is set
|
|
||||||
if (!empty($matches['country'])) {
|
|
||||||
$lang = sprintf('%s_%s', $lang_short, $matches['country']);
|
|
||||||
}
|
|
||||||
// encoding if set
|
|
||||||
$encoding = strtoupper($matches['charset'] ?? 'UTF-8');
|
|
||||||
}
|
|
||||||
// if domain is set, must be alphanumeric, if not unset
|
|
||||||
if (
|
|
||||||
!empty($domain) &&
|
|
||||||
!preg_match("/^\w+$/", $domain)
|
|
||||||
) {
|
|
||||||
$domain = '';
|
|
||||||
}
|
|
||||||
// path checks if set, if not valid path unset
|
|
||||||
if (
|
|
||||||
!empty($path) &&
|
|
||||||
!is_dir($path)
|
|
||||||
) {
|
|
||||||
$path = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
// just emergency fallback for language
|
|
||||||
// set encoding
|
|
||||||
if (empty($encoding)) {
|
|
||||||
if (!empty($_SESSION['DEFAULT_CHARSET'])) {
|
|
||||||
$encoding = $_SESSION['DEFAULT_CHARSET'];
|
|
||||||
} else {
|
|
||||||
$encoding = DEFAULT_ENCODING;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// gobal override
|
|
||||||
if (empty($lang)) {
|
|
||||||
if (!empty($GLOBALS['OVERRIDE_LANG'])) {
|
|
||||||
$lang = $GLOBALS['OVERRIDE_LANG'];
|
|
||||||
} elseif (!empty($_SESSION['DEFAULT_LANG'])) {
|
|
||||||
// session (login)
|
|
||||||
$lang = $_SESSION['DEFAULT_LANG'];
|
|
||||||
} else {
|
|
||||||
// mostly default SITE LANG or DEFAULT LANG
|
|
||||||
$lang = defined('SITE_LANG') && !empty(SITE_LANG) ?
|
|
||||||
SITE_LANG :
|
|
||||||
DEFAULT_LANG;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// create the char lang encoding
|
|
||||||
if (empty($lang_short)) {
|
|
||||||
$lang_short = substr($lang, 0, 2);
|
|
||||||
}
|
|
||||||
// set the language folder
|
|
||||||
if (empty($path)) {
|
|
||||||
// LEGACY
|
|
||||||
$path = BASE . INCLUDES . LANG . CONTENT_PATH;
|
|
||||||
// will be BASE . INCLUDES . LANG . $language . /LC_MESSAGES/
|
|
||||||
// so CONTENT_PATH has to be removed
|
|
||||||
}
|
|
||||||
// if no domain is set, fall back to content path
|
|
||||||
if (empty($domain)) {
|
|
||||||
$domain = str_replace('/', '', CONTENT_PATH);
|
|
||||||
}
|
|
||||||
// return
|
|
||||||
return [
|
|
||||||
// as array
|
|
||||||
0 => $encoding,
|
|
||||||
1 => $lang,
|
|
||||||
2 => $lang_short,
|
|
||||||
3 => $domain,
|
|
||||||
4 => $path,
|
|
||||||
// with index name
|
|
||||||
// encoding
|
|
||||||
'encoding' => $encoding,
|
|
||||||
// language full string, eg en_US
|
|
||||||
'lang' => $lang,
|
|
||||||
// lang short, if eg en_US only en
|
|
||||||
'lang_short' => $lang_short,
|
|
||||||
// translation domain (CONTENT_PATH)
|
|
||||||
'domain' => $domain,
|
|
||||||
// folder BASE ONLY
|
|
||||||
'path' => $path,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,34 +3,26 @@
|
|||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* AUTHOR: Clemens Schwaighofer
|
* AUTHOR: Clemens Schwaighofer
|
||||||
* CREATED: 2004/11/18
|
* CREATED: 2004/11/18
|
||||||
* VERSION: 1.0.0
|
* VERSION: 3.0.0
|
||||||
* RELEASED LICENSE: GNU GPL 3
|
* RELEASED LICENSE: GNU GPL 3
|
||||||
* SHORT DESCRIPTION:
|
* 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
|
* I changed that to a class to be more portable with my style of coding
|
||||||
*
|
* VERSION 3.0 (2022/4) removes all old folder layout and uses standard gettext
|
||||||
* PUBLIC VARIABLES
|
|
||||||
*
|
|
||||||
* PRIVATE VARIABLES
|
|
||||||
*
|
|
||||||
* PUBLIC METHODS
|
* PUBLIC METHODS
|
||||||
* __: returns string (translated or original if not found)
|
* __ : returns string (translated or original if not found)
|
||||||
* __e: echos out string (translated or original if not found)
|
* __n : plural string
|
||||||
* __n: should return plural. never tested this.
|
* __p : string with context
|
||||||
*
|
* __np: string with context and plural
|
||||||
* PRIVATE METHODS
|
|
||||||
*
|
*
|
||||||
* HISTORY:
|
* 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)
|
* 2005/10/17 (cs) made an on the fly switch method (reload of lang)
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
// TODO: default path change to <base>/lang/LC_MESSAGES/domain.encoding.mo
|
|
||||||
// for example: lang: ja_JP.UTF-8, domain: admin
|
|
||||||
// <base>/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);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace CoreLibs\Language;
|
namespace CoreLibs\Language;
|
||||||
@@ -48,15 +40,20 @@ class L10n
|
|||||||
private $domains = [];
|
private $domains = [];
|
||||||
/** @var array<string,string> bound paths for domains */
|
/** @var array<string,string> bound paths for domains */
|
||||||
private $paths = ['' => './'];
|
private $paths = ['' => './'];
|
||||||
|
|
||||||
|
// files
|
||||||
/** @var string the full path to the mo file to loaded */
|
/** @var string the full path to the mo file to loaded */
|
||||||
private $mofile = '';
|
private $mofile = '';
|
||||||
/** @var string base path to search level */
|
/** @var string base path to search level */
|
||||||
private $base_locale_path = '';
|
private $base_locale_path = '';
|
||||||
/** @var string dynamic set path to where the mo file is actually */
|
/** @var string dynamic set path to where the mo file is actually */
|
||||||
private $base_content_path = '';
|
private $base_content_path = '';
|
||||||
|
|
||||||
|
// errors
|
||||||
/** @var bool if load of mo file was unsuccessful */
|
/** @var bool if load of mo file was unsuccessful */
|
||||||
private $load_failure = false;
|
private $load_failure = false;
|
||||||
|
|
||||||
|
// object holders
|
||||||
/** @var FileReader|bool reader class for file reading, false for short circuit */
|
/** @var FileReader|bool reader class for file reading, false for short circuit */
|
||||||
private $input = false;
|
private $input = false;
|
||||||
/** @var GetTextReader reader class for MO data */
|
/** @var GetTextReader reader class for MO data */
|
||||||
@@ -74,20 +71,24 @@ class L10n
|
|||||||
*
|
*
|
||||||
* @param string $locale language name, default empty string
|
* @param string $locale language name, default empty string
|
||||||
* will return self instance
|
* 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 string $domain override CONTENT_PATH . $encoding name for mo file
|
||||||
* @param bool $legacy default true, if set to true, will look in the old
|
* @param string $path path, if empty fallback on default internal path
|
||||||
* folder format lang/ CONTENT_PATH / $lang . mo
|
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
string $locale = '',
|
string $locale = '',
|
||||||
string $path = '',
|
|
||||||
string $domain = '',
|
string $domain = '',
|
||||||
bool $legacy = true
|
string $path = '',
|
||||||
) {
|
) {
|
||||||
// load the mo file if locale is not empty
|
// auto load language only if at least locale and domain is set
|
||||||
if (!empty($locale)) {
|
if (!empty($locale) && !empty($domain)) {
|
||||||
$this->getTranslator($locale, $path, $domain, $legacy);
|
// 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';
|
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
|
* loads the mo file base on path, locale and domain set
|
||||||
*
|
*
|
||||||
* @param string $locale language name (optional), fallback is en
|
* @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 string $domain override CONTENT_PATH . $encoding name for mo file
|
||||||
* @param bool $legacy default true, if set to true, will look in the old
|
* @param string $path path, if empty fallback on default internal path
|
||||||
* folder format lang/ CONTENT_PATH / $lang . mo
|
|
||||||
* @return GetTextReader the main gettext reader object
|
* @return GetTextReader the main gettext reader object
|
||||||
*/
|
*/
|
||||||
public function getTranslator(
|
public function getTranslator(
|
||||||
string $locale = '',
|
string $locale = '',
|
||||||
string $path = '',
|
|
||||||
string $domain = '',
|
string $domain = '',
|
||||||
bool $legacy = false
|
string $path = ''
|
||||||
): GetTextReader {
|
): GetTextReader {
|
||||||
// set local if not from parameter
|
// set local if not from parameter
|
||||||
if (empty($locale)) {
|
if (empty($locale)) {
|
||||||
@@ -169,48 +145,34 @@ class L10n
|
|||||||
$old_base_locale_path = $this->base_locale_path;
|
$old_base_locale_path = $this->base_locale_path;
|
||||||
$old_base_content_path = $this->base_content_path;
|
$old_base_content_path = $this->base_content_path;
|
||||||
|
|
||||||
// legacy or new type
|
// if path is a dir
|
||||||
// legacy will use the old lang/content/file.mo type as default
|
// 1) from a previous set domain
|
||||||
// if path is not set, also locale is the file name
|
// 2) from method option as is
|
||||||
// for new type it follows the gettext spec and path is just the
|
// 3) fallback if BASE/INCLUDES/LOCALE set
|
||||||
// base folder where the mo files will be searched
|
// 4) current dir
|
||||||
if ($legacy === true) {
|
if (!empty($this->paths[$domain]) && is_dir($this->paths[$domain])) {
|
||||||
if (!is_dir($path)) {
|
$this->base_locale_path = $this->paths[$domain];
|
||||||
$this->base_locale_path = BASE . INCLUDES . LANG;
|
} elseif (is_dir($path)) {
|
||||||
$this->base_content_path = CONTENT_PATH;
|
$this->base_locale_path = $path;
|
||||||
$path = $this->base_locale_path . $this->base_content_path;
|
} elseif (
|
||||||
}
|
defined('BASE') && defined('INCLUDES') && defined('LOCALE')
|
||||||
$this->mofile = $path . $locale . ".mo";
|
) {
|
||||||
|
// set fallback base path if constant set
|
||||||
|
$this->base_locale_path = BASE . INCLUDES . LOCALE;
|
||||||
} else {
|
} else {
|
||||||
// if new path is a dir
|
$this->base_locale_path = './';
|
||||||
// 1) from a previous set domain
|
}
|
||||||
// 2) from method option as is
|
// now we loop over lang compositions to get the base path
|
||||||
// 3) fallback if BASE/INCLUDES/LOCALE set
|
// then we check
|
||||||
// 4) current dir
|
$locales = $this->listLocales($locale);
|
||||||
if (!empty($this->paths[$domain]) && is_dir($this->paths[$domain])) {
|
foreach ($locales as $_locale) {
|
||||||
$this->base_locale_path = $this->paths[$domain];
|
$this->base_content_path = $_locale . DIRECTORY_SEPARATOR
|
||||||
} elseif (is_dir($path)) {
|
. 'LC_MESSAGES' . DIRECTORY_SEPARATOR;
|
||||||
$this->base_locale_path = $path;
|
$this->mofile = $this->base_locale_path
|
||||||
} elseif (
|
. $this->base_content_path
|
||||||
defined('BASE') && defined('INCLUDES') && defined('LOCALE')
|
. $domain . '.mo';
|
||||||
) {
|
if (file_exists($this->mofile)) {
|
||||||
// set fallback base path if constant set
|
break;
|
||||||
$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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,6 +235,34 @@ class L10n
|
|||||||
return $this->l10n;
|
return $this->l10n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* parse the locale string for further processing
|
||||||
|
*
|
||||||
|
* @param string $locale Locale to parse
|
||||||
|
* @return array<string,string|null> array with lang, country, charset, modifier
|
||||||
|
*/
|
||||||
|
public static function parseLocale(string $locale = ''): array
|
||||||
|
{
|
||||||
|
preg_match(
|
||||||
|
// language code
|
||||||
|
'/^(?P<lang>[a-z]{2,3})'
|
||||||
|
// country code
|
||||||
|
. '(?:_(?P<country>[A-Z]{2}))?'
|
||||||
|
// charset
|
||||||
|
. '(?:\\.(?P<charset>[-A-Za-z0-9_]+))?'
|
||||||
|
// @ modifier
|
||||||
|
. '(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/',
|
||||||
|
$locale,
|
||||||
|
$matches
|
||||||
|
);
|
||||||
|
return [
|
||||||
|
'lang' => $matches['lang'] ?? null,
|
||||||
|
'country' => $matches['country'] ?? null,
|
||||||
|
'charset' => $matches['charset'] ?? null,
|
||||||
|
'modifier' => $matches['modifier'] ?? null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* original:
|
* original:
|
||||||
* vendor/phpmyadmin/motranslator/src/Loader.php
|
* vendor/phpmyadmin/motranslator/src/Loader.php
|
||||||
@@ -294,28 +284,16 @@ class L10n
|
|||||||
return $locale_list;
|
return $locale_list;
|
||||||
}
|
}
|
||||||
// is matching regex
|
// is matching regex
|
||||||
if (
|
$locale_detail = L10n::parseLocale($locale);
|
||||||
!preg_match(
|
// all null = nothing mached, return locale as is
|
||||||
// language code
|
if ($locale_detail === array_filter($locale_detail, 'is_null')) {
|
||||||
'/^(?P<lang>[a-z]{2,3})'
|
|
||||||
// country code
|
|
||||||
. '(?:_(?P<country>[A-Z]{2}))?'
|
|
||||||
// charset
|
|
||||||
. '(?:\\.(?P<charset>[-A-Za-z0-9_]+))?'
|
|
||||||
// @ modifier
|
|
||||||
. '(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/',
|
|
||||||
$locale,
|
|
||||||
$matches
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
// not matching, return as is
|
|
||||||
return [$locale];
|
return [$locale];
|
||||||
}
|
}
|
||||||
// do matching run
|
// write to innteral vars
|
||||||
$lang = $matches['lang'] ?? null;
|
$lang = $locale_detail['lang'];
|
||||||
$country = $matches['country'] ?? null;
|
$country = $locale_detail['country'];
|
||||||
$charset = $matches['charset'] ?? null;
|
$charset = $locale_detail['charset'];
|
||||||
$modifier = $matches['modifier'] ?? null;
|
$modifier = $locale_detail['modifier'];
|
||||||
// we need to add all possible cominations from not null set
|
// we need to add all possible cominations from not null set
|
||||||
// entries to the list, from longest to shortest
|
// entries to the list, from longest to shortest
|
||||||
// %s_%s.%s@%s (lang _ country . encoding @ suffix)
|
// %s_%s.%s@%s (lang _ country . encoding @ suffix)
|
||||||
@@ -623,7 +601,7 @@ class L10n
|
|||||||
* @param int $number number value
|
* @param int $number number value
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function __pn(string $context, string $single, string $plural, int $number): string
|
public function __np(string $context, string $single, string $plural, int $number): string
|
||||||
{
|
{
|
||||||
if ($this->l10n === null) {
|
if ($this->l10n === null) {
|
||||||
return $number > 1 ? $plural : $single;
|
return $number > 1 ? $plural : $single;
|
||||||
|
|||||||
@@ -1,8 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*********************************************************************
|
||||||
|
* Original: https://github.com/phpmyadmin/motranslator
|
||||||
|
* Has the same function names, but uses a different base system
|
||||||
|
* setlocale -> setLocale
|
||||||
|
* bindtextdomain -> setTextDomain
|
||||||
|
* textdomain -> setDomain
|
||||||
|
*********************************************************************/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use CoreLibs\Language\L10n;
|
use CoreLibs\Language\L10n as Loader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a requested locale.
|
* Sets a requested locale.
|
||||||
@@ -12,9 +20,9 @@ use CoreLibs\Language\L10n;
|
|||||||
*
|
*
|
||||||
* @return string Set or current locale
|
* @return string Set or current locale
|
||||||
*/
|
*/
|
||||||
function __setlocale(int $category, string $locale): string
|
function _setlocale(int $category, string $locale): string
|
||||||
{
|
{
|
||||||
return L10n::getInstance()->setLocale($locale);
|
return Loader::getInstance()->setLocale($locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,9 +31,9 @@ function __setlocale(int $category, string $locale): string
|
|||||||
* @param string $domain Domain name
|
* @param string $domain Domain name
|
||||||
* @param string $path Path where to find locales
|
* @param string $path Path where to find locales
|
||||||
*/
|
*/
|
||||||
function __bindtextdomain(string $domain, string $path): void
|
function _bindtextdomain(string $domain, string $path): void
|
||||||
{
|
{
|
||||||
L10n::getInstance()->setTextDomain($domain, $path);
|
Loader::getInstance()->setTextDomain($domain, $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,7 +47,7 @@ function __bindtextdomain(string $domain, string $path): void
|
|||||||
* @param string $domain Domain where to set character set
|
* @param string $domain Domain where to set character set
|
||||||
* @param string $codeset Character set to set
|
* @param string $codeset Character set to set
|
||||||
*/
|
*/
|
||||||
function __bind_textdomain_codeset(string $domain, string $codeset): void
|
function _bind_textdomain_codeset(string $domain, string $codeset): void
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,9 +56,9 @@ function __bind_textdomain_codeset(string $domain, string $codeset): void
|
|||||||
*
|
*
|
||||||
* @param string $domain Domain name
|
* @param string $domain Domain name
|
||||||
*/
|
*/
|
||||||
function __textdomain(string $domain): void
|
function _textdomain(string $domain): void
|
||||||
{
|
{
|
||||||
L10n::getInstance()->setDomain($domain);
|
Loader::getInstance()->setDomain($domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,9 +68,9 @@ function __textdomain(string $domain): void
|
|||||||
*
|
*
|
||||||
* @return string translated string (or original, if not found)
|
* @return string translated string (or original, if not found)
|
||||||
*/
|
*/
|
||||||
function __gettext(string $msgid): string
|
function _gettext(string $msgid): string
|
||||||
{
|
{
|
||||||
return L10n::getInstance()->getTranslator()->gettext(
|
return Loader::getInstance()->getTranslator()->gettext(
|
||||||
$msgid
|
$msgid
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -76,7 +84,7 @@ function __gettext(string $msgid): string
|
|||||||
*/
|
*/
|
||||||
function __(string $msgid): string
|
function __(string $msgid): string
|
||||||
{
|
{
|
||||||
return L10n::getInstance()->getTranslator()->gettext(
|
return Loader::getInstance()->getTranslator()->gettext(
|
||||||
$msgid
|
$msgid
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -90,9 +98,9 @@ function __(string $msgid): string
|
|||||||
*
|
*
|
||||||
* @return string translated plural form
|
* @return string translated plural form
|
||||||
*/
|
*/
|
||||||
function __ngettext(string $msgid, string $msgidPlural, int $number): string
|
function _ngettext(string $msgid, string $msgidPlural, int $number): string
|
||||||
{
|
{
|
||||||
return L10n::getInstance()->getTranslator()->ngettext(
|
return Loader::getInstance()->getTranslator()->ngettext(
|
||||||
$msgid,
|
$msgid,
|
||||||
$msgidPlural,
|
$msgidPlural,
|
||||||
$number
|
$number
|
||||||
@@ -107,9 +115,9 @@ function __ngettext(string $msgid, string $msgidPlural, int $number): string
|
|||||||
*
|
*
|
||||||
* @return string translated plural form
|
* @return string translated plural form
|
||||||
*/
|
*/
|
||||||
function __pgettext(string $msgctxt, string $msgid): string
|
function _pgettext(string $msgctxt, string $msgid): string
|
||||||
{
|
{
|
||||||
return L10n::getInstance()->getTranslator()->pgettext(
|
return Loader::getInstance()->getTranslator()->pgettext(
|
||||||
$msgctxt,
|
$msgctxt,
|
||||||
$msgid
|
$msgid
|
||||||
);
|
);
|
||||||
@@ -125,9 +133,9 @@ function __pgettext(string $msgctxt, string $msgid): string
|
|||||||
*
|
*
|
||||||
* @return string translated plural form
|
* @return string translated plural form
|
||||||
*/
|
*/
|
||||||
function __npgettext(string $msgctxt, string $msgid, string $msgidPlural, int $number): string
|
function _npgettext(string $msgctxt, string $msgid, string $msgidPlural, int $number): string
|
||||||
{
|
{
|
||||||
return L10n::getInstance()->getTranslator()->npgettext(
|
return Loader::getInstance()->getTranslator()->npgettext(
|
||||||
$msgctxt,
|
$msgctxt,
|
||||||
$msgid,
|
$msgid,
|
||||||
$msgidPlural,
|
$msgidPlural,
|
||||||
@@ -143,9 +151,9 @@ function __npgettext(string $msgctxt, string $msgid, string $msgidPlural, int $n
|
|||||||
*
|
*
|
||||||
* @return string translated string (or original, if not found)
|
* @return string translated string (or original, if not found)
|
||||||
*/
|
*/
|
||||||
function __dgettext(string $domain, string $msgid): string
|
function _dgettext(string $domain, string $msgid): string
|
||||||
{
|
{
|
||||||
return L10n::getInstance()->getTranslator('', '', $domain)->gettext(
|
return Loader::getInstance()->getTranslator('', '', $domain)->gettext(
|
||||||
$msgid
|
$msgid
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -160,9 +168,9 @@ function __dgettext(string $domain, string $msgid): string
|
|||||||
*
|
*
|
||||||
* @return string translated plural form
|
* @return string translated plural form
|
||||||
*/
|
*/
|
||||||
function __dngettext(string $domain, string $msgid, string $msgidPlural, int $number): string
|
function _dngettext(string $domain, string $msgid, string $msgidPlural, int $number): string
|
||||||
{
|
{
|
||||||
return L10n::getInstance()->getTranslator('', '', $domain)->ngettext(
|
return Loader::getInstance()->getTranslator('', '', $domain)->ngettext(
|
||||||
$msgid,
|
$msgid,
|
||||||
$msgidPlural,
|
$msgidPlural,
|
||||||
$number
|
$number
|
||||||
@@ -178,9 +186,9 @@ function __dngettext(string $domain, string $msgid, string $msgidPlural, int $nu
|
|||||||
*
|
*
|
||||||
* @return string translated plural form
|
* @return string translated plural form
|
||||||
*/
|
*/
|
||||||
function __dpgettext(string $domain, string $msgctxt, string $msgid): string
|
function _dpgettext(string $domain, string $msgctxt, string $msgid): string
|
||||||
{
|
{
|
||||||
return L10n::getInstance()->getTranslator('', '', $domain)->pgettext(
|
return Loader::getInstance()->getTranslator('', '', $domain)->pgettext(
|
||||||
$msgctxt,
|
$msgctxt,
|
||||||
$msgid
|
$msgid
|
||||||
);
|
);
|
||||||
@@ -197,9 +205,9 @@ function __dpgettext(string $domain, string $msgctxt, string $msgid): string
|
|||||||
*
|
*
|
||||||
* @return string translated plural form
|
* @return string translated plural form
|
||||||
*/
|
*/
|
||||||
function __dnpgettext(string $domain, string $msgctxt, string $msgid, string $msgidPlural, int $number): string
|
function _dnpgettext(string $domain, string $msgctxt, string $msgid, string $msgidPlural, int $number): string
|
||||||
{
|
{
|
||||||
return L10n::getInstance()->getTranslator('', '', $domain)->npgettext(
|
return Loader::getInstance()->getTranslator('', '', $domain)->npgettext(
|
||||||
$msgctxt,
|
$msgctxt,
|
||||||
$msgid,
|
$msgid,
|
||||||
$msgidPlural,
|
$msgidPlural,
|
||||||
|
|||||||
@@ -299,23 +299,39 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* construct form generator
|
* construct form generator
|
||||||
* @param array<mixed> $db_config db config array
|
* @param array<mixed> $db_config db config array, mandatory
|
||||||
* @param \CoreLibs\Debug\Logging|null $log Logging class
|
* @param \CoreLibs\Debug\Logging|null $log Logging class, null auto set
|
||||||
* @param \CoreLibs\Language\L10n|null $l10n l10n language class
|
* @param \CoreLibs\Language\L10n|null $l10n l10n language class, null auto set
|
||||||
* if null, auto set
|
* @param array<string,string>|null $locale locale array from ::setLocale,
|
||||||
|
* null auto set
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
array $db_config,
|
array $db_config,
|
||||||
\CoreLibs\Debug\Logging $log = null,
|
?\CoreLibs\Debug\Logging $log = null,
|
||||||
?\CoreLibs\Language\L10n $l10n = null
|
?\CoreLibs\Language\L10n $l10n = null,
|
||||||
|
?array $locale = null
|
||||||
) {
|
) {
|
||||||
global $table_arrays;
|
global $table_arrays;
|
||||||
// replace any non valid variable names
|
// replace any non valid variable names
|
||||||
// TODO extract only alphanumeric and _ after . to _ replacement
|
// TODO extract only alphanumeric and _ after . to _ replacement
|
||||||
$this->my_page_name = str_replace(['.'], '_', System::getPageName(System::NO_EXTENSION));
|
$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
|
// 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
|
// load config array
|
||||||
// get table array definitions for current page name
|
// get table array definitions for current page name
|
||||||
|
|
||||||
@@ -443,29 +459,6 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
|||||||
parent::__destruct();
|
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 |=================================================>
|
// PUBLIC METHODS |=================================================>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -154,50 +154,41 @@ class SmartyExtend extends \Smarty
|
|||||||
* constructor class, just sets the language stuff
|
* constructor class, just sets the language stuff
|
||||||
* calls L10 for pass on internaly in smarty
|
* calls L10 for pass on internaly in smarty
|
||||||
* also registers the getvar caller plugin
|
* also registers the getvar caller plugin
|
||||||
* @param \CoreLibs\Language\L10n|null $l10n l10n language class
|
* @param \CoreLibs\Language\L10n $l10n l10n language class
|
||||||
* if null, auto set
|
* @param array<string,string> $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
|
// call basic smarty
|
||||||
// or Smarty::__construct();
|
// or Smarty::__construct();
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
// set lang vars
|
|
||||||
$this->setLangEncoding();
|
|
||||||
// iinit lang
|
// iinit lang
|
||||||
$this->l10n = $l10n ?? new \CoreLibs\Language\L10n($this->lang);
|
$this->l10n = $l10n;
|
||||||
// Smarty 3.x
|
// parse and read, legacy stuff
|
||||||
// $this->registerPlugin('modifier', 'getvar', [&$this, 'get_template_vars']);
|
$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();
|
||||||
|
|
||||||
|
// opt load functions so we can use legacy init for smarty run perhaps
|
||||||
|
\CoreLibs\Language\L10n::loadFunctions();
|
||||||
|
_setlocale(LC_MESSAGES, $locale['locale']);
|
||||||
|
_textdomain($this->domain);
|
||||||
|
_bindtextdomain($this->domain, $this->lang_dir);
|
||||||
|
_bind_textdomain_codeset($this->domain, $this->encoding);
|
||||||
|
|
||||||
|
// register smarty variable
|
||||||
$this->registerPlugin('modifier', 'getvar', [&$this, 'getTemplateVars']);
|
$this->registerPlugin('modifier', 'getvar', [&$this, 'getTemplateVars']);
|
||||||
|
|
||||||
$this->page_name = pathinfo($_SERVER["PHP_SELF"])['basename'];
|
$this->page_name = \CoreLibs\Get\System::getPageName();
|
||||||
|
|
||||||
// set internal settings
|
// set internal settings
|
||||||
$this->CACHE_ID = defined('CACHE_ID') ? CACHE_ID : '';
|
$this->CACHE_ID = defined('CACHE_ID') ? CACHE_ID : '';
|
||||||
$this->COMPILE_ID = defined('COMPILE_ID') ? COMPILE_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
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -3,30 +3,19 @@
|
|||||||
/**
|
/**
|
||||||
* smarty-gettext.php - Gettext support for smarty
|
* smarty-gettext.php - Gettext support for smarty
|
||||||
*
|
*
|
||||||
* ------------------------------------------------------------------------- *
|
|
||||||
* This library is free software; you can redistribute it and/or *
|
|
||||||
* modify it under the terms of the GNU Lesser General Public *
|
|
||||||
* License as published by the Free Software Foundation; either *
|
|
||||||
* version 2.1 of the License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This library is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
|
||||||
* Lesser General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU Lesser General Public *
|
|
||||||
* License along with this library; if not, write to the Free Software *
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
|
||||||
* ------------------------------------------------------------------------- *
|
|
||||||
*
|
|
||||||
* To register as a smarty block function named 't', use:
|
* To register as a smarty block function named 't', use:
|
||||||
* $smarty->register_block('t', 'smarty_translate');
|
* $smarty->register_block('t', 'smarty_translate');
|
||||||
*
|
*
|
||||||
|
* NOTE: native php support for conext sensitive does not exist
|
||||||
|
* Those jumps are disabled
|
||||||
|
*
|
||||||
* @package smarty-gettext
|
* @package smarty-gettext
|
||||||
* @version $Id: block.t.php 4738 2022-05-06 01:28:48Z clemens $
|
* @version $Id: block.t.php 4738 2022-05-06 01:28:48Z clemens $
|
||||||
* @link http://smarty-gettext.sf.net/
|
* @link http://smarty-gettext.sf.net/
|
||||||
* @author Sagi Bashari <sagi@boom.org.il>
|
* @author Sagi Bashari <sagi@boom.org.il>
|
||||||
* @copyright 2004 Sagi Bashari
|
* @copyright 2004 Sagi Bashari
|
||||||
|
* @copyright Elan Ruusamäe
|
||||||
|
* @copyright Clemens Schwaighofer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,7 +28,7 @@
|
|||||||
*/
|
*/
|
||||||
function smarty_gettext_strarg($str/*, $varargs... */)
|
function smarty_gettext_strarg($str/*, $varargs... */)
|
||||||
{
|
{
|
||||||
$tr = array();
|
$tr = [];
|
||||||
$p = 0;
|
$p = 0;
|
||||||
|
|
||||||
$nargs = func_num_args();
|
$nargs = func_num_args();
|
||||||
@@ -68,14 +57,18 @@ function smarty_gettext_strarg($str/*, $varargs... */)
|
|||||||
* - escape - sets escape mode:
|
* - escape - sets escape mode:
|
||||||
* - 'html' for HTML escaping, this is the default.
|
* - 'html' for HTML escaping, this is the default.
|
||||||
* - 'js' for javascript escaping.
|
* - 'js' for javascript escaping.
|
||||||
|
* - 'url' for url escaping.
|
||||||
* - 'no'/'off'/0 - turns off escaping
|
* - 'no'/'off'/0 - turns off escaping
|
||||||
* - plural - The plural version of the text (2nd parameter of ngettext())
|
* - plural - The plural version of the text (2nd parameter of ngettext())
|
||||||
* - count - The item count for plural mode (3rd parameter of ngettext())
|
* - count - The item count for plural mode (3rd parameter of ngettext())
|
||||||
|
* - domain - Textdomain to be used, default if skipped (dgettext() instead of gettext())
|
||||||
|
* - context - gettext context. reserved for future use.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// cs modified: __ calls instead of direct gettext calls
|
// cs modified: __ calls instead of direct gettext calls
|
||||||
|
|
||||||
function smarty_block_t($params, $text, $template, &$repeat)
|
function smarty_block_t($params, $text)
|
||||||
{
|
{
|
||||||
if (!isset($text)) {
|
if (!isset($text)) {
|
||||||
return $text;
|
return $text;
|
||||||
@@ -101,11 +94,75 @@ function smarty_block_t($params, $text, $template, &$repeat)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get domain param
|
||||||
|
if (isset($params['domain'])) {
|
||||||
|
$domain = $params['domain'];
|
||||||
|
unset($params['domain']);
|
||||||
|
} else {
|
||||||
|
$domain = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get context param
|
||||||
|
if (isset($params['context'])) {
|
||||||
|
$context = $params['context'];
|
||||||
|
unset($params['context']);
|
||||||
|
} else {
|
||||||
|
$context = null;
|
||||||
|
}
|
||||||
|
|
||||||
// use plural if required parameters are set
|
// use plural if required parameters are set
|
||||||
if (isset($count) && isset($plural)) {
|
if (isset($count) && isset($plural)) {
|
||||||
$text = $template->l10n->__ngettext($text, $plural, $count);
|
if (isset($domain) && isset($context)) {
|
||||||
|
if (is_callable('_dnpgettext')) {
|
||||||
|
$text = _dnpgettext($domain, $context, $text, $plural, $count);
|
||||||
|
}/* elseif (is_callable('dnpgettext')) {
|
||||||
|
$text = dnpgettext($domain, $context, $text, $plural, $count);
|
||||||
|
} */
|
||||||
|
} elseif (isset($domain)) {
|
||||||
|
if (is_callable('_dngettext')) {
|
||||||
|
$text = _dngettext($domain, $text, $plural, $count);
|
||||||
|
} elseif (is_callable('dngettext')) {
|
||||||
|
$text = dngettext($domain, $text, $plural, $count);
|
||||||
|
}
|
||||||
|
} elseif (isset($context)) {
|
||||||
|
if (is_callable('_npgettext')) {
|
||||||
|
$text = _npgettext($context, $text, $plural, $count);
|
||||||
|
}/* elseif (is_callable('npgettext')) {
|
||||||
|
$text = npgettext($context, $text, $plural, $count);
|
||||||
|
} */
|
||||||
|
} else {
|
||||||
|
if (is_callable('_ngettext')) {
|
||||||
|
$text = _ngettext($text, $plural, $count);
|
||||||
|
} elseif (is_callable('ngettext')) {
|
||||||
|
$text = ngettext($text, $plural, $count);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else { // use normal
|
} else { // use normal
|
||||||
$text = $template->l10n->__($text);
|
if (isset($domain) && isset($context)) {
|
||||||
|
if (is_callable('_dpgettext')) {
|
||||||
|
$text = _dpgettext($domain, $context, $text);
|
||||||
|
}/* elseif (is_callable('dpgettext')) {
|
||||||
|
$text = dpgettext($domain, $context, $text);
|
||||||
|
} */
|
||||||
|
} elseif (isset($domain)) {
|
||||||
|
if (is_callable('_dgettext')) {
|
||||||
|
$text = _dgettext($domain, $text);
|
||||||
|
} elseif (is_callable('dpgettext')) {
|
||||||
|
$text = dgettext($domain, $text);
|
||||||
|
}
|
||||||
|
} elseif (isset($context)) {
|
||||||
|
if (is_callable('_pgettext')) {
|
||||||
|
$text = _pgettext($context, $text);
|
||||||
|
}/* elseif (is_callable('pgettext')) {
|
||||||
|
$text = pgettext($context, $text);
|
||||||
|
} */
|
||||||
|
} else {
|
||||||
|
if (is_callable('_gettext')) {
|
||||||
|
$text = _gettext($text);
|
||||||
|
} elseif (is_callable('gettext')) {
|
||||||
|
$text = gettext($text);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// run strarg if there are parameters
|
// run strarg if there are parameters
|
||||||
@@ -115,6 +172,7 @@ function smarty_block_t($params, $text, $template, &$repeat)
|
|||||||
|
|
||||||
switch ($escape) {
|
switch ($escape) {
|
||||||
case 'html':
|
case 'html':
|
||||||
|
// default
|
||||||
$text = nl2br(htmlspecialchars($text));
|
$text = nl2br(htmlspecialchars($text));
|
||||||
break;
|
break;
|
||||||
case 'javascript':
|
case 'javascript':
|
||||||
@@ -122,13 +180,29 @@ function smarty_block_t($params, $text, $template, &$repeat)
|
|||||||
// javascript escape
|
// javascript escape
|
||||||
$text = strtr(
|
$text = strtr(
|
||||||
$text,
|
$text,
|
||||||
array('\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n', '</' => '<\/')
|
[
|
||||||
|
'\\' => '\\\\',
|
||||||
|
"'" => "\\'",
|
||||||
|
'"' => '\\"',
|
||||||
|
"\r" => '\\r',
|
||||||
|
"\n" => '\\n',
|
||||||
|
'</' => '<\/'
|
||||||
|
]
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case 'url':
|
case 'url':
|
||||||
// url escape
|
// url escape
|
||||||
$text = urlencode($text);
|
$text = urlencode($text);
|
||||||
break;
|
break;
|
||||||
|
// below is a list for explicit OFF
|
||||||
|
case 'no':
|
||||||
|
case 'off':
|
||||||
|
case 'false':
|
||||||
|
case '0':
|
||||||
|
case 0:
|
||||||
|
// explicit OFF
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
|
|||||||
2
www/vendor/composer/autoload_classmap.php
vendored
2
www/vendor/composer/autoload_classmap.php
vendored
@@ -47,7 +47,7 @@ return array(
|
|||||||
'CoreLibs\\Language\\Core\\StreamReader' => $baseDir . '/lib/CoreLibs/Language/Core/StreamReader.php',
|
'CoreLibs\\Language\\Core\\StreamReader' => $baseDir . '/lib/CoreLibs/Language/Core/StreamReader.php',
|
||||||
'CoreLibs\\Language\\Core\\StringReader' => $baseDir . '/lib/CoreLibs/Language/Core/StringReader.php',
|
'CoreLibs\\Language\\Core\\StringReader' => $baseDir . '/lib/CoreLibs/Language/Core/StringReader.php',
|
||||||
'CoreLibs\\Language\\Encoding' => $baseDir . '/lib/CoreLibs/Language/Encoding.php',
|
'CoreLibs\\Language\\Encoding' => $baseDir . '/lib/CoreLibs/Language/Encoding.php',
|
||||||
'CoreLibs\\Language\\GetSettings' => $baseDir . '/lib/CoreLibs/Language/GetSettings.php',
|
'CoreLibs\\Language\\GetLocale' => $baseDir . '/lib/CoreLibs/Language/GetLocale.php',
|
||||||
'CoreLibs\\Language\\L10n' => $baseDir . '/lib/CoreLibs/Language/L10n.php',
|
'CoreLibs\\Language\\L10n' => $baseDir . '/lib/CoreLibs/Language/L10n.php',
|
||||||
'CoreLibs\\Output\\Form\\Elements' => $baseDir . '/lib/CoreLibs/Output/Form/Elements.php',
|
'CoreLibs\\Output\\Form\\Elements' => $baseDir . '/lib/CoreLibs/Output/Form/Elements.php',
|
||||||
'CoreLibs\\Output\\Form\\Generate' => $baseDir . '/lib/CoreLibs/Output/Form/Generate.php',
|
'CoreLibs\\Output\\Form\\Generate' => $baseDir . '/lib/CoreLibs/Output/Form/Generate.php',
|
||||||
|
|||||||
2
www/vendor/composer/autoload_static.php
vendored
2
www/vendor/composer/autoload_static.php
vendored
@@ -112,7 +112,7 @@ class ComposerStaticInit10fe8fe2ec4017b8644d2b64bcf398b9
|
|||||||
'CoreLibs\\Language\\Core\\StreamReader' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/Core/StreamReader.php',
|
'CoreLibs\\Language\\Core\\StreamReader' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/Core/StreamReader.php',
|
||||||
'CoreLibs\\Language\\Core\\StringReader' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/Core/StringReader.php',
|
'CoreLibs\\Language\\Core\\StringReader' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/Core/StringReader.php',
|
||||||
'CoreLibs\\Language\\Encoding' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/Encoding.php',
|
'CoreLibs\\Language\\Encoding' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/Encoding.php',
|
||||||
'CoreLibs\\Language\\GetSettings' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/GetSettings.php',
|
'CoreLibs\\Language\\GetLocale' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/GetLocale.php',
|
||||||
'CoreLibs\\Language\\L10n' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/L10n.php',
|
'CoreLibs\\Language\\L10n' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/L10n.php',
|
||||||
'CoreLibs\\Output\\Form\\Elements' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/Form/Elements.php',
|
'CoreLibs\\Output\\Form\\Elements' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/Form/Elements.php',
|
||||||
'CoreLibs\\Output\\Form\\Generate' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/Form/Generate.php',
|
'CoreLibs\\Output\\Form\\Generate' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/Form/Generate.php',
|
||||||
|
|||||||
Reference in New Issue
Block a user