Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c181a83b48 | ||
|
|
c830a32962 | ||
|
|
82bc99b181 | ||
|
|
556cabca38 | ||
|
|
6f4c5e36e6 | ||
|
|
a3c49e408a | ||
|
|
cc77d7e031 | ||
|
|
d553c1364f | ||
|
|
3f374a2cd7 | ||
|
|
9e99275db5 | ||
|
|
330e2baf39 |
@@ -68,9 +68,10 @@ INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('Visitor', 'B0C4B3
|
||||
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('User', '1E789E', 1);
|
||||
|
||||
-- edit language
|
||||
-- iso_name = encoding
|
||||
DELETE FROM edit_language;
|
||||
INSERT INTO edit_language (short_name, long_name, iso_name, order_number, enabled, lang_default) VALUES ('en', 'English', 'UTF-8', 1, 1, 1);
|
||||
INSERT INTO edit_language (short_name, long_name, iso_name, order_number, enabled, lang_default) VALUES ('ja', 'Japanese', 'UTF-8', 2, 1, 0);
|
||||
INSERT INTO edit_language (long_name, short_name, iso_name, order_number, enabled, lang_default) VALUES ('English', 'en_US', 'UTF-8', 1, 1, 1);
|
||||
INSERT INTO edit_language (long_name, short_name, long_name, iso_name, order_number, enabled, lang_default) VALUES ('Japanese', 'ja_JP', 'UTF-8', 2, 1, 0);
|
||||
|
||||
-- edit group
|
||||
DELETE FROM edit_group;
|
||||
|
||||
@@ -12,7 +12,7 @@ CREATE TABLE edit_language (
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
lang_default SMALLINT NOT NULL DEFAULT 0,
|
||||
long_name VARCHAR,
|
||||
short_name VARCHAR,
|
||||
iso_name VARCHAR,
|
||||
short_name VARCHAR, -- en_US, en or en_US@latin without encoding
|
||||
iso_name VARCHAR, -- should actually be encoding
|
||||
order_number INT
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
55
4dev/locale/Readme.md
Normal file
55
4dev/locale/Readme.md
Normal file
@@ -0,0 +1,55 @@
|
||||
# Translation files
|
||||
|
||||
## Source file name convetion
|
||||
|
||||
Locale Name . Domain . Encoding .po
|
||||
|
||||
## Name parte explenations
|
||||
|
||||
### Locale Name Examples
|
||||
|
||||
If underscore in name the long version is checked first, then the short version:
|
||||
en_US@latin -> en_US -> en
|
||||
|
||||
* en
|
||||
* en_US
|
||||
* en_US.UTF-8
|
||||
* en_US@latin
|
||||
|
||||
### Domain
|
||||
|
||||
For current case auto set CONTENT_PATH is used
|
||||
|
||||
* admin
|
||||
* frontend
|
||||
|
||||
### Encoding
|
||||
|
||||
if not set UTF-8 is assumed. Any other utf8 encoding is changed to UTF-8
|
||||
|
||||
* UTF-8
|
||||
* SJIS
|
||||
* EUC
|
||||
|
||||
## File name example source
|
||||
|
||||
`ja-admin.po`
|
||||
|
||||
First part is LOCALE, second part is domain. Separator is `-`
|
||||
|
||||
## Folder layout
|
||||
|
||||
`includes/locale/ja/LC_MESSAGES/frontend.mo`
|
||||
|
||||
ALTERNATE LOCALE NAMES:
|
||||
* ja
|
||||
* ja_JP
|
||||
* ja.UTF-8
|
||||
* ja_JP.UTF-8
|
||||
|
||||
ja_JP.UTF-8: Locale Name
|
||||
frontend: dmain (CONTENT_PATH)
|
||||
|
||||
## command
|
||||
|
||||
`msgfmt -o www/includes/locale/ja/LC_MESSAGES/frontend.mo 4dev/lang/ja.admin.po`
|
||||
@@ -3,21 +3,22 @@
|
||||
# CREATED: 2005/08/09
|
||||
# SHORT DESCRIPTION:
|
||||
# Backned English Messages file for gettext
|
||||
# to craete: msgfmt -o ja.mo messages_en.po
|
||||
# HISTORY:
|
||||
# to craete: msgfmt -o <output.po> <input.mo>
|
||||
# ********************************************************************/
|
||||
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Project Version\n"
|
||||
"Project-Id-Version: en_US.UTF-8 LC_MESSAGES admin\n"
|
||||
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
|
||||
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: \n"
|
||||
"Last-Translator: clemens.schwaighofer@egplusww.co\n"
|
||||
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
|
||||
"Language: en_US\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 "Year"
|
||||
msgstr "Year"
|
||||
@@ -26,7 +27,25 @@ msgid "Month"
|
||||
msgstr "Month"
|
||||
|
||||
msgid "INPUT TEST"
|
||||
msgstr "OUTPUT TEST EN"
|
||||
msgstr "OUTPUT TEST ADMIN EN"
|
||||
|
||||
# testing multi
|
||||
msgid "single"
|
||||
msgid_plural "multi"
|
||||
msgstr[0] "Multi Admin en_US 0"
|
||||
msgstr[1] "Multi Admin en_US 1"
|
||||
msgstr[2] "Multi Admin en_US 2"
|
||||
|
||||
msgctxt "month name"
|
||||
msgid "May"
|
||||
msgstr "May Admin en_US"
|
||||
|
||||
msgctxt "month name"
|
||||
msgid "single"
|
||||
msgid_plural "multi"
|
||||
msgstr[0] "Multi Admin month en_US 0"
|
||||
msgstr[1] "Multi Admin month en_US 1"
|
||||
msgstr[2] "Multi Admin month en_US 2"
|
||||
|
||||
msgid "I should be translated"
|
||||
msgstr "I should be translated: I WAS TRANSLATED"
|
||||
24
4dev/locale/en_US-frontend.po
Normal file
24
4dev/locale/en_US-frontend.po
Normal file
@@ -0,0 +1,24 @@
|
||||
# to craete: msgfmt -o <output.po> <input.mo>
|
||||
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: en_US.UTF-8 LC_MESSAGES frontend\n"
|
||||
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
|
||||
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: clemens.schwaighofer@egplusww.co\n"
|
||||
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
|
||||
"Language: en_US\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 EN"
|
||||
|
||||
msgid "single"
|
||||
msgid_plural "multi"
|
||||
msgstr[0] "Multi frontend en_US 0"
|
||||
msgstr[1] "Multi frontend en_US 1"
|
||||
msgstr[2] "Multi frontend en_US 2"
|
||||
@@ -3,21 +3,22 @@
|
||||
# CREATED: 2018/03/28
|
||||
# SHORT DESCRIPTION:
|
||||
# Backend Japanese Messages file for gettext
|
||||
# to craete: msgfmt -o ja.mo messages_ja.po
|
||||
# HISTORY:
|
||||
# to craete: msgfmt -o <output.po> <input.mo>
|
||||
# ********************************************************************/
|
||||
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Project Version\n"
|
||||
"Project-Id-Version: ja_JP.UTF-8 LC_MESSAGES admin\n"
|
||||
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
|
||||
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: \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=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
|
||||
|
||||
msgid "Yes"
|
||||
msgstr "はい"
|
||||
@@ -63,7 +64,14 @@ msgid "Sun"
|
||||
msgstr "日"
|
||||
|
||||
msgid "INPUT TEST"
|
||||
msgstr "OUTPUT TEST JA"
|
||||
msgstr "OUTPUT TEST ADMIN JA"
|
||||
|
||||
# testing multi
|
||||
msgid "single"
|
||||
msgid_plural "multi"
|
||||
msgstr[0] "Multi Admin ja_JP 0"
|
||||
msgstr[1] "Multi Admin ja_JP 1"
|
||||
msgstr[2] "Multi Admin ja_JP 2"
|
||||
|
||||
# login string
|
||||
msgid "Hello %s"
|
||||
8
4dev/locale/ja-frontend.po
Normal file
8
4dev/locale/ja-frontend.po
Normal file
@@ -0,0 +1,8 @@
|
||||
# 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"
|
||||
117
4dev/tests/CoreLibsCheckEncodingTest.php
Normal file
117
4dev/tests/CoreLibsCheckEncodingTest.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Check\Encoding
|
||||
* @coversDefaultClass \CoreLibs\Check\Encoding
|
||||
* @testdox \CoreLibs\Check\Encoding method tests
|
||||
*/
|
||||
final class CoreLibsCheckEncodingTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function checkConvertEncodingProvider(): array
|
||||
{
|
||||
return [
|
||||
// 0: string to test
|
||||
// 1: source encoding
|
||||
// 2: target encoding
|
||||
// 3: substitue character
|
||||
// 4: false for ok, array with error list
|
||||
'valid test UTF-8 to SJIS (default)' => [
|
||||
'日本語',
|
||||
'UTF-8',
|
||||
'SJIS',
|
||||
null,
|
||||
false
|
||||
],
|
||||
'invalid test UTF-8 to SJIS (dots as code point)' => [
|
||||
'❶',
|
||||
'UTF-8',
|
||||
'SJIS',
|
||||
0x2234,
|
||||
['❶']
|
||||
],
|
||||
'invalid test UTF-8 to SJIS (dots as string)' => [
|
||||
'❶',
|
||||
'UTF-8',
|
||||
'SJIS',
|
||||
'∴',
|
||||
['❶']
|
||||
],
|
||||
'invalid test UTF-8 to SJIS (none)' => [
|
||||
'❶',
|
||||
'UTF-8',
|
||||
'SJIS',
|
||||
'none',
|
||||
['❶']
|
||||
],
|
||||
'invalid test UTF-8 to SJIS (long)' => [
|
||||
'❶',
|
||||
'UTF-8',
|
||||
'SJIS',
|
||||
'long',
|
||||
['❶']
|
||||
],
|
||||
'invalid test UTF-8 to SJIS (entity)' => [
|
||||
'❶',
|
||||
'UTF-8',
|
||||
'SJIS',
|
||||
'entity',
|
||||
['❶']
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::checkConvertEncoding
|
||||
* @dataProvider checkConvertEncodingProvider
|
||||
* @testdox check encoding convert from $from_encoding to $to_encoding [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $from_encoding
|
||||
* @param string $to_encoding
|
||||
* @param string|int|null $error_char
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckConvertEncoding(
|
||||
string $input,
|
||||
string $from_encoding,
|
||||
string $to_encoding,
|
||||
$error_char,
|
||||
$expected
|
||||
): void {
|
||||
if ($error_char !== null) {
|
||||
\CoreLibs\Check\Encoding::setErrorChar($error_char);
|
||||
if (!in_array($error_char, ['none', 'long', 'entity'])) {
|
||||
$this->assertEquals(
|
||||
\IntlChar::chr($error_char),
|
||||
\CoreLibs\Check\Encoding::getErrorChar()
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$error_char,
|
||||
\CoreLibs\Check\Encoding::getErrorChar()
|
||||
);
|
||||
}
|
||||
}
|
||||
$return = \CoreLibs\Check\Encoding::checkConvertEncoding($input, $from_encoding, $to_encoding);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$return
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
102
4dev/tests/CoreLibsConvertEncodingTest.php
Normal file
102
4dev/tests/CoreLibsConvertEncodingTest.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Convert\Encoding
|
||||
* @coversDefaultClass \CoreLibs\Convert\Encoding
|
||||
* @testdox \CoreLibs\Convert\Encoding method tests
|
||||
*/
|
||||
final class CoreLibsConvertEncodingTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function convertEncodingProvider(): array
|
||||
{
|
||||
return [
|
||||
// 0: original string
|
||||
// 1: target encoding
|
||||
// 2: optional source encoding
|
||||
// 3: auto check (not used)
|
||||
// 4: expected string
|
||||
// 5: expected string encoding
|
||||
'simple from UTF-8 to SJIS' => [
|
||||
'input string',
|
||||
'SJIS',
|
||||
null,
|
||||
null,
|
||||
'input string',
|
||||
'SJIS'
|
||||
],
|
||||
'kanji from UTF-8 to SJIS' => [
|
||||
'日本語',
|
||||
'SJIS',
|
||||
null,
|
||||
null,
|
||||
'日本語',
|
||||
'SJIS'
|
||||
],
|
||||
'kanji from UTF-8 to SJIS with source' => [
|
||||
'日本語',
|
||||
'SJIS',
|
||||
'UTF-8',
|
||||
null,
|
||||
'日本語',
|
||||
'SJIS'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::convertEncoding
|
||||
* @dataProvider convertEncodingProvider
|
||||
* @testdox convert encoding $target_encoding, source: $source_encoding, auto: $auto_check [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $target_encoding
|
||||
* @param string $source_encoding
|
||||
* @param bool $auto_check
|
||||
* @param string $expected
|
||||
* @param string $expected_encoding
|
||||
* @return void
|
||||
*/
|
||||
public function testConvertEncoding(
|
||||
string $input,
|
||||
string $target_encoding,
|
||||
?string $source_encoding,
|
||||
?bool $auto_check,
|
||||
string $expected,
|
||||
string $expected_encoding
|
||||
): void {
|
||||
if ($source_encoding === null and $auto_check === null) {
|
||||
$string = \CoreLibs\Convert\Encoding::convertEncoding($input, $target_encoding);
|
||||
} elseif ($auto_check === null) {
|
||||
$string = \CoreLibs\Convert\Encoding::convertEncoding($input, $target_encoding, $source_encoding);
|
||||
} else {
|
||||
$string = \CoreLibs\Convert\Encoding::convertEncoding(
|
||||
$input,
|
||||
$target_encoding,
|
||||
$source_encoding,
|
||||
$auto_check
|
||||
);
|
||||
}
|
||||
// because we can't store encoding in here anyway
|
||||
$target = mb_convert_encoding($expected, $expected_encoding, 'UTF-8');
|
||||
// print "IN: $input, $target_encoding\n";
|
||||
$this->assertEquals(
|
||||
$target,
|
||||
$string
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
101
4dev/tests/CoreLibsConvertMimeEncodeTest.php
Normal file
101
4dev/tests/CoreLibsConvertMimeEncodeTest.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Convert\MimeEncode
|
||||
* @coversDefaultClass \CoreLibs\Convert\MimeEncode
|
||||
* @testdox \CoreLibs\Convert\MimeEncode method tests
|
||||
*/
|
||||
final class CoreLibsConvertMimeEncodeTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function mbMimeEncodeProvider(): array
|
||||
{
|
||||
return [
|
||||
// 0: input string
|
||||
// 1: encoding
|
||||
// 2: expected
|
||||
'standard UTF-8' => [
|
||||
'Test string',
|
||||
'UTF-8',
|
||||
'Test string'
|
||||
],
|
||||
'long text UTF-8' => [
|
||||
'The quick brown fox jumps over the lazy sheep that sleeps in the ravine '
|
||||
. 'and has no idea what is going on here',
|
||||
'UTF-8',
|
||||
'The quick brown fox jumps over the lazy sheep that sleeps in the ravine '
|
||||
. 'and has no idea what is going on here'
|
||||
],
|
||||
'standard with special chars UTF-8' => [
|
||||
'This is ümläßtと漢字もカタカナ!!^$%&',
|
||||
'UTF-8',
|
||||
'This is =?UTF-8?B?w7xtbMOkw59044Go5ryi5a2X44KC44Kr44K/44Kr44OK77yBIV4k?='
|
||||
. "\r\n"
|
||||
. ' =?UTF-8?B?JQ==?=&'
|
||||
],
|
||||
'35 chars and space at the end UTF-8' => [
|
||||
'12345678901234567890123456789012345 '
|
||||
. 'is there a space?',
|
||||
'UTF-8',
|
||||
'12345678901234567890123456789012345 '
|
||||
. 'is there a =?UTF-8?B?c3BhY2U/?='
|
||||
],
|
||||
'36 chars and space at the end UTF-8' => [
|
||||
'123456789012345678901234567890123456 '
|
||||
. 'is there a space?',
|
||||
'UTF-8',
|
||||
'123456789012345678901234567890123456 '
|
||||
. 'is there a =?UTF-8?B?c3BhY2U/?='
|
||||
],
|
||||
'36 kanji and space UTF-8' => [
|
||||
'カタカナカタカナかなカタカナカタカナかなカタカナカタカナかなカタカナカタ '
|
||||
. 'is there a space?',
|
||||
'UTF-8',
|
||||
"=?UTF-8?B?44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq44Kr44K/44Kr44OK44Kr?=\r\n"
|
||||
. " =?UTF-8?B?44K/44Kr44OK?=\r\n"
|
||||
. " =?UTF-8?B?44GL44Gq44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq44Kr44K/44Kr?=\r\n"
|
||||
. " =?UTF-8?B?44OK44Kr44K/?= is there a =?UTF-8?B?c3BhY2U/?="
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* mb mime header encoding test
|
||||
*
|
||||
* @covers ::__mbMimeEncode
|
||||
* @dataProvider mbMimeEncodeProvider
|
||||
* @testdox mb encoding target $encoding [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUuMbMimeEncode(string $input, string $encoding, string $expected): void
|
||||
{
|
||||
// encode string first
|
||||
$encoded = \CoreLibs\Convert\MimeEncode::__mbMimeEncode($input, $encoding);
|
||||
// print "MIME: -" . $encoded . "-\n";
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$encoded
|
||||
);
|
||||
$decoded = mb_decode_mimeheader($encoded);
|
||||
// print "INPUT : " . $input . "\n";
|
||||
// print "DECODED: " . $decoded . "\n";
|
||||
// back compare decoded
|
||||
$this->assertEquals(
|
||||
$input,
|
||||
$decoded
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -347,6 +347,7 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
|
||||
/**
|
||||
* Returns test list for dbCompareVersion check
|
||||
* NOTE: unless we fully mock the =version check needs to be updated
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -357,16 +358,16 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
return [
|
||||
'compare = ok' => [ '=13.6.0', true ],
|
||||
'compare = bad' => [ '=9.2.0', false ],
|
||||
'compare < ok' => [ '<20.0.0', true ],
|
||||
'compare < ok' => [ '<99.0.0', true ],
|
||||
'compare < bad' => [ '<9.2.0', false ],
|
||||
'compare <= ok a' => [ '<=20.0.0', true ],
|
||||
'compare <= ok a' => [ '<=99.0.0', true ],
|
||||
'compare <= ok b' => [ '<=13.6.0', true ],
|
||||
'compare <= false' => [ '<=9.2.0', false ],
|
||||
'compare > ok' => [ '>9.2.0', true ],
|
||||
'compare > bad' => [ '>20.2.0', false ],
|
||||
'compare > bad' => [ '>99.2.0', false ],
|
||||
'compare >= ok a' => [ '>=13.6.0', true ],
|
||||
'compare >= ok b' => [ '>=9.2.0', true ],
|
||||
'compare >= bad' => [ '>=20.0.0', false ],
|
||||
'compare >= bad' => [ '>=99.0.0', false ],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Language\Encoding
|
||||
* @coversDefaultClass \CoreLibs\Language\Encoding
|
||||
* @testdox \CoreLibs\Language\Encoding method tests
|
||||
*/
|
||||
final class CoreLibsLanguageEncodingTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @testdox Language\Encoding Class tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testLanguageEncoding()
|
||||
{
|
||||
$this->assertTrue(true, 'Language Encoding Tests not implemented');
|
||||
$this->markTestIncomplete(
|
||||
'Language\Encoding Tests have not yet been implemented'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
325
4dev/tests/CoreLibsLanguageGetSettingsTest.php
Normal file
325
4dev/tests/CoreLibsLanguageGetSettingsTest.php
Normal file
@@ -0,0 +1,325 @@
|
||||
<?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__
|
||||
File diff suppressed because it is too large
Load Diff
16
4dev/tests/includes/create_po.sh
Executable file
16
4dev/tests/includes/create_po.sh
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# if we don't have one base file we are in the wrong folder
|
||||
if [ ! -f "locale/en_US/LC_MESSAGES/admin.mo" ]; then
|
||||
echo "Locale file is missing, wrong base folder?"
|
||||
echo "Should be: 4dev/tests/includes/"
|
||||
exit;
|
||||
fi;
|
||||
|
||||
for file in $(ls -1 locale/*.po); do
|
||||
echo $file;
|
||||
file=$(basename $file .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
4dev/tests/includes/lang/admin/en_utf8.mo
Symbolic link
1
4dev/tests/includes/lang/admin/en_utf8.mo
Symbolic link
@@ -0,0 +1 @@
|
||||
../../locale/en_US/LC_MESSAGES/admin.mo
|
||||
1
4dev/tests/includes/lang/admin/ja_utf8.mo
Symbolic link
1
4dev/tests/includes/lang/admin/ja_utf8.mo
Symbolic link
@@ -0,0 +1 @@
|
||||
../../locale/ja_JP/LC_MESSAGES/admin.mo
|
||||
1
4dev/tests/includes/lang/frontend/en_utf8.mo
Symbolic link
1
4dev/tests/includes/lang/frontend/en_utf8.mo
Symbolic link
@@ -0,0 +1 @@
|
||||
../../locale/en_US/LC_MESSAGES/frontend.mo
|
||||
1
4dev/tests/includes/lang/frontend/ja_utf8.mo
Symbolic link
1
4dev/tests/includes/lang/frontend/ja_utf8.mo
Symbolic link
@@ -0,0 +1 @@
|
||||
../../locale/ja_JP/LC_MESSAGES/frontend.mo
|
||||
34
4dev/tests/includes/locale/en_US-admin.po
Normal file
34
4dev/tests/includes/locale/en_US-admin.po
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: en_US.UTF-8 LC_MESSAGES admin\n"
|
||||
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
|
||||
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: clemens.schwaighofer@egplusww.co\n"
|
||||
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
|
||||
"Language: en_US\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 "Original"
|
||||
msgstr "Translated admin en_US"
|
||||
|
||||
msgid "single"
|
||||
msgid_plural "multi"
|
||||
msgstr[0] "Multi admin en_US 0"
|
||||
msgstr[1] "Multi admin en_US 1"
|
||||
msgstr[2] "Multi admin en_US 2"
|
||||
|
||||
msgctxt "context"
|
||||
msgid "Original"
|
||||
msgstr "Original context admin en_US"
|
||||
|
||||
msgctxt "context"
|
||||
msgid "single"
|
||||
msgid_plural "multi"
|
||||
msgstr[0] "Multi context admin en_US 0"
|
||||
msgstr[1] "Multi context admin en_US 1"
|
||||
msgstr[2] "Multi context admin en_US 2"
|
||||
34
4dev/tests/includes/locale/en_US-frontend.po
Normal file
34
4dev/tests/includes/locale/en_US-frontend.po
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: en_US.UTF-8 LC_MESSAGES frontend\n"
|
||||
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
|
||||
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: clemens.schwaighofer@egplusww.co\n"
|
||||
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
|
||||
"Language: en_US\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 "Original"
|
||||
msgstr "Translated frontend en_US"
|
||||
|
||||
msgid "single"
|
||||
msgid_plural "multi"
|
||||
msgstr[0] "Multi frontend en_US 0"
|
||||
msgstr[1] "Multi frontend en_US 1"
|
||||
msgstr[2] "Multi frontend en_US 2"
|
||||
|
||||
msgctxt "context"
|
||||
msgid "Original"
|
||||
msgstr "Original context frontend en_US"
|
||||
|
||||
msgctxt "context"
|
||||
msgid "single"
|
||||
msgid_plural "multi"
|
||||
msgstr[0] "Multi context frontend en_US 0"
|
||||
msgstr[1] "Multi context frontend en_US 1"
|
||||
msgstr[2] "Multi context frontend en_US 2"
|
||||
BIN
4dev/tests/includes/locale/en_US/LC_MESSAGES/admin.mo
Normal file
BIN
4dev/tests/includes/locale/en_US/LC_MESSAGES/admin.mo
Normal file
Binary file not shown.
BIN
4dev/tests/includes/locale/en_US/LC_MESSAGES/frontend.mo
Normal file
BIN
4dev/tests/includes/locale/en_US/LC_MESSAGES/frontend.mo
Normal file
Binary file not shown.
35
4dev/tests/includes/locale/ja_JP-admin.po
Normal file
35
4dev/tests/includes/locale/ja_JP-admin.po
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: ja_JP.UTF-8 LC_MESSAGES admin\n"
|
||||
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
|
||||
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: clemens.schwaighofer@egplusww.co\n"
|
||||
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <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=3; plural=n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2;\n"
|
||||
# 0, 1, 2 plural
|
||||
|
||||
msgid "Original"
|
||||
msgstr "Translated admin ja_JP"
|
||||
|
||||
msgid "single"
|
||||
msgid_plural "multi"
|
||||
msgstr[0] "Multi admin ja_JP 0"
|
||||
msgstr[1] "Multi admin ja_JP 1"
|
||||
msgstr[2] "Multi admin ja_JP 2"
|
||||
|
||||
msgctxt "context"
|
||||
msgid "Original"
|
||||
msgstr "Original context admin ja_JP"
|
||||
|
||||
msgctxt "context"
|
||||
msgid "single"
|
||||
msgid_plural "multi"
|
||||
msgstr[0] "Multi context admin ja_JP 0"
|
||||
msgstr[1] "Multi context admin ja_JP 1"
|
||||
msgstr[2] "Multi context admin ja_JP 2"
|
||||
35
4dev/tests/includes/locale/ja_JP-frontend.po
Normal file
35
4dev/tests/includes/locale/ja_JP-frontend.po
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: ja_JP.UTF-8 LC_MESSAGES frontend\n"
|
||||
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
|
||||
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: clemens.schwaighofer@egplusww.co\n"
|
||||
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <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=3; plural=n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2;\n"
|
||||
# 0, 1, 2 plural
|
||||
|
||||
msgid "Original"
|
||||
msgstr "Translated frontend ja_JP"
|
||||
|
||||
msgid "single"
|
||||
msgid_plural "multi"
|
||||
msgstr[0] "Multi frontend ja_JP 0"
|
||||
msgstr[1] "Multi frontend ja_JP 1"
|
||||
msgstr[2] "Multi frontend ja_JP 2"
|
||||
|
||||
msgctxt "context"
|
||||
msgid "Original"
|
||||
msgstr "Original context frontend ja_JP"
|
||||
|
||||
msgctxt "context"
|
||||
msgid "single"
|
||||
msgid_plural "multi"
|
||||
msgstr[0] "Multi context frontend ja_JP 0"
|
||||
msgstr[1] "Multi context frontend ja_JP 1"
|
||||
msgstr[2] "Multi context frontend ja_JP 2"
|
||||
BIN
4dev/tests/includes/locale/ja_JP/LC_MESSAGES/admin.mo
Normal file
BIN
4dev/tests/includes/locale/ja_JP/LC_MESSAGES/admin.mo
Normal file
Binary file not shown.
BIN
4dev/tests/includes/locale/ja_JP/LC_MESSAGES/frontend.mo
Normal file
BIN
4dev/tests/includes/locale/ja_JP/LC_MESSAGES/frontend.mo
Normal file
Binary file not shown.
@@ -45,6 +45,7 @@ $log = new CoreLibs\Debug\Logging([
|
||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||
$backend = new CoreLibs\Admin\Backend($db, $log);
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: ADMIN BACKEND</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -45,6 +45,7 @@ $log = new CoreLibs\Debug\Logging([
|
||||
// $_array = new CoreLibs\Combined\ArrayHandler();
|
||||
// $array_class = 'CoreLibs\Combination\ArrayHandler';
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: ARRAY HANDLER</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -32,6 +32,7 @@ ob_end_flush();
|
||||
|
||||
use CoreLibs\Convert\Byte;
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: AUTOLOADER</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -43,6 +43,7 @@ $log = new CoreLibs\Debug\Logging([
|
||||
]);
|
||||
$byte_class = 'CoreLibs\Convert\Byte';
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: BYTE CONVERT</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -44,6 +44,7 @@ $log = new CoreLibs\Debug\Logging([
|
||||
]);
|
||||
$color_class = 'CoreLibs\Convert\Colors';
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: COLORS</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -44,6 +44,7 @@ $log = new CoreLibs\Debug\Logging([
|
||||
]);
|
||||
$datetime_class = 'CoreLibs\Combined\DateTime';
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: DATE/TIME</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -39,6 +39,7 @@ $log = new CoreLibs\Debug\Logging([
|
||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||
$db->log->debug('START', '=============================>');
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: DB</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -44,6 +44,7 @@ $debug = new CoreLibs\Debug\Logging([
|
||||
$debug_support_class = 'CoreLibs\Debug\Support';
|
||||
$debug_logging_class = 'CoreLibs\Debug\Logging';
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: DEBUG</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -43,6 +43,7 @@ $log = new CoreLibs\Debug\Logging([
|
||||
'print_all' => $PRINT_ALL ?? false,
|
||||
]);
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: HTML/ELEMENTS</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -29,7 +29,9 @@ if (!defined('SET_SESSION_NAME')) {
|
||||
$LOG_FILE_ID = 'classTest-encoding';
|
||||
ob_end_flush();
|
||||
|
||||
use CoreLibs\Language\Encoding;
|
||||
use CoreLibs\Convert\Encoding as ConEnc;
|
||||
use CoreLibs\Check\Encoding as ChkEnc;
|
||||
use CoreLibs\Convert\MimeEncode;
|
||||
|
||||
$log = new CoreLibs\Debug\Logging([
|
||||
'log_folder' => BASE . LOG,
|
||||
@@ -41,10 +43,13 @@ $log = new CoreLibs\Debug\Logging([
|
||||
'echo_all' => $ECHO_ALL ?? false,
|
||||
'print_all' => $PRINT_ALL ?? false,
|
||||
]);
|
||||
$_encoding = new CoreLibs\Language\Encoding();
|
||||
$encoding_class = 'CoreLibs\Language\Encoding';
|
||||
// class type
|
||||
$_chk_enc = new CoreLibs\Check\Encoding();
|
||||
$_con_enc = new CoreLibs\Convert\Encoding();
|
||||
$chk_enc = 'CoreLibs\Check\Encoding';
|
||||
|
||||
print "<html><head><title>TEST CLASS: ENCODING</title><head>";
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: ENCODING (CHECK/CONVERT/MIME)</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -58,41 +63,47 @@ $mime_encodes = [
|
||||
['日本語ながい日本語ながい日本語ながい日本語ながい日本語ながい日本語ながい日本語ながい', 'ISO-2022-JP-MS'],
|
||||
];
|
||||
foreach ($mime_encodes as $mime_encode) {
|
||||
print "__MBMIMEENCODE: $mime_encode[0]: " . Encoding::__mbMimeEncode($mime_encode[0], $mime_encode[1]) . "<br>";
|
||||
print "__MBMIMEENCODE: $mime_encode[0]: " . MimeEncode::__mbMimeEncode($mime_encode[0], $mime_encode[1]) . "<br>";
|
||||
}
|
||||
echo "<br>";
|
||||
|
||||
$enc_strings = [
|
||||
'Normal Text',
|
||||
'日本語',
|
||||
// bad
|
||||
'❶',
|
||||
// unworkable
|
||||
''
|
||||
];
|
||||
// class
|
||||
$_encoding->setErrorChar('∴');
|
||||
$_chk_enc->setErrorChar(0x2234);
|
||||
$_chk_enc->setErrorChar('∴');
|
||||
print "ERROR CHAR: " . $_chk_enc->getErrorChar() . "<br>";
|
||||
foreach ($enc_strings as $_string) {
|
||||
$string = $_encoding->checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
|
||||
print "ENC CHECK: $_string: " . ($string === false ? '-OK-' : $string) . "<br>";
|
||||
print "CONV ENCODING: $_string: " . $_encoding->convertEncoding($_string, 'ISO-2022-JP') . "<br>";
|
||||
print "CONV ENCODING (s): $_string: " . $_encoding->convertEncoding($_string, 'ISO-2022-JP', 'UTF-8') . "<br>";
|
||||
$string = $_chk_enc->checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
|
||||
print "ENC CHECK: $_string: " . ($string === false ? '<b>-OK-</b>' : print_r($string, true)) . "<br>";
|
||||
print "CONV ENCODING: $_string: " . $_con_enc->convertEncoding($_string, 'ISO-2022-JP') . "<br>";
|
||||
print "CONV ENCODING (s): $_string: " . $_con_enc->convertEncoding($_string, 'ISO-2022-JP', 'UTF-8') . "<br>";
|
||||
print "CONV ENCODING (s,a-false): $_string: "
|
||||
. $_encoding->convertEncoding($_string, 'ISO-2022-JP', 'UTF-8', false) . "<br>";
|
||||
. $_con_enc->convertEncoding($_string, 'ISO-2022-JP', 'UTF-8', false) . "<br>";
|
||||
}
|
||||
print "ERROR CHAR: " . $_encoding->getErrorChar() . "<br>";
|
||||
echo "<br>";
|
||||
// static
|
||||
$encoding_class::setErrorChar('∴');
|
||||
// ChkEnc::setErrorChar('∴');
|
||||
ChkEnc::setErrorChar(0x2234);
|
||||
print "S::ERROR CHAR: " . ChkEnc::getErrorChar() . "<br>";
|
||||
foreach ($enc_strings as $_string) {
|
||||
$string = $encoding_class::checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
|
||||
print "S::ENC CHECK: $_string: " . ($string === false ? '-OK-' : $string) . "<br>";
|
||||
print "S::CONV ENCODING: $_string: " . $encoding_class::convertEncoding($_string, 'ISO-2022-JP') . "<br>";
|
||||
$string = ChkEnc::checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
|
||||
print "S::ENC CHECK: $_string: " . ($string === false ? '<b>-OK-</b>' : print_r($string, true)) . "<br>";
|
||||
print "S::CONV ENCODING: $_string: " . ConEnc::convertEncoding($_string, 'ISO-2022-JP') . "<br>";
|
||||
print "S::CONV ENCODING (s): $_string: "
|
||||
. $encoding_class::convertEncoding($_string, 'ISO-2022-JP', 'UTF-8') . "<br>";
|
||||
. ConEnc::convertEncoding($_string, 'ISO-2022-JP', 'UTF-8') . "<br>";
|
||||
print "S::CONV ENCODING (s,a-false): $_string: "
|
||||
. $encoding_class::convertEncoding($_string, 'ISO-2022-JP', 'UTF-8', false) . "<br>";
|
||||
. ConEnc::convertEncoding($_string, 'ISO-2022-JP', 'UTF-8', false) . "<br>";
|
||||
}
|
||||
print "S::ERROR CHAR: " . $encoding_class::getErrorChar() . "<br>";
|
||||
// static use
|
||||
$_string = $enc_strings[1];
|
||||
$string = Encoding::checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
|
||||
$string = $chk_enc::checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
|
||||
print "S::ENC CHECK: $_string: " . ($string === false ? '-OK-' : $string) . "<br>";
|
||||
|
||||
// error message
|
||||
|
||||
@@ -42,6 +42,7 @@ $log = new CoreLibs\Debug\Logging([
|
||||
'print_all' => $PRINT_ALL ?? false,
|
||||
]);
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: FILE</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -45,6 +45,7 @@ $hash_class = 'CoreLibs\Create\Hash';
|
||||
|
||||
// define a list of from to color sets for conversion test
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: HASH</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -49,6 +49,7 @@ $elements_class = 'CoreLibs\Output\Form\Elements';
|
||||
|
||||
// define a list of from to color sets for conversion test
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: HTML/ELEMENTS</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -46,6 +46,7 @@ $image_class = 'CoreLibs\Output\Image';
|
||||
|
||||
// define a list of from to color sets for conversion test
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: IMAGE</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -46,6 +46,7 @@ $json_class = 'CoreLibs\Convert\Json';
|
||||
|
||||
// define a list of from to color sets for conversion test
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: JSON</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -29,28 +29,135 @@ if (!defined('SET_SESSION_NAME')) {
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-lang';
|
||||
|
||||
$l = new CoreLibs\Language\L10n($lang);
|
||||
ob_end_flush();
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: LANG</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
use CoreLibs\Language\L10n;
|
||||
|
||||
$string = 'INPUT TEST';
|
||||
|
||||
echo "LANGUAGE SET: " . $l->__getLang() . "<br>";
|
||||
echo "LANGUAGE FILE: " . $l->__getMoFile() . "<br>";
|
||||
echo "<br><b>LEGACY TEST</b><br>";
|
||||
|
||||
$lang = 'en_utf8';
|
||||
$l = new CoreLibs\Language\L10n($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>";
|
||||
$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>";
|
||||
}
|
||||
$context = "month name";
|
||||
$context_string = "May";
|
||||
echo "CONTEXT TRANSLATION: " . $context_string . " => " . $l->__p($context, $context_string) . "<br>";
|
||||
$single_string = 'single';
|
||||
$multi_string = 'multi';
|
||||
for ($n = 0; $n <= 3; $n++) {
|
||||
echo "CONTEXT MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
|
||||
. $l->__pn($context, $single_string, $multi_string, $n) . "<br>";
|
||||
}
|
||||
|
||||
// switch to other language
|
||||
$lang = 'ja_utf8';
|
||||
$l->l10nReloadMOfile($lang);
|
||||
|
||||
echo "LANGUAGE SET: " . $l->__getLang() . "<br>";
|
||||
echo "LANGUAGE FILE: " . $l->__getMoFile() . "<br>";
|
||||
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>";
|
||||
// TODO: run compare check input must match output
|
||||
// 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';
|
||||
$l->getTranslator('', $path, $domain);
|
||||
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>";
|
||||
|
||||
$domain = 'admin';
|
||||
echo "<br><b>STATIC TYPE TEST</b><br>";
|
||||
// static tests from l10n_load
|
||||
L10n::getInstance()->setLocale($lang);
|
||||
echo "SET LOCALE: " . L10n::getInstance()->getLocale() . "<br>";
|
||||
L10n::getInstance()->setDomain($domain);
|
||||
echo "SET DOMAIN: " . L10n::getInstance()->getDomain() . "<br>";
|
||||
L10n::getInstance()->setTextDomain($domain, $path);
|
||||
echo "SET TEXT DOMAIN: " . L10n::getInstance()->getTextDomain($domain) . "<br>";
|
||||
// null call __bind_textdomain_codeset
|
||||
echo "INPUT TEST: " . $string . " => " . L10n::getInstance()->getTranslator()->gettext($string) . "<br>";
|
||||
|
||||
echo "<br><b>FUNCTIONS</b><br>";
|
||||
// real statisc test
|
||||
L10n::loadFunctions();
|
||||
$locale = 'ja';
|
||||
__setlocale(LC_MESSAGES, $locale);
|
||||
__textdomain($domain);
|
||||
__bindtextdomain($domain, $path);
|
||||
__bind_textdomain_codeset($domain, $encoding);
|
||||
echo "INPUT TEST $locale: " . $string . " => " . __($string) . "<br>";
|
||||
|
||||
$locale = 'en_US.UTF-8';
|
||||
__setlocale(LC_MESSAGES, $locale);
|
||||
__textdomain($domain);
|
||||
__bindtextdomain($domain, $path);
|
||||
__bind_textdomain_codeset($domain, $encoding);
|
||||
echo "INPUT TEST $locale: " . $string . " => " . __($string) . "<br>";
|
||||
|
||||
print "</body></html>";
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ $math_class = 'CoreLibs\Convert\Math';
|
||||
|
||||
// define a list of from to color sets for conversion test
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: MATH</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -41,6 +41,7 @@ $log = new CoreLibs\Debug\Logging([
|
||||
]);
|
||||
$_mime = new CoreLibs\Convert\MimeAppName();
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: MIME</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -69,6 +69,7 @@ $log = new CoreLibs\Debug\Logging([
|
||||
]);
|
||||
$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $log);
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: FORM GENERATE</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -46,6 +46,7 @@ $password_class = 'CoreLibs\Check\Password';
|
||||
|
||||
// define a list of from to color sets for conversion test
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: PASSWORD</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -45,6 +45,7 @@ $backend = new CoreLibs\Admin\Backend($db, $log);
|
||||
$backend->db->dbInfo(true);
|
||||
ob_end_flush();
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS</title><head>";
|
||||
print "<body>";
|
||||
|
||||
@@ -60,7 +61,7 @@ print '<div><a href="class_test.email.php">Class Test: EMAIL</a></div>';
|
||||
print '<div><a href="class_test.uids.php">Class Test: UIDS</a></div>';
|
||||
print '<div><a href="class_test.phpv.php">Class Test: PHP VERSION</a></div>';
|
||||
print '<div><a href="class_test.hash.php">Class Test: HASH</a></div>';
|
||||
print '<div><a href="class_test.encoding.php">Class Test: ENCODING</a></div>';
|
||||
print '<div><a href="class_test.encoding.php">Class Test: ENCODING (CHECK/CONVERT/MIME)</a></div>';
|
||||
print '<div><a href="class_test.image.php">Class Test: IMAGE</a></div>';
|
||||
print '<div><a href="class_test.byte.php">Class Test: BYTE CONVERT</a></div>';
|
||||
print '<div><a href="class_test.datetime.php">Class Test: DATE/TIME</a></div>';
|
||||
|
||||
@@ -46,6 +46,7 @@ $phpv_class = 'CoreLibs\Check\PhpVersion';
|
||||
|
||||
// define a list of from to color sets for conversion test
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: PHP VERSION</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -43,6 +43,7 @@ $log = new CoreLibs\Debug\Logging([
|
||||
]);
|
||||
$array_class = 'CoreLibs\Create\RandomKey';
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: RANDOM KEY</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -34,6 +34,7 @@ $log = new CoreLibs\Debug\Logging([
|
||||
]);
|
||||
$ref_class = 'CoreLibs\Get\ReadEnvFile';
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: READ ENV FILE</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -42,6 +42,7 @@ $log = new CoreLibs\Debug\Logging([
|
||||
'print_all' => $PRINT_ALL ?? false,
|
||||
]);
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: RUNNING IMTE</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -46,6 +46,7 @@ $log = new CoreLibs\Debug\Logging([
|
||||
$smarty = new CoreLibs\Template\SmartyExtend();
|
||||
$l = new CoreLibs\Language\L10n($lang);
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: SMARTY</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -44,6 +44,7 @@ $log = new CoreLibs\Debug\Logging([
|
||||
]);
|
||||
$basic = new CoreLibs\Basic($log);
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: SYSTEM</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -42,6 +42,7 @@ $log = new CoreLibs\Debug\Logging([
|
||||
$_token = new CoreLibs\Output\Form\Token();
|
||||
$token_class = 'CoreLibs\Output\Form\Token';
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: FORM TOKEN</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -43,6 +43,7 @@ $_uids = new CoreLibs\Create\Uids();
|
||||
use CoreLibs\Create\Uids;
|
||||
$uids_class = 'CoreLibs\Create\Uids';
|
||||
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: UIDS</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
@@ -27,7 +27,9 @@ $__LOCAL_CONFIG = [
|
||||
'db_host' => 'test',
|
||||
'location' => 'test',
|
||||
'debug_flag' => true,
|
||||
'site_lang' => 'en_utf8',
|
||||
'site_lang' => 'en_US',
|
||||
'site_encoding' => 'UTF-8',
|
||||
'site_locale' => 'en_US.UTF-8',
|
||||
'login_enabled' => true
|
||||
];
|
||||
|
||||
@@ -45,7 +47,10 @@ $SITE_CONFIG = [
|
||||
// show DEBUG override
|
||||
'debug_flag' => true,
|
||||
// site language
|
||||
'site_lang' => 'en_utf8',
|
||||
'site_lang' => 'en_US',
|
||||
'site_encoding' => 'UTF-8',
|
||||
// lang + encoding
|
||||
'site_locale' => 'en_US.UTF-8',
|
||||
// enable/disable login override
|
||||
'login_enabled' => true
|
||||
],
|
||||
|
||||
@@ -65,8 +65,10 @@ define('JS', 'javascript' . DIRECTORY_SEPARATOR);
|
||||
define('TABLE_ARRAYS', 'table_arrays' . DIRECTORY_SEPARATOR);
|
||||
// smarty libs path
|
||||
define('SMARTY', 'Smarty' . DIRECTORY_SEPARATOR);
|
||||
// po langs
|
||||
// po langs [DEPRECAED: use LOCALE]
|
||||
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
||||
// po locale file
|
||||
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||
// cache path
|
||||
define('CACHE', 'cache' . DIRECTORY_SEPARATOR);
|
||||
// temp path
|
||||
@@ -158,9 +160,11 @@ define('CACHE_ID', 'CACHE_' . BASE_NAME . '_' . SERVER_NAME_HASH);
|
||||
define('COMPILE_ID', 'COMPILE_' . BASE_NAME . '_' . SERVER_NAME_HASH);
|
||||
|
||||
/************* LANGUAGE / ENCODING *******/
|
||||
define('DEFAULT_LANG', 'en_utf8');
|
||||
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');
|
||||
|
||||
/************* LOGGING *******************/
|
||||
// below two can be defined here, but they should be
|
||||
@@ -258,7 +262,9 @@ $GLOBALS['DB_CONFIG'] = DB_CONFIG;
|
||||
// debug settings, site lang, etc
|
||||
define('TARGET', $SITE_CONFIG[HOST_NAME]['location'] ?? 'test');
|
||||
define('DEBUG', $SITE_CONFIG[HOST_NAME]['debug_flag'] ?? false);
|
||||
define('SITE_LANG', $SITE_CONFIG[HOST_NAME]['site_lang'] ?? 'en_utf8');
|
||||
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('LOGIN_ENABLED', $SITE_CONFIG[HOST_NAME]['login_enabled'] ?? false);
|
||||
define('AUTH', $SITE_CONFIG[HOST_NAME]['auth'] ?? false);
|
||||
// paths
|
||||
|
||||
@@ -21,7 +21,10 @@ $paths = [
|
||||
];
|
||||
// find convert
|
||||
foreach ($paths as $path) {
|
||||
if (file_exists($path . DIRECTORY_SEPARATOR . 'convert') && is_file($path . DIRECTORY_SEPARATOR . 'convert')) {
|
||||
if (
|
||||
file_exists($path . DIRECTORY_SEPARATOR . 'convert') &&
|
||||
is_file($path . DIRECTORY_SEPARATOR . 'convert')
|
||||
) {
|
||||
// image magick convert location
|
||||
define('CONVERT', $path . DIRECTORY_SEPARATOR . 'convert');
|
||||
break;
|
||||
|
||||
Binary file not shown.
1
www/includes/lang/admin/en_utf8.mo
Symbolic link
1
www/includes/lang/admin/en_utf8.mo
Symbolic link
@@ -0,0 +1 @@
|
||||
../../locale/en_US/LC_MESSAGES/admin.mo
|
||||
Binary file not shown.
1
www/includes/lang/admin/ja_utf8.mo
Symbolic link
1
www/includes/lang/admin/ja_utf8.mo
Symbolic link
@@ -0,0 +1 @@
|
||||
../../locale/ja/LC_MESSAGES/admin.mo
|
||||
1
www/includes/lang/frontend/en_utf8.mo
Symbolic link
1
www/includes/lang/frontend/en_utf8.mo
Symbolic link
@@ -0,0 +1 @@
|
||||
../../locale/en_US/LC_MESSAGES/frontend.mo
|
||||
1
www/includes/lang/frontend/ja_utf8.mo
Symbolic link
1
www/includes/lang/frontend/ja_utf8.mo
Symbolic link
@@ -0,0 +1 @@
|
||||
../../locale/ja/LC_MESSAGES/frontend.mo
|
||||
BIN
www/includes/locale/en_US/LC_MESSAGES/admin.mo
Normal file
BIN
www/includes/locale/en_US/LC_MESSAGES/admin.mo
Normal file
Binary file not shown.
BIN
www/includes/locale/en_US/LC_MESSAGES/frontend.mo
Normal file
BIN
www/includes/locale/en_US/LC_MESSAGES/frontend.mo
Normal file
Binary file not shown.
BIN
www/includes/locale/ja/LC_MESSAGES/admin.mo
Normal file
BIN
www/includes/locale/ja/LC_MESSAGES/admin.mo
Normal file
Binary file not shown.
BIN
www/includes/locale/ja/LC_MESSAGES/frontend.mo
Normal file
BIN
www/includes/locale/ja/LC_MESSAGES/frontend.mo
Normal file
Binary file not shown.
@@ -715,20 +715,20 @@ class Basic
|
||||
|
||||
// *** ARRAY HANDLING END
|
||||
// [!!! DEPRECATED !!!]
|
||||
// Moved to \CoreLibs\Language\Encoding
|
||||
// Moved to \CoreLibs\Convert\MimeEncode
|
||||
|
||||
/**
|
||||
* wrapper function for mb mime convert, for correct conversion with long strings
|
||||
* @param string $string string to encode
|
||||
* @param string $encoding target encoding
|
||||
* @return string encoded string
|
||||
* @deprecated Use \CoreLibs\Language\Encoding::__mbMimeEncode() instead
|
||||
* @deprecated Use \CoreLibs\Convert\MimeEncode::__mbMimeEncode() instead
|
||||
*/
|
||||
public static function __mbMimeEncode(string $string, string $encoding): string
|
||||
{
|
||||
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Language\Encoding::__mbMimeEncode()', E_USER_DEPRECATED);
|
||||
return \CoreLibs\Language\Encoding::__mbMimeEncode($string, $encoding);
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\MimeEncode::__mbMimeEncode()', E_USER_DEPRECATED);
|
||||
return \CoreLibs\Convert\MimeEncode::__mbMimeEncode($string, $encoding);
|
||||
}
|
||||
|
||||
// *** HUMAND BYTE READABLE CONVERT
|
||||
@@ -1009,7 +1009,7 @@ class Basic
|
||||
|
||||
// *** ENCODING FUNCTIONS
|
||||
// [!!! DEPRECATED !!!]
|
||||
// Moved to \CoreLibs\Language\Encoding
|
||||
// Moved to \CoreLibs\Check\Encoding and \CoreLibs\Convert\Encoding
|
||||
|
||||
/**
|
||||
* test if a string can be safely convert between encodings. mostly utf8 to shift jis
|
||||
@@ -1026,12 +1026,12 @@ class Basic
|
||||
* @param string $from_encoding encoding of string to test
|
||||
* @param string $to_encoding target encoding
|
||||
* @return bool|array<mixed> false if no error or array with failed characters
|
||||
* @deprecated use \CoreLibs\Language\Encoding::checkConvertEncoding() instead
|
||||
* @deprecated use \CoreLibs\Check\Encoding::checkConvertEncoding() instead
|
||||
*/
|
||||
public function checkConvertEncoding(string $string, string $from_encoding, string $to_encoding)
|
||||
{
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Language\Encoding::checkConvertEncoding()', E_USER_DEPRECATED);
|
||||
return \CoreLibs\Language\Encoding::checkConvertEncoding($string, $from_encoding, $to_encoding);
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Check\Encoding::checkConvertEncoding()', E_USER_DEPRECATED);
|
||||
return \CoreLibs\Check\Encoding::checkConvertEncoding($string, $from_encoding, $to_encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1047,12 +1047,12 @@ class Basic
|
||||
* check that the source is actually matching
|
||||
* to what we sav the source is
|
||||
* @return string encoding converted string
|
||||
* @deprecated use \CoreLibs\Language\Encoding::convertEncoding() instead
|
||||
* @deprecated use \CoreLibs\Convert\Encoding::convertEncoding() instead
|
||||
*/
|
||||
public static function convertEncoding(string $string, string $to_encoding, string $source_encoding = '', bool $auto_check = true): string
|
||||
{
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Language\Encoding::convertEncoding()', E_USER_DEPRECATED);
|
||||
return \CoreLibs\Language\Encoding::convertEncoding($string, $to_encoding, $source_encoding, $auto_check);
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Encoding::convertEncoding()', E_USER_DEPRECATED);
|
||||
return \CoreLibs\Convert\Encoding::convertEncoding($string, $to_encoding, $source_encoding, $auto_check);
|
||||
}
|
||||
|
||||
// *** ENCODING FUNCTIONS END
|
||||
|
||||
117
www/lib/CoreLibs/Check/Encoding.php
Normal file
117
www/lib/CoreLibs/Check/Encoding.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* check if string is valid in target encoding
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Check;
|
||||
|
||||
class Encoding
|
||||
{
|
||||
/** @var int<min, -1>|int<1, max>|string */
|
||||
private static $mb_error_char = '';
|
||||
|
||||
/**
|
||||
* set error char
|
||||
*
|
||||
* @param string|int|null $string The character to use to represent
|
||||
* error chars
|
||||
* "long" for long, "none" for none
|
||||
* or a valid code point in int
|
||||
* like 0x2234 (8756, ∴)
|
||||
* default character is ? (63)
|
||||
* if null is set then "none"
|
||||
* @return void
|
||||
*/
|
||||
public static function setErrorChar($string): void
|
||||
{
|
||||
if (empty($string)) {
|
||||
$string = 'none';
|
||||
}
|
||||
// if not special string or char but code point
|
||||
if (in_array($string, ['none', 'long', 'entity'])) {
|
||||
self::$mb_error_char = $string;
|
||||
} else {
|
||||
// always convert to char for internal use
|
||||
self::$mb_error_char = \IntlChar::chr($string);
|
||||
// if string convert to code point
|
||||
if (is_string($string)) {
|
||||
$string = \IntlChar::ord($string);
|
||||
}
|
||||
}
|
||||
mb_substitute_character($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the current set error character
|
||||
*
|
||||
* @param bool $return_substitute_func if set to true return the set
|
||||
* character from the php function
|
||||
* directly
|
||||
* @return string|int Set error character
|
||||
*/
|
||||
public static function getErrorChar(bool $return_substitute_func = false)
|
||||
{
|
||||
// return mb_substitute_character();
|
||||
if ($return_substitute_func === true) {
|
||||
return mb_substitute_character();
|
||||
} else {
|
||||
return self::$mb_error_char;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* test if a string can be safely convert between encodings.
|
||||
* mostly utf8 to shift jis
|
||||
* the default compare has a possibility of failure, especially with windows
|
||||
* it is recommended to the following in the script which uses this method:
|
||||
* mb_substitute_character(0x2234);
|
||||
* $class->mb_error_char = '∴';
|
||||
* if check to Shift JIS
|
||||
* if check to ISO-2022-JP
|
||||
* if check to ISO-2022-JP-MS
|
||||
* set three dots (∴) as wrong character for correct convert error detect
|
||||
* (this char is used, because it is one of the least used ones)
|
||||
*
|
||||
* @param string $string string to test
|
||||
* @param string $from_encoding encoding of string to test
|
||||
* @param string $to_encoding target encoding
|
||||
* @return bool|array<string> false if no error or
|
||||
* array with failed characters
|
||||
*/
|
||||
public static function checkConvertEncoding(
|
||||
string $string,
|
||||
string $from_encoding,
|
||||
string $to_encoding
|
||||
) {
|
||||
// convert to target encoding and convert back
|
||||
$temp = mb_convert_encoding($string, $to_encoding, $from_encoding);
|
||||
$compare = mb_convert_encoding($temp, $from_encoding, $to_encoding);
|
||||
// if string does not match anymore we have a convert problem
|
||||
if ($string != $compare) {
|
||||
$failed = [];
|
||||
// go through each character and find the ones that do not match
|
||||
for ($i = 0, $iMax = mb_strlen($string, $from_encoding); $i < $iMax; $i++) {
|
||||
$char = mb_substr($string, $i, 1, $from_encoding);
|
||||
$r_char = mb_substr($compare, $i, 1, $from_encoding);
|
||||
// the ord 194 is a hack to fix the IE7/IE8
|
||||
// bug with line break and illegal character
|
||||
if (
|
||||
(($char != $r_char && (!self::$mb_error_char ||
|
||||
in_array(self::$mb_error_char, ['none', 'long', 'entity']))) ||
|
||||
($char != $r_char && $r_char == self::$mb_error_char && self::$mb_error_char)) &&
|
||||
ord($char) != 194
|
||||
) {
|
||||
$failed[] = $char;
|
||||
}
|
||||
}
|
||||
return $failed;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
60
www/lib/CoreLibs/Convert/Encoding.php
Normal file
60
www/lib/CoreLibs/Convert/Encoding.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* check if string is valid in target encoding
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Convert;
|
||||
|
||||
class Encoding
|
||||
{
|
||||
/**
|
||||
* detects the source encoding of the string and if doesn't match
|
||||
* to the given target encoding it convert is
|
||||
* if source encoding is set and auto check is true (default) a second
|
||||
* check is done so that the source string encoding actually matches
|
||||
* will be skipped if source encoding detection is ascii
|
||||
*
|
||||
* @param string $string string to convert
|
||||
* @param string $to_encoding target encoding
|
||||
* @param string $source_encoding optional source encoding, will try to auto detect
|
||||
* @param bool $auto_check default true, if source encoding is set
|
||||
* check that the source is actually matching
|
||||
* to what we sav the source is
|
||||
* @return string encoding converted string
|
||||
*/
|
||||
public static function convertEncoding(
|
||||
string $string,
|
||||
string $to_encoding,
|
||||
string $source_encoding = '',
|
||||
bool $auto_check = true
|
||||
): string {
|
||||
// set if not given
|
||||
if (!$source_encoding) {
|
||||
$source_encoding = mb_detect_encoding($string);
|
||||
} else {
|
||||
$_source_encoding = mb_detect_encoding($string);
|
||||
}
|
||||
if (
|
||||
$auto_check === true &&
|
||||
isset($_source_encoding) &&
|
||||
$_source_encoding == $source_encoding
|
||||
) {
|
||||
// trigger check if we have override source encoding.
|
||||
// if different (_source is all but not ascii) then trigger
|
||||
// skip if matching
|
||||
}
|
||||
if ($source_encoding != $to_encoding) {
|
||||
if ($source_encoding) {
|
||||
$string = mb_convert_encoding($string, $to_encoding, $source_encoding);
|
||||
} else {
|
||||
$string = mb_convert_encoding($string, $to_encoding);
|
||||
}
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
67
www/lib/CoreLibs/Convert/MimeEncode.php
Normal file
67
www/lib/CoreLibs/Convert/MimeEncode.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* alternate for header mime encode to void problems with long strings and
|
||||
* spaces/strange encoding problems.
|
||||
* Orignal issues during PHP5/7
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Convert;
|
||||
|
||||
class MimeEncode
|
||||
{
|
||||
/**
|
||||
* wrapper function for mb mime convert
|
||||
* for correct conversion with long strings
|
||||
*
|
||||
* @param string $string string to encode
|
||||
* @param string $encoding target encoding
|
||||
* @param string $line_break default line break is \r\n
|
||||
* @return string encoded string
|
||||
*/
|
||||
public static function __mbMimeEncode(
|
||||
string $string,
|
||||
string $encoding,
|
||||
string $line_break = "\r\n"
|
||||
): string {
|
||||
// set internal encoding, so the mimeheader encode works correctly
|
||||
mb_internal_encoding($encoding);
|
||||
// if a subject, make a work around for the broken mb_mimencode
|
||||
$pos = 0;
|
||||
// after 36 single bytes characters,
|
||||
// if then comes MB, it is broken
|
||||
// has to 2 x 36 < 74 so the mb_encode_mimeheader
|
||||
// 74 hardcoded split does not get triggered
|
||||
$split = 36;
|
||||
$_string = '';
|
||||
while ($pos < mb_strlen($string, $encoding)) {
|
||||
$output = mb_strimwidth($string, $pos, $split, "", $encoding);
|
||||
$pos += mb_strlen($output, $encoding);
|
||||
// if the strinlen is 0 here, get out of the loop
|
||||
if (!mb_strlen($output, $encoding)) {
|
||||
$pos += mb_strlen($string, $encoding);
|
||||
}
|
||||
$_string_encoded = mb_encode_mimeheader($output, $encoding);
|
||||
// only make linebreaks if we have mime encoded code inside
|
||||
// the space only belongs in the second line
|
||||
if ($_string && preg_match("/^=\?/", $_string_encoded)) {
|
||||
$_string .= $line_break . " ";
|
||||
} elseif (
|
||||
// hack for plain text with space at the end
|
||||
mb_strlen($output, $encoding) == $split &&
|
||||
mb_substr($output, -1, 1, $encoding) == " "
|
||||
) {
|
||||
// if output ends with space, add one more
|
||||
$_string_encoded .= " ";
|
||||
}
|
||||
$_string .= $_string_encoded;
|
||||
}
|
||||
// strip out any spaces BEFORE a line break
|
||||
$string = str_replace(" " . $line_break, $line_break, $_string);
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -39,7 +39,7 @@ class FileReader
|
||||
* file read constructor
|
||||
* @param string $filename file name to load
|
||||
*/
|
||||
public function __construct($filename)
|
||||
public function __construct(string $filename)
|
||||
{
|
||||
if (file_exists($filename)) {
|
||||
$this->fr_length = filesize($filename) ?: 0;
|
||||
@@ -58,7 +58,7 @@ class FileReader
|
||||
* @param int $bytes how many bytes to read
|
||||
* @return string read data as string
|
||||
*/
|
||||
public function read($bytes)
|
||||
public function read(int $bytes): string
|
||||
{
|
||||
if (!$bytes || !is_resource($this->fr_fd)) {
|
||||
return '';
|
||||
@@ -86,7 +86,7 @@ class FileReader
|
||||
* @param int $pos position where to go to
|
||||
* @return int file position after seek done
|
||||
*/
|
||||
public function seekto($pos)
|
||||
public function seekto(int $pos): int
|
||||
{
|
||||
if (!is_resource($this->fr_fd)) {
|
||||
return 0;
|
||||
@@ -100,7 +100,7 @@ class FileReader
|
||||
* get current position in file
|
||||
* @return int current position in bytes
|
||||
*/
|
||||
public function currentpos()
|
||||
public function currentpos(): int
|
||||
{
|
||||
return $this->fr_pos;
|
||||
}
|
||||
@@ -109,7 +109,7 @@ class FileReader
|
||||
* file length/size
|
||||
* @return int file size in bytes
|
||||
*/
|
||||
public function length()
|
||||
public function length(): int
|
||||
{
|
||||
return $this->fr_length;
|
||||
}
|
||||
|
||||
@@ -67,17 +67,15 @@ class GetTextReader
|
||||
/** @var array<mixed> */
|
||||
private $cache_translations = []; // original -> translation mapping
|
||||
|
||||
|
||||
/* Methods */
|
||||
|
||||
|
||||
/**
|
||||
* Reads a 32bit Integer from the Stream
|
||||
*
|
||||
* @access private
|
||||
* @return int Integer from the Stream
|
||||
*/
|
||||
private function readint()
|
||||
private function readint(): int
|
||||
{
|
||||
if ($this->BYTEORDER == 0) {
|
||||
// low endian
|
||||
@@ -91,10 +89,11 @@ class GetTextReader
|
||||
|
||||
/**
|
||||
* read bytes
|
||||
*
|
||||
* @param int $bytes byte length to read
|
||||
* @return string return data, possible string
|
||||
*/
|
||||
public function read($bytes)
|
||||
public function read(int $bytes): string
|
||||
{
|
||||
return $this->STREAM->read($bytes);
|
||||
}
|
||||
@@ -105,7 +104,7 @@ class GetTextReader
|
||||
* @param int $count How many elements should be read
|
||||
* @return array<mixed> Array of Integers
|
||||
*/
|
||||
public function readintarray($count)
|
||||
public function readintarray(int $count): array
|
||||
{
|
||||
if ($this->BYTEORDER == 0) {
|
||||
// low endian
|
||||
@@ -120,9 +119,10 @@ class GetTextReader
|
||||
* Constructor
|
||||
*
|
||||
* @param FileReader|bool $Reader the StreamReader object
|
||||
* @param bool $enable_cache Enable or disable caching of strings (default on)
|
||||
* @param bool $enable_cache Enable or disable caching
|
||||
* of strings (default on)
|
||||
*/
|
||||
public function __construct($Reader, $enable_cache = true)
|
||||
public function __construct($Reader, bool $enable_cache = true)
|
||||
{
|
||||
// If there isn't a StreamReader, turn on short circuit mode.
|
||||
if ((!is_object($Reader) && !$Reader) || (is_object($Reader) && $Reader->error)) {
|
||||
@@ -159,6 +159,26 @@ class GetTextReader
|
||||
$this->translations = $this->readint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current short circuit, equals to no translator running
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getShortCircuit(): bool
|
||||
{
|
||||
return $this->short_circuit;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the current cache enabled status
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getEnableCache(): bool
|
||||
{
|
||||
return $this->enable_cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the translation tables from the MO file into the cache
|
||||
* If caching is enabled, also loads all strings into a cache
|
||||
@@ -207,7 +227,7 @@ class GetTextReader
|
||||
* @param int $num Offset number of original string
|
||||
* @return string Requested string if found, otherwise ''
|
||||
*/
|
||||
private function getOriginalString($num)
|
||||
private function getOriginalString(int $num): string
|
||||
{
|
||||
$length = $this->table_originals[$num * 2 + 1] ?? 0;
|
||||
$offset = $this->table_originals[$num * 2 + 2] ?? 0;
|
||||
@@ -226,7 +246,7 @@ class GetTextReader
|
||||
* @param int $num Offset number of original string
|
||||
* @return string Requested string if found, otherwise ''
|
||||
*/
|
||||
private function getTranslationString($num)
|
||||
private function getTranslationString(int $num): string
|
||||
{
|
||||
$length = $this->table_translations[$num * 2 + 1] ?? 0;
|
||||
$offset = $this->table_translations[$num * 2 + 2] ?? 0;
|
||||
@@ -242,12 +262,12 @@ class GetTextReader
|
||||
* Binary search for string
|
||||
*
|
||||
* @access private
|
||||
* @param string $string string to find
|
||||
* @param int $start (internally used in recursive function)
|
||||
* @param int $end (internally used in recursive function)
|
||||
* @return int (offset in originals table)
|
||||
* @param string $string string to find
|
||||
* @param int $start (internally used in recursive function)
|
||||
* @param int $end (internally used in recursive function)
|
||||
* @return int (offset in originals table)
|
||||
*/
|
||||
private function findString($string, $start = -1, $end = -1)
|
||||
private function findString(string $string, int $start = -1, int $end = -1): int
|
||||
{
|
||||
if (($start == -1) or ($end == -1)) {
|
||||
// findString is called with only one parameter, set start end end
|
||||
@@ -289,7 +309,7 @@ class GetTextReader
|
||||
* @param string $string to be translated
|
||||
* @return string translated string (or original, if not found)
|
||||
*/
|
||||
public function translate($string)
|
||||
public function translate(string $string): string
|
||||
{
|
||||
if ($this->short_circuit) {
|
||||
return $string;
|
||||
@@ -298,7 +318,10 @@ class GetTextReader
|
||||
|
||||
if ($this->enable_cache) {
|
||||
// Caching enabled, get translated string from cache
|
||||
if (is_array($this->cache_translations) && array_key_exists($string, $this->cache_translations)) {
|
||||
if (
|
||||
is_array($this->cache_translations) &&
|
||||
array_key_exists($string, $this->cache_translations)
|
||||
) {
|
||||
return $this->cache_translations[$string];
|
||||
} else {
|
||||
return $string;
|
||||
@@ -321,7 +344,7 @@ class GetTextReader
|
||||
* @param string $expr an expression to match
|
||||
* @return string sanitized plural form expression
|
||||
*/
|
||||
private function sanitizePluralExpression($expr)
|
||||
private function sanitizePluralExpression(string $expr): string
|
||||
{
|
||||
// Get rid of disallowed characters.
|
||||
$expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr);
|
||||
@@ -330,7 +353,8 @@ class GetTextReader
|
||||
$expr .= ';';
|
||||
$res = '';
|
||||
$p = 0;
|
||||
for ($i = 0; $i < strlen($expr); $i++) {
|
||||
$expr_len = strlen($expr);
|
||||
for ($i = 0; $i < $expr_len; $i++) {
|
||||
$ch = $expr[$i];
|
||||
switch ($ch) {
|
||||
case '?':
|
||||
@@ -358,7 +382,7 @@ class GetTextReader
|
||||
* @param string $header header search in plurals
|
||||
* @return string verbatim plural form header field
|
||||
*/
|
||||
private function extractPluralFormsHeaderFromPoHeader($header)
|
||||
private function extractPluralFormsHeaderFromPoHeader(string $header): string
|
||||
{
|
||||
if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) {
|
||||
$expr = $regs[2];
|
||||
@@ -374,14 +398,14 @@ class GetTextReader
|
||||
* @access private
|
||||
* @return string plural form header
|
||||
*/
|
||||
private function getPluralForms()
|
||||
private function getPluralForms(): string
|
||||
{
|
||||
// lets assume message number 0 is header
|
||||
// this is true, right?
|
||||
$this->loadTables();
|
||||
|
||||
// cache header field for plural forms
|
||||
if (! is_string($this->pluralheader)) {
|
||||
if (empty($this->pluralheader) || !is_string($this->pluralheader)) {
|
||||
if ($this->enable_cache) {
|
||||
$header = $this->cache_translations[''];
|
||||
} else {
|
||||
@@ -397,25 +421,38 @@ class GetTextReader
|
||||
* Detects which plural form to take
|
||||
*
|
||||
* @access private
|
||||
* @param string $n count
|
||||
* @return int array index of the right plural form
|
||||
* @param int $n count
|
||||
* @return int array index of the right plural form
|
||||
*/
|
||||
private function selectString($n)
|
||||
private function selectString(int $n): int
|
||||
{
|
||||
$string = $this->getPluralForms();
|
||||
$string = str_replace('nplurals', "\$total", $string);
|
||||
$string = str_replace("n", $n, $string);
|
||||
$string = str_replace("n", (string)$n, $string);
|
||||
$string = str_replace('plural', "\$plural", $string);
|
||||
|
||||
$total = 0;
|
||||
$plural = 0;
|
||||
|
||||
// FIXME use Symfony\Component\ExpressionLanguage\ExpressionLanguage or similar
|
||||
eval("$string");
|
||||
/** @phpstan-ignore-next-line */
|
||||
/** @phpstan-ignore-next-line 0 >= 0 is always true*/
|
||||
if ($plural >= $total) {
|
||||
$plural = $total - 1;
|
||||
}
|
||||
return $plural;
|
||||
return (int)$plural;
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper for translate() method
|
||||
*
|
||||
* @access public
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public function gettext(string $string): string
|
||||
{
|
||||
return $this->translate($string);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -424,10 +461,10 @@ class GetTextReader
|
||||
* @access public
|
||||
* @param string $single
|
||||
* @param string $plural
|
||||
* @param string $number
|
||||
* @param int $number
|
||||
* @return string plural form
|
||||
*/
|
||||
public function ngettext($single, $plural, $number)
|
||||
public function ngettext(string $single, string $plural, int $number): string
|
||||
{
|
||||
if ($this->short_circuit) {
|
||||
if ($number != 1) {
|
||||
@@ -465,11 +502,12 @@ class GetTextReader
|
||||
|
||||
/**
|
||||
* p get text
|
||||
*
|
||||
* @param string $context [description]
|
||||
* @param string $msgid [description]
|
||||
* @return string [description]
|
||||
*/
|
||||
public function pgettext($context, $msgid)
|
||||
public function pgettext(string $context, string $msgid): string
|
||||
{
|
||||
$key = $context . chr(4) . $msgid;
|
||||
$ret = $this->translate($key);
|
||||
@@ -482,14 +520,19 @@ class GetTextReader
|
||||
|
||||
/**
|
||||
* np get text
|
||||
*
|
||||
* @param string $context [description]
|
||||
* @param string $singular [description]
|
||||
* @param string $plural [description]
|
||||
* @param string $number [description]
|
||||
* @param int $number [description]
|
||||
* @return string [description]
|
||||
*/
|
||||
public function npgettext($context, $singular, $plural, $number)
|
||||
{
|
||||
public function npgettext(
|
||||
string $context,
|
||||
string $singular,
|
||||
string $plural,
|
||||
int $number
|
||||
): string {
|
||||
$key = $context . chr(4) . $singular;
|
||||
$ret = $this->ngettext($key, $plural, $number);
|
||||
if (strpos($ret, "\004") !== false) {
|
||||
|
||||
@@ -41,7 +41,7 @@ class StreamReader
|
||||
* @param int $bytes bytes to read
|
||||
* @return bool dummy false
|
||||
*/
|
||||
public function read($bytes)
|
||||
public function read(int $bytes): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -51,7 +51,7 @@ class StreamReader
|
||||
* @param int $position seek to position
|
||||
* @return bool dummy false
|
||||
*/
|
||||
public function seekto($position)
|
||||
public function seekto(int $position): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -60,7 +60,7 @@ class StreamReader
|
||||
* returns current position
|
||||
* @return bool dummy false
|
||||
*/
|
||||
public function currentpos()
|
||||
public function currentpos(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ class StreamReader
|
||||
* returns length of entire stream (limit for seekto()s)
|
||||
* @return bool dummy false
|
||||
*/
|
||||
public function length()
|
||||
public function length(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class StringReader
|
||||
* constructor for string reader
|
||||
* @param string $str basic string
|
||||
*/
|
||||
public function __construct($str = '')
|
||||
public function __construct(string $str = '')
|
||||
{
|
||||
$this->sr_str = $str;
|
||||
$this->sr_pos = 0;
|
||||
@@ -46,7 +46,7 @@ class StringReader
|
||||
* @param int $bytes bytes to read in string
|
||||
* @return string data read in length of bytes as string
|
||||
*/
|
||||
public function read($bytes)
|
||||
public function read(int $bytes): string
|
||||
{
|
||||
$data = substr($this->sr_str, $this->sr_pos, $bytes);
|
||||
$this->sr_pos += $bytes;
|
||||
@@ -62,7 +62,7 @@ class StringReader
|
||||
* @param int $pos position in string
|
||||
* @return int new position in string after seek
|
||||
*/
|
||||
public function seekto($pos)
|
||||
public function seekto(int $pos): int
|
||||
{
|
||||
$this->sr_pos = $pos;
|
||||
if (strlen($this->sr_str) < $this->sr_pos) {
|
||||
@@ -75,7 +75,7 @@ class StringReader
|
||||
* get current position in string
|
||||
* @return int position in string
|
||||
*/
|
||||
public function currentpos()
|
||||
public function currentpos(): int
|
||||
{
|
||||
return $this->sr_pos;
|
||||
}
|
||||
@@ -84,7 +84,7 @@ class StringReader
|
||||
* get length of string
|
||||
* @return int return length of assigned string
|
||||
*/
|
||||
public function length()
|
||||
public function length(): int
|
||||
{
|
||||
return strlen($this->sr_str);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* hash wrapper functions for old problem fixes
|
||||
* deprecated function calls
|
||||
* Language\Encoding::__mbMimeEncode -> Convert\MimeEncode::__mbMimeEncode
|
||||
* Langauge\Encoding::checkConvertEncoding -> Check\Encoding::checkConvertEncoding
|
||||
* Langauge\Encoding::setErrorChar -> Check\Encoding::setErrorChar
|
||||
* Langauge\Encoding::getErrorChar -> Encoding::getErrorChar
|
||||
* Langauge\Encoding::convertEncoding -> Convert\Encoding::convertEncoding
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
@@ -10,67 +15,59 @@ namespace CoreLibs\Language;
|
||||
|
||||
class Encoding
|
||||
{
|
||||
/** @var string */
|
||||
private static $mb_error_char = '';
|
||||
|
||||
/**
|
||||
* wrapper function for mb mime convert, for correct conversion with long strings
|
||||
* @param string $string string to encode
|
||||
* @param string $encoding target encoding
|
||||
* @return string encoded string
|
||||
* wrapper function for mb mime convert
|
||||
* for correct conversion with long strings
|
||||
*
|
||||
* @param string $string string to encode
|
||||
* @param string $encoding target encoding
|
||||
* @param string $line_break default line break is \r\n
|
||||
* @return string encoded string
|
||||
* @deprecated Use \CoreLibs\Convert\MimeEncode::__mbMimeEncode();
|
||||
*/
|
||||
public static function __mbMimeEncode(string $string, string $encoding): string
|
||||
{
|
||||
// set internal encoding, so the mimeheader encode works correctly
|
||||
mb_internal_encoding($encoding);
|
||||
// if a subject, make a work around for the broken mb_mimencode
|
||||
$pos = 0;
|
||||
$split = 36; // after 36 single bytes characters, if then comes MB, it is broken
|
||||
// has to 2 x 36 < 74 so the mb_encode_mimeheader 74 hardcoded split does not get triggered
|
||||
$_string = '';
|
||||
while ($pos < mb_strlen($string, $encoding)) {
|
||||
$output = mb_strimwidth($string, $pos, $split, "", $encoding);
|
||||
$pos += mb_strlen($output, $encoding);
|
||||
// if the strinlen is 0 here, get out of the loop
|
||||
if (!mb_strlen($output, $encoding)) {
|
||||
$pos += mb_strlen($string, $encoding);
|
||||
}
|
||||
$_string_encoded = mb_encode_mimeheader($output, $encoding);
|
||||
// only make linebreaks if we have mime encoded code inside
|
||||
// the space only belongs in the second line
|
||||
if ($_string && preg_match("/^=\?/", $_string_encoded)) {
|
||||
$_string .= "\n ";
|
||||
}
|
||||
$_string .= $_string_encoded;
|
||||
}
|
||||
// strip out any spaces BEFORE a line break
|
||||
$string = str_replace(" \n", "\n", $_string);
|
||||
return $string;
|
||||
public static function __mbMimeEncode(
|
||||
string $string,
|
||||
string $encoding,
|
||||
string $line_break = "\r\n"
|
||||
): string {
|
||||
return \CoreLibs\Convert\MimeEncode::__mbMimeEncode($string, $encoding, $line_break);
|
||||
}
|
||||
|
||||
/**
|
||||
* set error char
|
||||
*
|
||||
* @param string $string The character to use to represent error chars
|
||||
* @param string|int|null $string The character to use to represent
|
||||
* error chars
|
||||
* "long" for long, "none" for none
|
||||
* or a valid code point in int
|
||||
* like 0x2234 (8756, ∴)
|
||||
* default character is ? (63)
|
||||
* if null is set then "none"
|
||||
* @return void
|
||||
* @deprecated Use \CoreLibs\Check\Encoding::setErrorChar();
|
||||
*/
|
||||
public static function setErrorChar(string $string): void
|
||||
public static function setErrorChar($string): void
|
||||
{
|
||||
self::$mb_error_char = $string;
|
||||
\CoreLibs\Check\Encoding::setErrorChar($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the current set error character
|
||||
*
|
||||
* @return string Set error character
|
||||
* @param bool $return_substitute_func if set to true return the set
|
||||
* character from the php function
|
||||
* directly
|
||||
* @return string|int Set error character
|
||||
* @deprecated Use \CoreLibs\Check\Encoding::getErrorChar();
|
||||
*/
|
||||
public static function getErrorChar(): string
|
||||
public static function getErrorChar(bool $return_substitute_func = false)
|
||||
{
|
||||
return self::$mb_error_char;
|
||||
return \CoreLibs\Check\Encoding::getErrorChar($return_substitute_func);
|
||||
}
|
||||
|
||||
/**
|
||||
* test if a string can be safely convert between encodings. mostly utf8 to shift jis
|
||||
* test if a string can be safely convert between encodings.
|
||||
* mostly utf8 to shift jis
|
||||
* the default compare has a possibility of failure, especially with windows
|
||||
* it is recommended to the following in the script which uses this method:
|
||||
* mb_substitute_character(0x2234);
|
||||
@@ -80,36 +77,20 @@ class Encoding
|
||||
* if check to ISO-2022-JP-MS
|
||||
* set three dots (∴) as wrong character for correct convert error detect
|
||||
* (this char is used, because it is one of the least used ones)
|
||||
*
|
||||
* @param string $string string to test
|
||||
* @param string $from_encoding encoding of string to test
|
||||
* @param string $to_encoding target encoding
|
||||
* @return bool|array<string> false if no error or array with failed characters
|
||||
* @return bool|array<string> false if no error or
|
||||
* array with failed characters
|
||||
* @deprecated Use \CoreLibs\Check\Encoding::checkConvertEncoding();
|
||||
*/
|
||||
public static function checkConvertEncoding(string $string, string $from_encoding, string $to_encoding)
|
||||
{
|
||||
// convert to target encoding and convert back
|
||||
$temp = mb_convert_encoding($string, $to_encoding, $from_encoding);
|
||||
$compare = mb_convert_encoding($temp, $from_encoding, $to_encoding);
|
||||
// if string does not match anymore we have a convert problem
|
||||
if ($string != $compare) {
|
||||
$failed = [];
|
||||
// go through each character and find the ones that do not match
|
||||
for ($i = 0, $iMax = mb_strlen($string, $from_encoding); $i < $iMax; $i++) {
|
||||
$char = mb_substr($string, $i, 1, $from_encoding);
|
||||
$r_char = mb_substr($compare, $i, 1, $from_encoding);
|
||||
// the ord 194 is a hack to fix the IE7/IE8 bug with line break and illegal character
|
||||
if (
|
||||
(($char != $r_char && !self::$mb_error_char) ||
|
||||
($char != $r_char && $r_char == self::$mb_error_char && self::$mb_error_char)) &&
|
||||
ord($char) != 194
|
||||
) {
|
||||
$failed[] = $char;
|
||||
}
|
||||
}
|
||||
return $failed;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
public static function checkConvertEncoding(
|
||||
string $string,
|
||||
string $from_encoding,
|
||||
string $to_encoding
|
||||
) {
|
||||
return \CoreLibs\Check\Encoding::checkConvertEncoding($string, $from_encoding, $to_encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,6 +99,7 @@ class Encoding
|
||||
* if source encoding is set and auto check is true (default) a second
|
||||
* check is done so that the source string encoding actually matches
|
||||
* will be skipped if source encoding detection is ascii
|
||||
*
|
||||
* @param string $string string to convert
|
||||
* @param string $to_encoding target encoding
|
||||
* @param string $source_encoding optional source encoding, will try to auto detect
|
||||
@@ -125,6 +107,7 @@ class Encoding
|
||||
* check that the source is actually matching
|
||||
* to what we sav the source is
|
||||
* @return string encoding converted string
|
||||
* @deprecated Use \CoreLibs\Convert\Encoding::convertEncoding();
|
||||
*/
|
||||
public static function convertEncoding(
|
||||
string $string,
|
||||
@@ -132,28 +115,12 @@ class Encoding
|
||||
string $source_encoding = '',
|
||||
bool $auto_check = true
|
||||
): string {
|
||||
// set if not given
|
||||
if (!$source_encoding) {
|
||||
$source_encoding = mb_detect_encoding($string);
|
||||
} else {
|
||||
$_source_encoding = mb_detect_encoding($string);
|
||||
}
|
||||
if (
|
||||
$auto_check === true &&
|
||||
isset($_source_encoding) &&
|
||||
$_source_encoding == $source_encoding
|
||||
) {
|
||||
// trigger check if we have override source encoding.
|
||||
// if different (_source is all but not ascii) then trigger skip if matching
|
||||
}
|
||||
if ($source_encoding != $to_encoding) {
|
||||
if ($source_encoding) {
|
||||
$string = mb_convert_encoding($string, $to_encoding, $source_encoding);
|
||||
} else {
|
||||
$string = mb_convert_encoding($string, $to_encoding);
|
||||
}
|
||||
}
|
||||
return $string;
|
||||
return \CoreLibs\Convert\Encoding::convertEncoding(
|
||||
$string,
|
||||
$to_encoding,
|
||||
$source_encoding,
|
||||
$auto_check
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,38 +13,55 @@ class GetSettings
|
||||
/**
|
||||
* Sets encoding and language
|
||||
* Can be overridden with language + path to mo file
|
||||
* If language is set it must be in the format of:
|
||||
* If locale is set it must be in the format of:
|
||||
* <lang>.<encoding>
|
||||
* <lang>_<country>.<encoding>
|
||||
* <lang>_<country>@<subset>.<encoding>
|
||||
* <lang>_<country>.<encoding>@<subset>
|
||||
* If no encoding is set in the is, UTF-8 is assumed
|
||||
*
|
||||
* @param string|null $language
|
||||
* @param string|null $path
|
||||
* @return array
|
||||
* 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 $language = null,
|
||||
?string $locale = null,
|
||||
?string $domain = null,
|
||||
?string $path = null
|
||||
): array {
|
||||
$lang = '';
|
||||
$lang_short = '';
|
||||
$encoding = '';
|
||||
// if language is set, extract
|
||||
if (!empty($language)) {
|
||||
// if is is set, extract
|
||||
if (!empty($locale)) {
|
||||
preg_match(
|
||||
"/^(([a-z]{2,})(_[A-Z]{2,})?(@[a-z]{1,})?)(\.([\w-])+)?$/",
|
||||
$language,
|
||||
// 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
|
||||
);
|
||||
// 1: lang (always)
|
||||
$lang = $matches[1] ?? '';
|
||||
// 2: lang short part
|
||||
$lang_short = $matches[2] ?? '';
|
||||
// 3: [ignore] sub part, if set, combined with lang
|
||||
// 4: [ignore] possible sub part, combined with lang in 1
|
||||
// 6: encoding if set
|
||||
$encoding = $matches[5] ?? '';
|
||||
// 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 (
|
||||
|
||||
@@ -40,104 +40,530 @@ use CoreLibs\Language\Core\GetTextReader;
|
||||
|
||||
class L10n
|
||||
{
|
||||
/** @var string */
|
||||
private $lang = '';
|
||||
/** @var string */
|
||||
/** @var string the current locale */
|
||||
private $locale = '';
|
||||
/** @var string the default selected/active domain */
|
||||
private $domain = '';
|
||||
/** @var array<string,array<string,GetTextReader>> locale > domain = translator */
|
||||
private $domains = [];
|
||||
/** @var array<string,string> bound paths for domains */
|
||||
private $paths = ['' => './'];
|
||||
/** @var string the full path to the mo file to loaded */
|
||||
private $mofile = '';
|
||||
/** @var FileReader|bool */
|
||||
private $input;
|
||||
/** @var GetTextReader */
|
||||
/** @var string base path to search level */
|
||||
private $base_locale_path = '';
|
||||
/** @var string dynamic set path to where the mo file is actually */
|
||||
private $base_content_path = '';
|
||||
/** @var bool if load of mo file was unsuccessful */
|
||||
private $load_failure = false;
|
||||
|
||||
/** @var FileReader|bool reader class for file reading, false for short circuit */
|
||||
private $input = false;
|
||||
/** @var GetTextReader reader class for MO data */
|
||||
private $l10n;
|
||||
/**
|
||||
* @static
|
||||
* @var L10n self class
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* class constructor call for language getstring
|
||||
* @param string $lang language name (optional), fallback is en
|
||||
* @param string $path path, if empty fallback on default internal path
|
||||
* if locale is not empty will load translation
|
||||
* else getTranslator needs to be called
|
||||
*
|
||||
* @param string $locale language name, default empty string
|
||||
* will return self instance
|
||||
* @param string $path path, if empty fallback on default internal path
|
||||
* @param string $domain override CONTENT_PATH . $encoding name for mo file
|
||||
* @param bool $legacy default true, if set to true, will look in the old
|
||||
* folder format lang/ CONTENT_PATH / $lang . mo
|
||||
*/
|
||||
public function __construct(string $lang = '', string $path = '')
|
||||
{
|
||||
if (!$lang) {
|
||||
$this->lang = 'en';
|
||||
} else {
|
||||
$this->lang = $lang;
|
||||
public function __construct(
|
||||
string $locale = '',
|
||||
string $path = '',
|
||||
string $domain = '',
|
||||
bool $legacy = true
|
||||
) {
|
||||
// load the mo file if locale is not empty
|
||||
if (!empty($locale)) {
|
||||
$this->getTranslator($locale, $path, $domain, $legacy);
|
||||
}
|
||||
|
||||
// override path check
|
||||
if (!is_dir($path)) {
|
||||
$path = BASE . INCLUDES . LANG . CONTENT_PATH;
|
||||
}
|
||||
|
||||
$this->mofile = $path . $this->lang . ".mo";
|
||||
|
||||
// check if get a readable mofile
|
||||
if (is_readable($this->mofile)) {
|
||||
$this->input = new FileReader($this->mofile);
|
||||
} else {
|
||||
$this->input = false;
|
||||
}
|
||||
$this->l10n = new GetTextReader($this->input);
|
||||
}
|
||||
|
||||
/**
|
||||
* reloads the mofile, if the location of the lang file changes
|
||||
* @param string $lang language to reload data
|
||||
* @param string $path optional path, if not set fallback on internal
|
||||
* @return bool successfull reload true/false
|
||||
* Returns the singleton L10n object.
|
||||
* For function wrapper use
|
||||
*
|
||||
* @return L10n object
|
||||
*/
|
||||
public function l10nReloadMOfile(string $lang, string $path = ''): bool
|
||||
public static function getInstance(): L10n
|
||||
{
|
||||
$success = false;
|
||||
$old_mofile = $this->mofile;
|
||||
$old_lang = $this->lang;
|
||||
|
||||
$this->lang = $lang;
|
||||
|
||||
// override path check
|
||||
if (!is_dir($path)) {
|
||||
$path = BASE . INCLUDES . LANG . CONTENT_PATH;
|
||||
/** @phpstan-ignore-next-line */
|
||||
if (empty(self::$instance)) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
$this->mofile = $path . $this->lang . ".mo";
|
||||
/**
|
||||
* Loads global localization functions.
|
||||
* prefixed with double underscore
|
||||
* eg: gettext -> __gettext
|
||||
*/
|
||||
public static function loadFunctions(): void
|
||||
{
|
||||
require_once __DIR__ . '/l10n_functions.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* legacy loader name for getTranslator
|
||||
* instead of returning the GetTextReader object it returns
|
||||
* true or false for successful load.
|
||||
* NOTE: some time down the road this will be deprecated
|
||||
*
|
||||
* @param string $locale
|
||||
* @param string $path
|
||||
* @param string $domain
|
||||
* @param bool $legacy
|
||||
* @return bool Returns true for successfull load, false for error
|
||||
*/
|
||||
public function l10nReloadMOfile(
|
||||
string $locale,
|
||||
string $path = '',
|
||||
string $domain = '',
|
||||
bool $legacy = true
|
||||
): bool {
|
||||
$this->getTranslator($locale, $path, $domain, $legacy);
|
||||
return $this->load_failure ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* loads the mo file base on path, locale and domain set
|
||||
*
|
||||
* @param string $locale language name (optional), fallback is en
|
||||
* @param string $path path, if empty fallback on default internal path
|
||||
* @param string $domain override CONTENT_PATH . $encoding name for mo file
|
||||
* @param bool $legacy default true, if set to true, will look in the old
|
||||
* folder format lang/ CONTENT_PATH / $lang . mo
|
||||
* @return GetTextReader the main gettext reader object
|
||||
*/
|
||||
public function getTranslator(
|
||||
string $locale = '',
|
||||
string $path = '',
|
||||
string $domain = '',
|
||||
bool $legacy = false
|
||||
): GetTextReader {
|
||||
// set local if not from parameter
|
||||
if (empty($locale)) {
|
||||
$locale = $this->locale;
|
||||
}
|
||||
// set domain if not given
|
||||
if (empty($domain)) {
|
||||
$domain = $this->domain;
|
||||
}
|
||||
// store old settings
|
||||
$old_mofile = $this->mofile;
|
||||
$old_lang = $this->locale;
|
||||
$old_domain = $this->domain;
|
||||
$old_base_locale_path = $this->base_locale_path;
|
||||
$old_base_content_path = $this->base_content_path;
|
||||
|
||||
// legacy or new type
|
||||
// legacy will use the old lang/content/file.mo type as default
|
||||
// if path is not set, also locale is the file name
|
||||
// for new type it follows the gettext spec and path is just the
|
||||
// base folder where the mo files will be searched
|
||||
if ($legacy === true) {
|
||||
if (!is_dir($path)) {
|
||||
$this->base_locale_path = BASE . INCLUDES . LANG;
|
||||
$this->base_content_path = CONTENT_PATH;
|
||||
$path = $this->base_locale_path . $this->base_content_path;
|
||||
}
|
||||
$this->mofile = $path . $locale . ".mo";
|
||||
} else {
|
||||
// if new path is a dir
|
||||
// 1) from a previous set domain
|
||||
// 2) from method option as is
|
||||
// 3) fallback if BASE/INCLUDES/LOCALE set
|
||||
// 4) current dir
|
||||
if (!empty($this->paths[$domain]) && is_dir($this->paths[$domain])) {
|
||||
$this->base_locale_path = $this->paths[$domain];
|
||||
} elseif (is_dir($path)) {
|
||||
$this->base_locale_path = $path;
|
||||
} elseif (
|
||||
defined('BASE') && defined('INCLUDES') && defined('LOCALE')
|
||||
) {
|
||||
// set fallback base path if constant set
|
||||
$this->base_locale_path = BASE . INCLUDES . LOCALE;
|
||||
} else {
|
||||
$this->base_locale_path = './';
|
||||
}
|
||||
// now we loop over lang compositions to get the base path
|
||||
// then we check
|
||||
$locales = $this->listLocales($locale);
|
||||
foreach ($locales as $_locale) {
|
||||
$this->base_content_path = $_locale . DIRECTORY_SEPARATOR
|
||||
. 'LC_MESSAGES' . DIRECTORY_SEPARATOR;
|
||||
$this->mofile = $this->base_locale_path
|
||||
. $this->base_content_path
|
||||
. $domain . '.mo';
|
||||
if (file_exists($this->mofile)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check if get a readable mofile
|
||||
if (is_readable($this->mofile)) {
|
||||
// locale and domain current wanted
|
||||
$this->locale = $locale;
|
||||
$this->domain = $domain;
|
||||
// set empty domains path with current locale
|
||||
if (empty($this->domains[$locale])) {
|
||||
$this->domains[$locale] = [];
|
||||
}
|
||||
// store current base path (without locale, etc)
|
||||
if (empty($this->paths[$domain])) {
|
||||
$this->paths[$domain] = $this->base_locale_path;
|
||||
}
|
||||
// file reader and mo reader
|
||||
$this->input = new FileReader($this->mofile);
|
||||
$this->l10n = new GetTextReader($this->input);
|
||||
// we successfully loaded
|
||||
$success = true;
|
||||
} else {
|
||||
// if short circuit is true, we failed to have a translator loaded
|
||||
$this->load_failure = $this->l10n->getShortCircuit();
|
||||
// below is not used at the moment, but can be to avoid reloading
|
||||
$this->domains[$this->locale][$domain] = $this->l10n;
|
||||
} elseif (!empty($old_mofile)) {
|
||||
// mo file not readable
|
||||
$this->load_failure = true;
|
||||
// else fall back to the old ones
|
||||
$this->mofile = $old_mofile;
|
||||
$this->lang = $old_lang;
|
||||
$this->locale = $old_lang;
|
||||
$this->domain = $old_domain;
|
||||
$this->base_locale_path = $old_base_locale_path;
|
||||
$this->base_content_path = $old_base_content_path;
|
||||
} else {
|
||||
// mo file not readable, no previous mo file set, set short circuit
|
||||
$this->load_failure = true;
|
||||
// dummy
|
||||
$this->l10n = new GetTextReader($this->input);
|
||||
}
|
||||
return $success;
|
||||
return $this->l10n;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* return current set GetTextReader or return the one for given
|
||||
* domain name if set
|
||||
* This can be used to access all the public methods from the
|
||||
* GetTextReader
|
||||
*
|
||||
* @param string $domain optional domain name
|
||||
* @return GetTextReader
|
||||
*/
|
||||
public function getTranslatorClass(string $domain = ''): GetTextReader
|
||||
{
|
||||
if (!empty($domain) && !empty($this->domains[$this->locale][$domain])) {
|
||||
return $this->domains[$this->locale][$domain];
|
||||
}
|
||||
// if null return short circuit version
|
||||
if ($this->l10n === null) {
|
||||
return new GetTextReader($this->input);
|
||||
}
|
||||
return $this->l10n;
|
||||
}
|
||||
|
||||
/**
|
||||
* original:
|
||||
* vendor/phpmyadmin/motranslator/src/Loader.php
|
||||
*
|
||||
* Returns array with all possible locale combinations based on the
|
||||
* given locale name
|
||||
*
|
||||
* I.e. for sr_CS.UTF-8@latin, look through all of
|
||||
* sr_CS.UTF-8@latin, sr_CS@latin, sr@latin, sr_CS.UTF-8, sr_CS, sr.
|
||||
*
|
||||
* @param string $locale Locale string
|
||||
* @return array<string> List of locale path parts that can be possible
|
||||
*/
|
||||
public static function listLocales(string $locale): array
|
||||
{
|
||||
$locale_list = [];
|
||||
|
||||
if (empty($locale)) {
|
||||
return $locale_list;
|
||||
}
|
||||
// is matching regex
|
||||
if (
|
||||
!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
|
||||
)
|
||||
) {
|
||||
// not matching, return as is
|
||||
return [$locale];
|
||||
}
|
||||
// do matching run
|
||||
$lang = $matches['lang'] ?? null;
|
||||
$country = $matches['country'] ?? null;
|
||||
$charset = $matches['charset'] ?? null;
|
||||
$modifier = $matches['modifier'] ?? null;
|
||||
// we need to add all possible cominations from not null set
|
||||
// entries to the list, from longest to shortest
|
||||
// %s_%s.%s@%s (lang _ country . encoding @ suffix)
|
||||
// %s_%s@%s (lang _ country @ suffix)
|
||||
// %s@%s (lang @ suffix)
|
||||
// %s_%s.%s (lang _ country . encoding)
|
||||
// %s_%s (lang _ country)
|
||||
// %s (lang)
|
||||
|
||||
// if lang is set
|
||||
if ($lang) {
|
||||
// modifier group
|
||||
if ($modifier) {
|
||||
if ($country) {
|
||||
if ($charset) {
|
||||
array_push(
|
||||
$locale_list,
|
||||
sprintf('%s_%s.%s@%s', $lang, $country, $charset, $modifier)
|
||||
);
|
||||
}
|
||||
|
||||
array_push(
|
||||
$locale_list,
|
||||
sprintf('%s_%s@%s', $lang, $country, $modifier)
|
||||
);
|
||||
} elseif ($charset) {
|
||||
array_push(
|
||||
$locale_list,
|
||||
sprintf('%s.%s@%s', $lang, $charset, $modifier)
|
||||
);
|
||||
}
|
||||
|
||||
array_push(
|
||||
$locale_list,
|
||||
sprintf('%s@%s', $lang, $modifier)
|
||||
);
|
||||
}
|
||||
// country group
|
||||
if ($country) {
|
||||
if ($charset) {
|
||||
array_push(
|
||||
$locale_list,
|
||||
sprintf('%s_%s.%s', $lang, $country, $charset)
|
||||
);
|
||||
}
|
||||
|
||||
array_push(
|
||||
$locale_list,
|
||||
sprintf('%s_%s', $lang, $country)
|
||||
);
|
||||
} elseif ($charset) {
|
||||
array_push(
|
||||
$locale_list,
|
||||
sprintf('%s.%s', $lang, $charset)
|
||||
);
|
||||
}
|
||||
// lang only
|
||||
array_push($locale_list, $lang);
|
||||
}
|
||||
|
||||
// If the locale name doesn't match POSIX style, just include it as-is.
|
||||
if (!in_array($locale, $locale_list)) {
|
||||
array_push($locale_list, $locale);
|
||||
}
|
||||
|
||||
return $locale_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* tries to detect the locale set in the following order:
|
||||
* - globals: LOCALE
|
||||
* - globals: LANG
|
||||
* - env: LC_ALL
|
||||
* - env: LC_MESSAGES
|
||||
* - env: LANG
|
||||
* if nothing set, returns 'en' as default
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function detectLocale(): string
|
||||
{
|
||||
// globals
|
||||
foreach (['LOCALE', 'LANG'] as $global) {
|
||||
if (!empty($GLOBALS[$global])) {
|
||||
return $GLOBALS[$global];
|
||||
}
|
||||
}
|
||||
// enviroment
|
||||
foreach (['LC_ALL', 'LC_MESSAGES', 'LANG'] as $env) {
|
||||
$locale = getenv($env);
|
||||
if ($locale !== false && !empty($locale)) {
|
||||
return $locale;
|
||||
}
|
||||
}
|
||||
return 'en';
|
||||
}
|
||||
|
||||
/************
|
||||
* INTERNAL VAR SET/GET
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sets the path for a domain.
|
||||
* must be set before running l10nReloadMOfile
|
||||
*
|
||||
* @param string $domain Domain name
|
||||
* @param string $path Path where to find locales
|
||||
*/
|
||||
public function setTextDomain(string $domain, string $path): void
|
||||
{
|
||||
$this->paths[$domain] = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* return set path for given domain
|
||||
* if not found return false
|
||||
*
|
||||
* @param string $domain
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getTextDomain(string $domain)
|
||||
{
|
||||
return $this->paths[$domain] ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the default domain.
|
||||
*
|
||||
* @param string $domain Domain name
|
||||
*/
|
||||
public function setDomain(string $domain): void
|
||||
{
|
||||
$this->domain = $domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* return current set domain name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDomain(): string
|
||||
{
|
||||
return $this->domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets a requested locale.
|
||||
*
|
||||
* @param string $locale Locale name
|
||||
* @return string Set or current locale
|
||||
*/
|
||||
public function setLocale(string $locale): string
|
||||
{
|
||||
if (!empty($locale)) {
|
||||
$this->locale = $locale;
|
||||
}
|
||||
return $this->locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* get current set locale
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocale(): string
|
||||
{
|
||||
return $this->locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* get current set language
|
||||
*
|
||||
* @return string current set language string
|
||||
* @deprecated Use getLocale()
|
||||
*/
|
||||
public function __getLang(): string
|
||||
{
|
||||
return $this->lang;
|
||||
return $this->getLocale();
|
||||
}
|
||||
|
||||
/**
|
||||
* get current set mo file
|
||||
*
|
||||
* @return string current set mo language file
|
||||
*/
|
||||
public function __getMoFile(): string
|
||||
public function getMoFile(): string
|
||||
{
|
||||
return $this->mofile;
|
||||
}
|
||||
|
||||
/**
|
||||
* get current set mo file
|
||||
*
|
||||
* @return string current set mo language file
|
||||
* @deprecated Use getMoFile()
|
||||
*/
|
||||
public function __getMoFile(): string
|
||||
{
|
||||
return $this->getMoFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* get the current base path in which we search
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBaseLocalePath(): string
|
||||
{
|
||||
return $this->base_locale_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* the path below the base path to where the mo file is located
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBaseContentPath(): string
|
||||
{
|
||||
return $this->base_content_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the current load error status
|
||||
* if true then the mo file failed to load
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getLoadError(): bool
|
||||
{
|
||||
return $this->load_failure;
|
||||
}
|
||||
|
||||
/************
|
||||
* TRANSLATION METHODS
|
||||
*/
|
||||
|
||||
/**
|
||||
* translates a string and returns translated text
|
||||
*
|
||||
* @param string $text text to translate
|
||||
* @return string translated text
|
||||
*/
|
||||
public function __(string $text): string
|
||||
{
|
||||
// fallback passthrough
|
||||
if ($this->l10n === null) {
|
||||
return $text;
|
||||
}
|
||||
return $this->l10n->translate($text);
|
||||
}
|
||||
|
||||
@@ -145,32 +571,75 @@ class L10n
|
||||
* prints translated string out to the screen
|
||||
* @param string $text text to translate
|
||||
* @return void has no return
|
||||
* @deprecated use echo __() instead
|
||||
*/
|
||||
public function __e(string $text): void
|
||||
{
|
||||
// fallback passthrough
|
||||
if ($this->l10n === null) {
|
||||
echo $text;
|
||||
}
|
||||
echo $this->l10n->translate($text);
|
||||
}
|
||||
|
||||
// Return the plural form.
|
||||
/**
|
||||
* Return the plural form.
|
||||
* @param string $single string for single word
|
||||
* @param string $plural string for plural word
|
||||
* @param int|float $number number value
|
||||
* @return string translated plural string
|
||||
*
|
||||
* @param string $single string for single word
|
||||
* @param string $plural string for plural word
|
||||
* @param int $number number value
|
||||
* @return string translated plural string
|
||||
*/
|
||||
public function __n(string $single, string $plural, $number): string
|
||||
public function __n(string $single, string $plural, int $number): string
|
||||
{
|
||||
// in case nothing got set yet, this is fallback
|
||||
if ($this->l10n === null) {
|
||||
return $number > 1 ? $plural : $single;
|
||||
}
|
||||
return $this->l10n->ngettext($single, $plural, $number);
|
||||
}
|
||||
|
||||
/**
|
||||
* context translation via msgctxt
|
||||
*
|
||||
* @param string $context context string
|
||||
* @param string $text text to translate
|
||||
* @return string
|
||||
*/
|
||||
public function __p(string $context, string $text): string
|
||||
{
|
||||
if ($this->l10n === null) {
|
||||
return $text;
|
||||
}
|
||||
return $this->l10n->pgettext($context, $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* context translation via msgctxt
|
||||
*
|
||||
* @param string $context context string
|
||||
* @param string $single string for single word
|
||||
* @param string $plural string for plural word
|
||||
* @param int $number number value
|
||||
* @return string
|
||||
*/
|
||||
public function __pn(string $context, string $single, string $plural, int $number): string
|
||||
{
|
||||
if ($this->l10n === null) {
|
||||
return $number > 1 ? $plural : $single;
|
||||
}
|
||||
return $this->l10n->npgettext($context, $single, $plural, $number);
|
||||
}
|
||||
|
||||
// alias functions to mimic gettext calls
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* alias for gettext,
|
||||
* calls __
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
* @deprecated Use __()
|
||||
*/
|
||||
public function gettext(string $text): string
|
||||
{
|
||||
@@ -178,22 +647,24 @@ class L10n
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* alias for ngettext
|
||||
* calls __n
|
||||
*
|
||||
* @param string $single
|
||||
* @param string $plural
|
||||
* @param int|float $number
|
||||
* @param int $number
|
||||
* @return string
|
||||
* @deprecated Use __n()
|
||||
*/
|
||||
public function ngettext(string $single, string $plural, $number): string
|
||||
public function ngettext(string $single, string $plural, int $number): string
|
||||
{
|
||||
return $this->__n($single, $plural, $number);
|
||||
}
|
||||
|
||||
// TODO: dgettext(string $domain, string $message): string
|
||||
// TODO: dngettext(string $domain, string $singular, string $plural, int $count): string
|
||||
// TODO: dcgettext(string $domain, string $message, int $category): string
|
||||
// TODO: dcngettext(string $domain, string $singular, string $plural, int $count, int $category): string
|
||||
// TODO: dpgettext(string $domain, string $message, int $category): string
|
||||
// TODO: dpngettext(string $domain, string $singular, string $plural, int $count, int $category): string
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
208
www/lib/CoreLibs/Language/l10n_functions.php
Normal file
208
www/lib/CoreLibs/Language/l10n_functions.php
Normal file
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use CoreLibs\Language\L10n;
|
||||
|
||||
/**
|
||||
* Sets a requested locale.
|
||||
*
|
||||
* @param int $category Locale category, ignored
|
||||
* @param string $locale Locale name
|
||||
*
|
||||
* @return string Set or current locale
|
||||
*/
|
||||
function __setlocale(int $category, string $locale): string
|
||||
{
|
||||
return L10n::getInstance()->setLocale($locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the path for a domain.
|
||||
*
|
||||
* @param string $domain Domain name
|
||||
* @param string $path Path where to find locales
|
||||
*/
|
||||
function __bindtextdomain(string $domain, string $path): void
|
||||
{
|
||||
L10n::getInstance()->setTextDomain($domain, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy compatibility function, MoTranslator assumes
|
||||
* everything is using same character set on input and
|
||||
* output.
|
||||
*
|
||||
* Generally it is wise to output in UTF-8 and have
|
||||
* mo files in UTF-8.
|
||||
*
|
||||
* @param string $domain Domain where to set character set
|
||||
* @param string $codeset Character set to set
|
||||
*/
|
||||
function __bind_textdomain_codeset(string $domain, string $codeset): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default domain.
|
||||
*
|
||||
* @param string $domain Domain name
|
||||
*/
|
||||
function __textdomain(string $domain): void
|
||||
{
|
||||
L10n::getInstance()->setDomain($domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a string.
|
||||
*
|
||||
* @param string $msgid String to be translated
|
||||
*
|
||||
* @return string translated string (or original, if not found)
|
||||
*/
|
||||
function __gettext(string $msgid): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator()->gettext(
|
||||
$msgid
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a string, alias for _gettext.
|
||||
*
|
||||
* @param string $msgid String to be translated
|
||||
*
|
||||
* @return string translated string (or original, if not found)
|
||||
*/
|
||||
function __(string $msgid): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator()->gettext(
|
||||
$msgid
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plural version of gettext.
|
||||
*
|
||||
* @param string $msgid Single form
|
||||
* @param string $msgidPlural Plural form
|
||||
* @param int $number Number of objects
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function __ngettext(string $msgid, string $msgidPlural, int $number): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator()->ngettext(
|
||||
$msgid,
|
||||
$msgidPlural,
|
||||
$number
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate with context.
|
||||
*
|
||||
* @param string $msgctxt Context
|
||||
* @param string $msgid String to be translated
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function __pgettext(string $msgctxt, string $msgid): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator()->pgettext(
|
||||
$msgctxt,
|
||||
$msgid
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plural version of pgettext.
|
||||
*
|
||||
* @param string $msgctxt Context
|
||||
* @param string $msgid Single form
|
||||
* @param string $msgidPlural Plural form
|
||||
* @param int $number Number of objects
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function __npgettext(string $msgctxt, string $msgid, string $msgidPlural, int $number): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator()->npgettext(
|
||||
$msgctxt,
|
||||
$msgid,
|
||||
$msgidPlural,
|
||||
$number
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a string.
|
||||
*
|
||||
* @param string $domain Domain to use
|
||||
* @param string $msgid String to be translated
|
||||
*
|
||||
* @return string translated string (or original, if not found)
|
||||
*/
|
||||
function __dgettext(string $domain, string $msgid): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator('', '', $domain)->gettext(
|
||||
$msgid
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plural version of gettext.
|
||||
*
|
||||
* @param string $domain Domain to use
|
||||
* @param string $msgid Single form
|
||||
* @param string $msgidPlural Plural form
|
||||
* @param int $number Number of objects
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function __dngettext(string $domain, string $msgid, string $msgidPlural, int $number): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator('', '', $domain)->ngettext(
|
||||
$msgid,
|
||||
$msgidPlural,
|
||||
$number
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate with context.
|
||||
*
|
||||
* @param string $domain Domain to use
|
||||
* @param string $msgctxt Context
|
||||
* @param string $msgid String to be translated
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function __dpgettext(string $domain, string $msgctxt, string $msgid): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator('', '', $domain)->pgettext(
|
||||
$msgctxt,
|
||||
$msgid
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plural version of pgettext.
|
||||
*
|
||||
* @param string $domain Domain to use
|
||||
* @param string $msgctxt Context
|
||||
* @param string $msgid Single form
|
||||
* @param string $msgidPlural Plural form
|
||||
* @param int $number Number of objects
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function __dnpgettext(string $domain, string $msgctxt, string $msgid, string $msgidPlural, int $number): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator('', '', $domain)->npgettext(
|
||||
$msgctxt,
|
||||
$msgid,
|
||||
$msgidPlural,
|
||||
$number
|
||||
);
|
||||
}
|
||||
3
www/vendor/composer/autoload_classmap.php
vendored
3
www/vendor/composer/autoload_classmap.php
vendored
@@ -12,6 +12,7 @@ return array(
|
||||
'CoreLibs\\Admin\\Backend' => $baseDir . '/lib/CoreLibs/Admin/Backend.php',
|
||||
'CoreLibs\\Basic' => $baseDir . '/lib/CoreLibs/Basic.php',
|
||||
'CoreLibs\\Check\\Email' => $baseDir . '/lib/CoreLibs/Check/Email.php',
|
||||
'CoreLibs\\Check\\Encoding' => $baseDir . '/lib/CoreLibs/Check/Encoding.php',
|
||||
'CoreLibs\\Check\\File' => $baseDir . '/lib/CoreLibs/Check/File.php',
|
||||
'CoreLibs\\Check\\Jason' => $baseDir . '/lib/CoreLibs/Check/Jason.php',
|
||||
'CoreLibs\\Check\\Password' => $baseDir . '/lib/CoreLibs/Check/Password.php',
|
||||
@@ -20,10 +21,12 @@ return array(
|
||||
'CoreLibs\\Combined\\DateTime' => $baseDir . '/lib/CoreLibs/Combined/DateTime.php',
|
||||
'CoreLibs\\Convert\\Byte' => $baseDir . '/lib/CoreLibs/Convert/Byte.php',
|
||||
'CoreLibs\\Convert\\Colors' => $baseDir . '/lib/CoreLibs/Convert/Colors.php',
|
||||
'CoreLibs\\Convert\\Encoding' => $baseDir . '/lib/CoreLibs/Convert/Encoding.php',
|
||||
'CoreLibs\\Convert\\Html' => $baseDir . '/lib/CoreLibs/Convert/Html.php',
|
||||
'CoreLibs\\Convert\\Json' => $baseDir . '/lib/CoreLibs/Convert/Json.php',
|
||||
'CoreLibs\\Convert\\Math' => $baseDir . '/lib/CoreLibs/Convert/Math.php',
|
||||
'CoreLibs\\Convert\\MimeAppName' => $baseDir . '/lib/CoreLibs/Convert/MimeAppName.php',
|
||||
'CoreLibs\\Convert\\MimeEncode' => $baseDir . '/lib/CoreLibs/Convert/MimeEncode.php',
|
||||
'CoreLibs\\Create\\Hash' => $baseDir . '/lib/CoreLibs/Create/Hash.php',
|
||||
'CoreLibs\\Create\\RandomKey' => $baseDir . '/lib/CoreLibs/Create/RandomKey.php',
|
||||
'CoreLibs\\Create\\Session' => $baseDir . '/lib/CoreLibs/Create/Session.php',
|
||||
|
||||
3
www/vendor/composer/autoload_static.php
vendored
3
www/vendor/composer/autoload_static.php
vendored
@@ -77,6 +77,7 @@ class ComposerStaticInit10fe8fe2ec4017b8644d2b64bcf398b9
|
||||
'CoreLibs\\Admin\\Backend' => __DIR__ . '/../..' . '/lib/CoreLibs/Admin/Backend.php',
|
||||
'CoreLibs\\Basic' => __DIR__ . '/../..' . '/lib/CoreLibs/Basic.php',
|
||||
'CoreLibs\\Check\\Email' => __DIR__ . '/../..' . '/lib/CoreLibs/Check/Email.php',
|
||||
'CoreLibs\\Check\\Encoding' => __DIR__ . '/../..' . '/lib/CoreLibs/Check/Encoding.php',
|
||||
'CoreLibs\\Check\\File' => __DIR__ . '/../..' . '/lib/CoreLibs/Check/File.php',
|
||||
'CoreLibs\\Check\\Jason' => __DIR__ . '/../..' . '/lib/CoreLibs/Check/Jason.php',
|
||||
'CoreLibs\\Check\\Password' => __DIR__ . '/../..' . '/lib/CoreLibs/Check/Password.php',
|
||||
@@ -85,10 +86,12 @@ class ComposerStaticInit10fe8fe2ec4017b8644d2b64bcf398b9
|
||||
'CoreLibs\\Combined\\DateTime' => __DIR__ . '/../..' . '/lib/CoreLibs/Combined/DateTime.php',
|
||||
'CoreLibs\\Convert\\Byte' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/Byte.php',
|
||||
'CoreLibs\\Convert\\Colors' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/Colors.php',
|
||||
'CoreLibs\\Convert\\Encoding' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/Encoding.php',
|
||||
'CoreLibs\\Convert\\Html' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/Html.php',
|
||||
'CoreLibs\\Convert\\Json' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/Json.php',
|
||||
'CoreLibs\\Convert\\Math' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/Math.php',
|
||||
'CoreLibs\\Convert\\MimeAppName' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/MimeAppName.php',
|
||||
'CoreLibs\\Convert\\MimeEncode' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/MimeEncode.php',
|
||||
'CoreLibs\\Create\\Hash' => __DIR__ . '/../..' . '/lib/CoreLibs/Create/Hash.php',
|
||||
'CoreLibs\\Create\\RandomKey' => __DIR__ . '/../..' . '/lib/CoreLibs/Create/RandomKey.php',
|
||||
'CoreLibs\\Create\\Session' => __DIR__ . '/../..' . '/lib/CoreLibs/Create/Session.php',
|
||||
|
||||
Reference in New Issue
Block a user