Compare commits

...

16 Commits

Author SHA1 Message Date
Clemens Schwaighofer
ffdd45e32a Fix phpUnit tests with constant settings and missing checks
BASE constant setting: moved all to same base folder in 4dev/tests
check all other CONSTANT settings if they are already set and skip (used
only in Language default set)

Add missing phpunit check for array merge recursive
2022-04-15 15:19:30 +09:00
Clemens Schwaighofer
316ca106fd Composer autoload update 2022-04-15 13:57:48 +09:00
Clemens Schwaighofer
fd9b201346 Remove old GetSettings for language legacy flow 2022-04-15 13:57:26 +09:00
Clemens Schwaighofer
667dc4de8e Clean up of old _LANG config variables 2022-04-15 13:53:37 +09:00
Clemens Schwaighofer
fed67e990d Update Language\L10n class and drop all legacy code
new Langauge\GetLocale::setLocale() for getting new type lang info from
session, etc
L10n class call chnage of parameters:
NEW: locale, domain, path
OLD: locale, path, domain, legacy(bool)

Temporary auto detect for possible path/domain switch if domain value
has slash inside

Rename all local files to names matching locale folder
en_US -> en

Delete lang folders with symlinks as they are no longer used

Update all header files and class Backend\Admin, ACL\Login,
Output\Form\Generate, Template\SmartyExtend with new language order:
call ::setLocale() afer login class

Update missing test translation strings in all po files

Update phpUnit tests to match all new changes
2022-04-15 13:29:41 +09:00
Clemens Schwaighofer
c181a83b48 Rename po files to new standard <locale>-<domain>.po 2022-04-14 14:47:58 +09:00
Clemens Schwaighofer
c830a32962 Minor fix in gettext loop for max string lenght 2022-04-14 13:43:26 +09:00
Clemens Schwaighofer
82bc99b181 Language\ namespace update
Update the Core Language classes to have all method parameter type
declaration.
GetTextReader has gettext as alias to translate.
GetTextReader public methods to get cache enable status and short
circuit (no translation loaded) status

Main language:
Add new methods for plural and plural in context (__n, __p, __pn)
Deprecate gettext, ngettext, _e

Add new translation loader in gettext standard
<locale>/LC_MESSAGES/<domain> style
Including locales checker, auto detect on enviroment variables, return
self as class (for functions type) return translator class after
loading, etc

New LoadFunctions to run all like functions. Names like php but with two
underscores prefixed. eg gettext -> __gettext
2022-04-13 16:26:15 +09:00
Clemens Schwaighofer
556cabca38 Add DOCTYPE to all admin test files, update phpunit DB IO test
DB IO Test: Change max DB version to 99 from 20 in Version check test

Add DOCTYPE html to all admin class test files
2022-04-13 10:25:04 +09:00
Clemens Schwaighofer
6f4c5e36e6 Move Encoding class away from the Language namespace
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

Also fixed encoding check that not only a code point but a string can
also be used as a parameter.

Update phpunit tests and split them out for each class

Normal test page is still combined for all classes but updated to
correctly use each class
2022-04-13 09:25:42 +09:00
Clemens Schwaighofer
a3c49e408a Update to get default language settings with correct POSIX locale form
Also add phpunit test
2022-04-12 20:20:10 +09:00
Clemens Schwaighofer
cc77d7e031 Update Language\Encoding and phpunit tets
Fix missing replace char settings for conversion check call.
The php replace char method was never called. Also add standard type
settings next to char settings.
Return (get) call can either class set or current set in php

Fix mime encode with trailing space problem if length is on split
length. Mime encode uses \r\n for all line breaks now, can be controlled
via parameter
2022-04-12 20:19:48 +09:00
Clemens Schwaighofer
d553c1364f Add LOCALE config settings
next to the current lang/encoding add locale that is a combination of
both.
Also add a locale folder constant

the default LANG variables (DEFAULT_LANG, SITE_LANG) change from en_utf8
to en_US
new DEFAULT_LOCALE with en_US.UTF-8
2022-04-12 20:14:41 +09:00
Clemens Schwaighofer
3f374a2cd7 Update default db edit* language settings
en = en_US
jp = ja_JP
2022-04-12 20:13:23 +09:00
Clemens Schwaighofer
9e99275db5 phpunit tests includes folder for translation tests 2022-04-12 20:12:38 +09:00
Clemens Schwaighofer
330e2baf39 Add new locale folder structure and symlinks for old lang layout 2022-04-12 14:25:19 +09:00
91 changed files with 3670 additions and 719 deletions

View File

@@ -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;

View File

@@ -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
View 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`

View File

@@ -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.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\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 0"
msgstr[1] "Multi Admin en 1"
msgstr[2] "Multi Admin en 2"
msgctxt "month name"
msgid "May"
msgstr "May Admin en"
msgctxt "month name"
msgid "single"
msgid_plural "multi"
msgstr[0] "Multi Admin month en 0"
msgstr[1] "Multi Admin month en 1"
msgstr[2] "Multi Admin month en 2"
msgid "I should be translated"
msgstr "I should be translated: I WAS TRANSLATED"

View File

@@ -0,0 +1,24 @@
# to craete: msgfmt -o <output.po> <input.mo>
msgid ""
msgstr ""
"Project-Id-Version: en.UTF-8 LC_MESSAGES frontend\n"
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: clemens.schwaighofer@egplusww.co\n"
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
"Language: en\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 0"
msgstr[1] "Multi frontend en 1"
msgstr[2] "Multi frontend en 2"

View File

@@ -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.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,25 @@ 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 0"
msgstr[1] "Multi Admin ja 1"
msgstr[2] "Multi Admin ja 2"
msgctxt "month name"
msgid "May"
msgstr "May Admin ja"
msgctxt "month name"
msgid "single"
msgid_plural "multi"
msgstr[0] "Multi Admin month ja 0"
msgstr[1] "Multi Admin month ja 1"
msgstr[2] "Multi Admin month ja 2"
# login string
msgid "Hello %s"

View File

@@ -0,0 +1,24 @@
# to craete: msgfmt -o <output.po> <input.mo>
msgid ""
msgstr ""
"Project-Id-Version: ja.UTF-8 LC_MESSAGES frontend\n"
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: clemens.schwaighofer@egplusww.com\n"
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
"Language: ja\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
msgid "INPUT TEST"
msgstr "OUTPUT TEST FRONTEND JA"
msgid "single"
msgid_plural "multi"
msgstr[0] "Multi frontend ja 0"
msgstr[1] "Multi frontend ja 1"
msgstr[2] "Multi frontend ja 2"

View 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__

View File

@@ -7,6 +7,7 @@ declare(strict_types=1);
namespace tests;
use Exception;
use PHPUnit\Framework\TestCase;
/**
@@ -274,7 +275,6 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
}
/**
* TODO: create provider for n array merge
* provides array listing for the merge test
*
* @return array
@@ -282,6 +282,61 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
public function arrayMergeRecursiveProvider(): array
{
return [
// 0: expected
// 1..n: to merge arrays
// n+1: trigger for handle keys as string
'two arrays' => [
['a' => 1, 'b' => 2, 'c' => 3],
['a' => 1, 'b' => 2],
['b' => 2, 'c' => 3],
],
'two arrays, string flag' => [
['a' => 1, 'b' => 2, 'c' => 3],
['a' => 1, 'b' => 2],
['b' => 2, 'c' => 3],
true,
],
// non hash arrays
'non hash array merge, no string flag' => [
[3, 4, 5],
[1, 2, 3],
[3, 4, 5],
],
'non hash array merge, string flag' => [
[1, 2, 3, 3, 4, 5],
[1, 2, 3],
[3, 4, 5],
true
],
];
}
/**
* for warning checks
*
* @return array
*/
public function arrayMergeRecursiveProviderWarning(): array
{
return [
// error <2 arguments
'too view arguments' => [
'arrayMergeRecursive needs two or more array arguments',
[1]
],
// error <2 arrays
'only one array' => [
'arrayMergeRecursive needs two or more array arguments',
[1],
true,
],
// error element is not array
'non array between array' => [
'arrayMergeRecursive encountered a non array argument',
[1],
'string',
[2]
],
];
}
@@ -626,21 +681,43 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
* Undocumented function
*
* @covers ::arrayMergeRecursive
* @#dataProvider arrayMergeRecursiveProvider
* @testdox arrayMergeRecursive ... will be $expected [$_dataName]
* @dataProvider arrayMergeRecursiveProvider
* @testdox arrayMergeRecursive ... [$_dataName]
*
* @param array $input nested array set as each parameter
* @param bool $flag
* @param bool|array $expected
* @return void
* array $input, bool $flag, $expected
*
*/
public function testArrayMergeRecursive(): void
{
$this->assertTrue(true, 'Implement proper test run');
$this->markTestIncomplete(
'testArrayMergeRecursive has not been implemented yet.'
$arrays = func_get_args();
// first is expected array, always
$expected = array_shift($arrays);
$output = \CoreLibs\Combined\ArrayHandler::arrayMergeRecursive(
...$arrays
);
$this->assertEquals(
$expected,
$output
);
}
/**
* Undocumented function
*
* @covers ::arrayMergeRecursive
* @dataProvider arrayMergeRecursiveProviderWarning
* @testdox arrayMergeRecursive with E_USER_WARNING [$_dataName]
*
* @return void
*/
public function testArrayMergeRecursiveWarningA(): void
{
$arrays = func_get_args();
// first is expected warning
$warning = array_shift($arrays);
$this->expectWarning();
$this->expectWarningMessage($warning);
\CoreLibs\Combined\ArrayHandler::arrayMergeRecursive(...$arrays);
}
/**

View 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__

View 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__

View File

@@ -68,6 +68,7 @@ final class CoreLibsCreateSessionTest extends TestCase
*/
public function testStartSession(string $input, string $type, $expected_n, $expected_i): void
{
// NEEDS MOCKING
/* $session_id = '';
switch ($type) {
case 'p':
@@ -97,7 +98,8 @@ final class CoreLibsCreateSessionTest extends TestCase
if ($type == 'g') {
unset($GLOBALS['SET_SESSION_NAME']);
} */
$this->markTestSkipped('No implementation for Create\Session. Cannot run session_start in CLI');
$this->markTestSkipped('[CoreLibsCreateSessionTest] No implementation '
. 'for Create\Session. Cannot run session_start in CLI');
}
}

View File

@@ -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 ],
];
}

View File

@@ -54,14 +54,16 @@ final class CoreLibsDebugLoggingTest extends TestCase
'no options set, constant set' => [
null,
[
'log_folder' => '/tmp/',
'log_folder' => str_replace('/configs', '', __DIR__)
. DIRECTORY_SEPARATOR . 'log/',
'debug_all' => false,
'print_all' => false,
],
[
'constant' => [
'BASE' => '/tmp',
'LOG' => '/'
'BASE' => str_replace('/configs', '', __DIR__)
. DIRECTORY_SEPARATOR,
'LOG' => 'log/'
]
]
],

View File

@@ -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__

View File

@@ -0,0 +1,310 @@
<?php // phpcs:disable Generic.Files.LineLength
declare(strict_types=1);
namespace tests;
use PHPUnit\Framework\TestCase;
/**
* Test class for Language\GetLocale
*
* @coversDefaultClass \CoreLibs\Language\GetLocale
* @testdox \CoreLibs\Language\GetLocale method tests
*/
final class CoreLibsLanguageGetLocaleTest extends TestCase
{
/**
* set all constant variables that must be set before call
*
* @return void
*/
public static function setUpBeforeClass(): void
{
// default web page encoding setting
if (!defined('DEFAULT_ENCODING')) {
define('DEFAULT_ENCODING', 'UTF-8');
}
if (!defined('DEFAULT_LOCALE')) {
// default lang + encoding
define('DEFAULT_LOCALE', 'en_US.UTF-8');
}
// site
if (!defined('SITE_ENCODING')) {
define('SITE_ENCODING', DEFAULT_ENCODING);
}
if (!defined('SITE_LOCALE')) {
define('SITE_LOCALE', DEFAULT_LOCALE);
}
// just set
if (!defined('BASE')) {
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
}
if (!defined('INCLUDES')) {
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
}
if (!defined('LANG')) {
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
}
if (!defined('LOCALE')) {
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
}
if (!defined('CONTENT_PATH')) {
define('CONTENT_PATH', 'frontend' . DIRECTORY_SEPARATOR);
}
// array session
$_SESSION = [];
global $_SESSION;
}
/**
* all the test data
*
* @return array
*/
public function setLocaleProvider(): array
{
return [
// 0: locale
// 1: domain
// 2: encoding
// 3: path
// 4: SESSION: DEFAULT_LOCALE
// 5: SESSION: DEFAULT_CHARSET
// 6: expected array
'no params, all default constants' => [
// lang, domain, encoding, path
null, null, null, null,
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
null, null,
// return array
[
'locale' => 'en_US.UTF-8',
'lang' => 'en_US',
'domain' => 'frontend',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?includes\/locale\/$/",
],
],
'no params, session charset and lang' => [
// lang, domain, encoding, path
null, null, null, null,
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
'ja_JP', 'UTF-8',
// return array
[
'locale' => 'ja_JP',
'lang' => 'ja_JP',
'domain' => 'frontend',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?includes\/locale\/$/",
],
],
'no params, session charset and lang short' => [
// lang, domain, encoding, path
null, null, null, null,
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
'ja', 'UTF-8',
// return array
[
'locale' => 'ja',
'lang' => 'ja',
'domain' => 'frontend',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?includes\/locale\/$/",
],
],
// param lang (no sessions)
'locale param only, no sessions' => [
// lang, domain, encoding, path
'ja.UTF-8', null, null, null,
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
null, null,
// return array
[
'locale' => 'ja.UTF-8',
'lang' => 'ja',
'domain' => 'frontend',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?includes\/locale\/$/",
],
],
// different locale setting
'locale complex param only, no sessions' => [
// lang, domain, encoding, path
'ja_JP.SJIS', null, null, null,
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
null, null,
// return array
[
'locale' => 'ja_JP.SJIS',
'lang' => 'ja_JP',
'domain' => 'frontend',
'encoding' => 'SJIS',
'path' => "/^\/(.*\/)?includes\/locale\/$/",
],
],
// param lang and domain (no override)
'locale, domain params, no sessions' => [
// lang, domain, encoding, path
'ja.UTF-8', 'admin', null, null,
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
null, null,
// return array
[
'locale' => 'ja.UTF-8',
'lang' => 'ja',
'domain' => 'admin',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?includes\/locale\/$/",
],
],
// param lang and domain (no override)
'locale, domain, encoding params, no sessions' => [
// lang, domain, encoding, path
'ja.UTF-8', 'admin', 'UTF-8', null,
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
null, null,
// return array
[
'locale' => 'ja.UTF-8',
'lang' => 'ja',
'domain' => 'admin',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?includes\/locale\/$/",
],
],
// lang, domain, path (no override)
'locale, domain and path, no sessions' => [
// lang, domain, encoding, path
'ja.UTF-8', 'admin', '', __DIR__ . '/locale_other/',
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
null, null,
// return array
[
'locale' => 'ja.UTF-8',
'lang' => 'ja',
'domain' => 'admin',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?locale_other\/$/",
],
],
// all params set (no override)
'all parameter, no sessions' => [
// lang, domain, encoding, path
'ja', 'admin', 'UTF-8', __DIR__ . '/locale_other/',
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
null, null,
// return array
[
'locale' => 'ja',
'lang' => 'ja',
'domain' => 'admin',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?locale_other\/$/",
],
],
// param lang and domain (no override)
'long locale, domain, encoding params, no sessions' => [
// lang, domain, encoding, path
'de_CH.UTF-8@euro', 'admin', 'UTF-8', null,
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
null, null,
// return array
[
'locale' => 'de_CH.UTF-8@euro',
'lang' => 'de_CH',
'domain' => 'admin',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?includes\/locale\/$/",
],
],
// TODO invalid params (bad path) (no override)
// TODO param calls, but with override set
];
}
/**
* Undocumented function
*
* @covers ::setLocale
* @dataProvider setLocaleProvider
* @testdox lang settings lang $language, domain $domain, encoding $encoding, path $path; session lang: $SESSION_DEFAULT_LOCALE, session char: $SESSION_DEFAULT_CHARSET [$_dataName]
*
* @return void
*/
public function testsetLocale(
?string $language,
?string $domain,
?string $encoding,
?string $path,
?string $SESSION_DEFAULT_LOCALE,
?string $SESSION_DEFAULT_CHARSET,
array $expected,
): void {
$return_lang_settings = [];
global $_SESSION;
// set override
if ($SESSION_DEFAULT_LOCALE !== null) {
$_SESSION['DEFAULT_LOCALE'] = $SESSION_DEFAULT_LOCALE;
}
if ($SESSION_DEFAULT_CHARSET !== null) {
$_SESSION['DEFAULT_CHARSET'] = $SESSION_DEFAULT_CHARSET;
}
// function call
if ($language === null && $domain === null && $encoding === null && $path === null) {
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale();
} elseif ($language !== null && $domain === null && $encoding === null && $path === null) {
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
$language
);
} elseif ($language !== null && $domain !== null && $encoding === null && $path === null) {
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
$language,
$domain
);
} elseif ($language !== null && $domain !== null && $encoding !== null && $path === null) {
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
$language,
$domain,
$encoding
);
} else {
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
$language,
$domain,
$encoding,
$path
);
}
// print "RETURN: " . print_r($return_lang_settings, true) . "\n";
foreach (
[
'locale', 'lang', 'domain', 'encoding', 'path'
] as $key
) {
$value = $expected[$key];
if (strpos($value, "/") === 0) {
// this is regex
$this->assertMatchesRegularExpression(
$value,
$return_lang_settings[$key],
'assert regex failed for ' . $key
);
} else {
// assert equal
$this->assertEquals(
$value,
$return_lang_settings[$key],
'assert equal failed for ' . $key
);
}
}
// unset all vars
$_SESSION = [];
unset($GLOBALS['OVERRIDE_LANG']);
}
}
// __END__

File diff suppressed because it is too large Load Diff

View 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;

View 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"

View 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"

Binary file not shown.

View 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"

View 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"

Binary file not shown.

View File

@@ -44,9 +44,24 @@ $db = new CoreLibs\DB\IO(DB_CONFIG, $log);
// login & page access check
$login = new CoreLibs\ACL\Login($db, $log);
```
* update language class
```php
// pre auto detect language after login
$locale = \CoreLibs\Language\GetLocale::setLocale();
// set lang and pass to smarty/backend
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
);
```
* smarty needs language
```php
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
```
* admin backend also needs logger
```php
$cms = new CoreLibs\Admin\Backend($db, $log);
$cms = new CoreLibs\Admin\Backend($db, $log, $l10n, $locale);
```
* update and `$cms` or similar calls so db is in `$cms->db->...` and log are in `$cms->log->...`
* update all `config.*.php` files where needed
@@ -60,6 +75,12 @@ require BASE . LIB . 'autoloader.php';
```
**UPDATE:**
```php
// po langs [DEPRECAED: use LOCALE]
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
// po locale file
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
```
```php
// SSL host name
// define('SSL_HOST', $_ENV['SSL_HOST'] ?? '');
```
@@ -85,6 +106,13 @@ define('CONTENT_WIDTH', '100%');
define('BASE_NAME', preg_replace('/[^A-Za-z0-9]/', '', $_ENV['BASE_NAME'] ?? ''));
```
```php
/************* LANGUAGE / ENCODING *******/
// default lang + encoding
define('DEFAULT_LOCALE', 'en_US.UTF-8');
// default web page encoding setting
define('DEFAULT_ENCODING', 'UTF-8');
```
```php
// BAIL ON MISSING DB CONFIG:
// we have either no db selction for this host but have db config entries
// or we have a db selection but no db config as array or empty
@@ -104,6 +132,10 @@ if (
}
```
```php
// remove SITE_LANG
define('SITE_LOCALE', $SITE_CONFIG[HOST_NAME]['site_locale'] ?? DEFAULT_LOCALE);
define('SITE_ENCODING', $SITE_CONFIG[HOST_NAME]['site_encoding'] ?? DEFAULT_ENCODING);
```
```php
/************* GENERAL PAGE TITLE ********/
define('G_TITLE', $_ENV['G_TITLE'] ?? '');
@@ -118,6 +150,15 @@ In the config then
```php
'db_name' => $_ENV['DB_NAME.TEST'] ?? '',
```
* config.host.php update
must add site_locale (site_lang + site_encoding)
remove site_lang
```php
// lang + encoding
'site_locale' => 'en_US.UTF-8',
// site language
'site_encoding' => 'UTF-8',
```
* copy `layout/admin/javascript/edit.jq.js`
* check other javacsript files if needed (`edit.jq.js`)

View File

@@ -43,14 +43,21 @@ $log = new CoreLibs\Debug\Logging([
]);
// db config with logger
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
$backend = new CoreLibs\Admin\Backend($db, $log);
$locale = \CoreLibs\Language\GetLocale::setLocale();
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
);
$backend = new CoreLibs\Admin\Backend($db, $log, $l10n, $locale);
print "<!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>';
// set acl, from eg login acl
print "SETACL[]: " . $backend->setACL([]) . "<br>";
print "SETACL[]: " . $backend->setACL(['EMPTY' => 'EMPTY']) . "<br>";
print "ADBEDITLOG: " . $backend->adbEditLog('CLASSTEST-ADMIN', 'Some info stirng') . "<br>";
print "ADBTOPMENU(0): " . \CoreLibs\Debug\Support::printAr($backend->adbTopMenu()) . "<br>";
print "ADBMSG: " . $backend->adbMsg('info', 'Message: %1$d', [1]) . "<br>";

View File

@@ -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>';

View File

@@ -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>';

View File

@@ -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>';

View File

@@ -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>';

View File

@@ -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>';

View File

@@ -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>';

View File

@@ -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>';

View File

@@ -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>';

View File

@@ -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

View File

@@ -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>';

View File

@@ -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>';

View File

@@ -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>';

View File

@@ -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>';

View File

@@ -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>';

View File

@@ -19,8 +19,6 @@ ob_start();
// basic class test file
define('USE_DATABASE', false);
// init language
$lang = 'en_utf8';
// sample config
require 'config.php';
// set session name
@@ -29,28 +27,145 @@ 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;
use CoreLibs\Debug\Support;
echo "<br><b>LIST LOCALES</b><br>";
$locale = 'en_US.UTF-8';
$locales = CoreLibs\Language\L10n::listLocales($locale);
print "[" . $locale . "] LOCALES: " . Support::printAr($locales) . "<br>";
$locale = 'en.UTF-8';
$locales = CoreLibs\Language\L10n::listLocales($locale);
print "[" . $locale . "] LOCALES: " . Support::printAr($locales) . "<br>";
echo "<br><b>LOCALE INFO</b><br>";
$locale = 'en_US.UTF-8';
$locale_info = CoreLibs\Language\L10n::parseLocale($locale);
print "[" . $locale . "] INFO: " . Support::printAr($locale_info) . "<br>";
$locale = 'en.UTF-8';
$locale_info = CoreLibs\Language\L10n::parseLocale($locale);
print "[" . $locale . "] INFO: " . Support::printAr($locale_info) . "<br>";
echo "<br><b>AUTO DETECT</b><br>";
$get_locale = \CoreLibs\Language\GetLocale::setLocale();
print "[AUTO]: " . Support::printAr($get_locale) . "<br>";
$get_locale = \CoreLibs\Language\GetLocale::setLocale('en', 'foo', 'ISO-8895');
print "[OVERRIDE]: " . Support::printAr($get_locale) . "<br>";
// try to load non existing
echo "<br><b>NEW TYPE</b><br>";
// translate string
$string = 'INPUT TEST';
echo "LANGUAGE SET: " . $l->__getLang() . "<br>";
echo "LANGUAGE FILE: " . $l->__getMoFile() . "<br>";
// new path test
$lang = 'ja';
$domain = 'admin';
$encoding = 'UTF-8';
$path = BASE . INCLUDES . LOCALE;
// load direct
$l = new CoreLibs\Language\L10n($lang, $domain, $path);
echo "*<br>";
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
echo "CONTENT PATH: " . $l->getBaseContentPath() . "<br>";
echo "DOMAIN PATH: " . $l->getTextDomain($domain) . "<br>";
echo "BASE PATH: " . $l->getBaseLocalePath() . "<br>";
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
// switch to other language
$lang = 'ja_utf8';
$l->l10nReloadMOfile($lang);
echo "LANGUAGE SET: " . $l->__getLang() . "<br>";
echo "LANGUAGE FILE: " . $l->__getMoFile() . "<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>";
}
$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>";
}
// change domain
$domain = 'frontend';
$l->getTranslator('', $domain, $path);
echo "*<br>";
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
echo "CONTENT PATH: " . $l->getBaseContentPath() . "<br>";
echo "DOMAIN PATH: " . $l->getTextDomain($domain) . "<br>";
echo "BASE PATH: " . $l->getBaseLocalePath() . "<br>";
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
// TODO: run compare check input must match output
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
// change language short type
$lang = 'en';
$domain = 'admin';
$l->getTranslator($lang, $domain, $path);
echo "*<br>";
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
echo "CONTENT PATH: " . $l->getBaseContentPath() . "<br>";
echo "DOMAIN PATH: " . $l->getTextDomain($domain) . "<br>";
echo "BASE PATH: " . $l->getBaseLocalePath() . "<br>";
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
// chang to wrong language
$lang = 'tr';
$l->getTranslator($lang, $domain, $path);
echo "*<br>";
echo "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>";

View File

@@ -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>';

View File

@@ -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>';

View File

@@ -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>';

View File

@@ -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>';

View File

@@ -41,10 +41,17 @@ $log = new CoreLibs\Debug\Logging([
]);
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
$login = new CoreLibs\ACL\Login($db, $log);
$backend = new CoreLibs\Admin\Backend($db, $log);
$locale = \CoreLibs\Language\GetLocale::setLocale();
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
);
$backend = new CoreLibs\Admin\Backend($db, $log, $l10n, $locale);
$backend->db->dbInfo(true);
ob_end_flush();
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS</title><head>";
print "<body>";
@@ -60,7 +67,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>';
@@ -78,9 +85,10 @@ print '<div><a href="class_test.smarty.php">Class Test: SMARTY</a></div>';
print '<div><a href="class_test.autoloader.php">Class Test: AUTOLOADER</a></div>';
print "<hr>";
print "L: " . CoreLibs\Debug\Support::printAr($locale) . "<br>";
// print all _ENV vars set
print "<div>READ _ENV ARRAY:</div>";
print "<pre>" . print_r(array_map('htmlentities', $_ENV), true) . "</pre>";
print CoreLibs\Debug\Support::printAr(array_map('htmlentities', $_ENV));
// set + check edit access id
$edit_access_id = 3;
if (is_object($login) && isset($login->acl['unit'])) {

View File

@@ -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>';

View File

@@ -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>';

View File

@@ -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>';

View File

@@ -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>';

View File

@@ -19,8 +19,6 @@ ob_start();
// basic class test file
define('USE_DATABASE', true);
// set language
$lang = 'en_utf8';
// sample config
require 'config.php';
// override ECHO ALL FALSE
@@ -43,9 +41,15 @@ $log = new CoreLibs\Debug\Logging([
'echo_all' => $ECHO_ALL ?? false,
'print_all' => $PRINT_ALL ?? false,
]);
$smarty = new CoreLibs\Template\SmartyExtend();
$l = new CoreLibs\Language\L10n($lang);
$locale = \CoreLibs\Language\GetLocale::setLocale();
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
);
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
print "<!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>';
@@ -69,7 +73,7 @@ $smarty->setSmartyPaths();
// smarty test
$smarty->DATA['SMARTY_TEST'] = 'Test Data';
$smarty->DATA['TRANSLATE_TEST'] = $l->__('Are we translated?');
$smarty->DATA['TRANSLATE_TEST'] = $l10n->__('Are we translated?');
$smarty->DATA['TRANSLATE_TEST_SMARTY'] = $smarty->l10n->__('Are we translated?');
$smarty->DATA['replace'] = 'Replaced';
// variable variables

View File

@@ -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>';

View File

@@ -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>';

View File

@@ -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>';

View File

@@ -27,7 +27,8 @@ $__LOCAL_CONFIG = [
'db_host' => 'test',
'location' => 'test',
'debug_flag' => true,
'site_lang' => 'en_utf8',
'site_locale' => 'en_US.UTF-8',
'site_encoding' => 'UTF-8',
'login_enabled' => true
];
@@ -44,8 +45,10 @@ $SITE_CONFIG = [
'location' => 'test',
// show DEBUG override
'debug_flag' => true,
// site language
'site_lang' => 'en_utf8',
// site locale
'site_locale' => 'en_US.UTF-8',
// site encoding
'site_encoding' => 'UTF-8',
// enable/disable login override
'login_enabled' => true
],

View File

@@ -65,8 +65,8 @@ define('JS', 'javascript' . DIRECTORY_SEPARATOR);
define('TABLE_ARRAYS', 'table_arrays' . DIRECTORY_SEPARATOR);
// smarty libs path
define('SMARTY', 'Smarty' . DIRECTORY_SEPARATOR);
// po langs
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
// po locale file
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
// cache path
define('CACHE', 'cache' . DIRECTORY_SEPARATOR);
// temp path
@@ -158,7 +158,8 @@ 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');
// default lang + encoding
define('DEFAULT_LOCALE', 'en_US.UTF-8');
// default web page encoding setting
define('DEFAULT_ENCODING', 'UTF-8');
@@ -258,7 +259,8 @@ $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_LOCALE', $SITE_CONFIG[HOST_NAME]['site_locale'] ?? DEFAULT_LOCALE);
define('SITE_ENCODING', $SITE_CONFIG[HOST_NAME]['site_encoding'] ?? DEFAULT_ENCODING);
define('LOGIN_ENABLED', $SITE_CONFIG[HOST_NAME]['login_enabled'] ?? false);
define('AUTH', $SITE_CONFIG[HOST_NAME]['auth'] ?? false);
// paths

View File

@@ -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;

View File

@@ -53,9 +53,14 @@ if (!defined('DIR')) {
// find trigger name "admin/" or "frontend/" in the getcwd() folder
foreach (['admin', 'frontend'] as $folder) {
if (strstr(getcwd() ?: '', DIRECTORY_SEPARATOR . $folder)) {
define('CONTENT_PATH', $folder . DIRECTORY_SEPARATOR);
break;
}
}
// if content path is empty, fallback is default
/** @phpstan-ignore-next-line can be empty */
if (empty($folder)) {
$folder = 'default';
}
define('CONTENT_PATH', $folder . DIRECTORY_SEPARATOR);
// __END__

View File

@@ -1,77 +0,0 @@
<?php
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2005/07/19
* SHORT DESCRIPTION:
* preset date variables
* HISTORY:
*********************************************************************/
declare(strict_types=1);
/******
All moved to CoreLibs\Combined\DateTime
DAY_SHORT
DAY_LONG
MONTH_LONG
MONTH_SHORT
*******/
trigger_error(
'Date.VArs.php is deprecated. '
. 'Use CoreLibs\Combined\DateTime:: with upper case old variable name',
E_USER_DEPRECATED
);
$day_short = [
1 => 'Mon',
2 => 'Tue',
3 => 'Wed',
4 => 'Thu',
5 => 'Fri',
6 => 'Sat',
7 => 'Sun'
];
$day_long = [
1 => 'Monday',
2 => 'Tuesday',
3 => 'Wednesday',
4 => 'Thursday',
5 => 'Friday',
6 => 'Saturday',
7 => 'Sunday'
];
// months
$month_long = [
1 => 'January',
2 => 'February',
3 => 'March',
4 => 'April',
5 => 'May',
6 => 'June',
7 => 'July',
8 => 'August',
9 => 'September',
10 => 'October',
11 => 'November',
12 => 'December'
];
$month_short = [
1 => 'Jan',
2 => 'Feb',
3 => 'Mar',
4 => 'Apr',
5 => 'May',
6 => 'Jun',
7 => 'Jul',
8 => 'Aug',
9 => 'Sep',
10 => 'Oct',
11 => 'Nov',
12 => 'Dec'
];
// __END__

View File

@@ -72,10 +72,19 @@ if (
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
// login & page access check
$login = new CoreLibs\ACL\Login($db, $log);
// lang, path, domain
// pre auto detect language after login
$locale = \CoreLibs\Language\GetLocale::setLocale();
// set lang and pass to smarty/backend
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
);
// create smarty object
$smarty = new CoreLibs\Template\SmartyExtend();
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
// create new Backend class with db and loger attached
$cms = new CoreLibs\Admin\Backend($db, $log);
$cms = new CoreLibs\Admin\Backend($db, $log, $l10n, $locale);
// the menu show flag (what menu to show)
$cms->menu_show_flag = 'main';
// db info

View File

@@ -1,22 +0,0 @@
<?php
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2007/09/03
* SHORT DESCRIPTION:
* set paths & language variables
* HISTORY:
*********************************************************************/
declare(strict_types=1);
/******
NOTE THAT THIS INCLUDE IS OBSOLETE
USE THE BELOW FUNCTION CALL IN THE SCRIPT ITSELF
*******/
trigger_error('admin_set_paths.php is deprecated. Use SmartyExtended->setSmartyPaths();', E_USER_DEPRECATED);
if ($smarty) {
$smarty->setSmartyPaths();
}
// __END__

View File

@@ -1,23 +0,0 @@
<?php
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2005/07/12
* SHORT DESCRIPTION:
* default smarty vars, and create output template for smarty
* HISTORY:
*********************************************************************/
declare(strict_types=1);
/******
NOTE THAT THIS INCLUDE IS OBSOLETE
USE THE BELOW FUNCTION CALL IN THE SCRIPT ITSELF
*******/
trigger_error(
'admin_smarty.php is deprecated. Use SmartyExtended->setSmartyVarsAdmin(); or setSmartyVarsFrontend();',
E_USER_DEPRECATED
);
$smarty->setSmartyVarsAdmin();
// __END__

View File

@@ -61,18 +61,27 @@ $log = new CoreLibs\Debug\Logging([
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
// login page
$login = new CoreLibs\ACL\Login($db, $log);
// lang, path, domain
// pre auto detect language after login
$locale = \CoreLibs\Language\GetLocale::setLocale();
// set lang and pass to smarty/backend
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
);
// flush and start
ob_end_flush();
// turn off set log per class
$log->setLogPer('class', false);
// create form class
$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $log);
$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $log, $l10n, $locale);
if ($form->mobile_phone) {
echo "I am sorry, but this page cannot be viewed by a mobile phone";
exit;
}
// smarty template engine (extended Translation version)
$smarty = new CoreLibs\Template\SmartyExtend();
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
// $form->log->debug('POST', $form->log->prAr($_POST));

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -167,13 +167,10 @@ class Login
* constructor, does ALL, opens db, works through connection checks, closes itself
* @param \CoreLibs\DB\IO $db Database connection class
* @param \CoreLibs\Debug\Logging $log Logging class
* @param \CoreLibs\Language\L10n|null $l10n l10n language class
* if null, auto set
*/
public function __construct(
\CoreLibs\DB\IO $db,
\CoreLibs\Debug\Logging $log,
?\CoreLibs\Language\L10n $l10n = null
\CoreLibs\Debug\Logging $log
) {
// log login data for this class only
$log->setLogPer('class', true);
@@ -215,19 +212,6 @@ class Login
// or need to pass it back
// to the continue AJAX class for output back to the user
$this->login_is_ajax_page = isset($GLOBALS['AJAX_PAGE']) && $GLOBALS['AJAX_PAGE'] ? true : false;
// set the default lang
$locale = 'en_US.UTF-8';
$lang = 'en_utf8';
if (Session::getSessionId() !== false && !empty($_SESSION['DEFAULT_LANG'])) {
$lang = $_SESSION['DEFAULT_LANG'];
$locale = $_SESSION['DEFAULT_LOCALE'];
} else {
$lang = defined('SITE_LANG') && !empty(SITE_LANG) ?
SITE_LANG : DEFAULT_LANG;
$locale = defined('SITE_LOCALE') && !empty(SITE_LOCALE) ?
SITE_LOCALE : DEFAULT_LOCALE;
}
$this->l = $l10n ?? new \CoreLibs\Language\L10n($lang);
// if we have a search path we need to set it, to use the correct DB to login
// check what schema to use. if there is a login schema use this, else check
@@ -300,6 +284,24 @@ class Login
$this->loginCheckPermissions();
// logsout user
$this->loginLogoutUser();
// ** LANGUAGE SET AFTER LOGIN **
// set the locale
if (Session::getSessionId() !== false && !empty($_SESSION['DEFAULT_LANG'])) {
$locale = $_SESSION['DEFAULT_LOCALE'] ?? '';
} else {
$locale = defined('SITE_LOCALE') && !empty(SITE_LOCALE) ?
SITE_LOCALE :
/** @phpstan-ignore-next-line DEFAULT_LOCALE could be empty */
(defined('DEFAULT_LOCALE') && !empty(DEFAULT_LOCALE) ?
DEFAULT_LOCALE : 'en.UTF-8');
}
// set domain
if (defined('CONTENT_PATH') && !empty(CONTENT_PATH)) {
$domain = str_replace('/', '', CONTENT_PATH);
} else {
$domain = 'admin';
}
$this->l = new \CoreLibs\Language\L10n($locale, $domain);
// if the password change flag is okay, run the password change method
if ($this->password_change) {
$this->loginPasswordChange();

View File

@@ -114,15 +114,16 @@ class Backend
// CONSTRUCTOR / DECONSTRUCTOR |====================================>
/**
* main class constructor
* @param \CoreLibs\DB\IO $db Database connection class
* @param \CoreLibs\Debug\Logging $log Logging class
* @param \CoreLibs\Language\L10n|null $l10n l10n language class
* if null, auto set
* @param \CoreLibs\DB\IO $db Database connection class
* @param \CoreLibs\Debug\Logging $log Logging class
* @param \CoreLibs\Language\L10n $l10n l10n language class
* @param array<string,string> $locale locale data read from setLocale
*/
public function __construct(
\CoreLibs\DB\IO $db,
\CoreLibs\Debug\Logging $log,
?\CoreLibs\Language\L10n $l10n = null
\CoreLibs\Language\L10n $l10n,
array $locale
) {
// set to log not per class
$log->setLogPer('class', false);
@@ -130,10 +131,15 @@ class Backend
$this->log = $log;
// attach db class
$this->db = $db;
// TODO lang create outside of class
$this->setLangEncoding();
// get the language sub class & init it
$this->l = $l10n ?? new \CoreLibs\Language\L10n($this->lang);
$this->l = $l10n;
// parse and read, legacy stuff
$this->encoding = $locale['encoding'];
$this->lang = $locale['lang'];
// get first part from lang
$this->lang_short = explode('_', $locale['lang'])[0];
$this->domain = $this->l->getDomain();
$this->lang_dir = $this->l->getBaseLocalePath();
// set the page name
$this->page_name = \CoreLibs\Get\System::getPageName();
@@ -159,29 +165,6 @@ class Backend
// NO OP
}
// INTERNAL METHODS |===============================================>
/**
* set the language encoding and language settings
* use $OVERRIDE_LANG to override all language settings
* the default charset from _SESSION login or from
* config DEFAULT ENCODING
* the lang full name for mo loading from _SESSION login
* or SITE LANG or DEFAULT LANG from config
* creates short lang (only first two chars) from the lang
* @return void
*/
private function setLangEncoding(): void
{
list (
$this->encoding,
$this->lang,
$this->lang_short,
$this->domain,
$this->lang_dir
) = \CoreLibs\Language\GetSettings::setLangEncoding();
}
// PUBLIC METHODS |=================================================>
/**

View File

@@ -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

View 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__

View File

@@ -218,7 +218,8 @@ class ArrayHandler
continue;
}
foreach ($array as $key => $value) {
// if string or if key is assumed to be string do key match else add new entry
// if string or if key is assumed to be string do key match
// else add new entry
if (is_string($key) || $key_is_string === false) {
if (is_array($value) && array_key_exists($key, $merged) && is_array($merged[$key])) {
// $merged[$key] = call_user_func(__METHOD__, $merged[$key], $value, $key_is_string);

View 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__

View 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__

View File

@@ -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;
}

View File

@@ -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) {

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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
);
}
}

View File

@@ -0,0 +1,117 @@
<?php
/*
* Internal function for getting locale and encodig settings
* used for new locale layout
*/
declare(strict_types=1);
namespace CoreLibs\Language;
class GetLocale
{
/**
* returns locale, lang, domain, encoding, path
* from either parameter set or from sessions/config variables
*
* @param string|null $locale override auto detect
* @param string|null $domain override domain
* @param string|null $encoding override encoding
* @param string|null $path override path
* @return array<string,string> locale, domain, encoding, path
*/
public static function setLocale(
?string $locale = null,
?string $domain = null,
?string $encoding = null,
?string $path = null
): array {
// locale must match at least basic rules
if (
empty($locale) ||
!preg_match("/^[-A-Za-z0-9_.@]+$/", $locale)
) {
if (!empty($_SESSION['DEFAULT_LOCALE'])) {
// parse from session (logged in)
$locale = $_SESSION['DEFAULT_LOCALE'];
} else {
// else parse from site locale
$locale = defined('SITE_LOCALE') && !empty(SITE_LOCALE) ?
SITE_LOCALE :
// else parse from default, if not 'en'
/** @phpstan-ignore-next-line DEFAULT_LOCALE could be empty */
(defined('DEFAULT_LOCALE') && !empty(DEFAULT_LOCALE) ?
DEFAULT_LOCALE : 'en');
}
}
// if domain is set, must be alphanumeric, if not unset
if (
empty($domain) ||
!preg_match("/^\w+$/", $domain)
) {
// if no domain is set, fall back to content path
$domain = str_replace('/', '', CONTENT_PATH);
}
// check that override encoding matches locale encoding
// if locale encoding is set
preg_match('/(?:\\.(?P<charset>[-A-Za-z0-9_]+))/', $locale, $matches);
$locale_encoding = $matches['charset'] ?? null;
if (
// empty encoding
empty($encoding) ||
// not valid encoding
!preg_match("/^[-A-Za-z0-9_]+$/", $encoding) ||
// locale encoding set and not matching to encoding
(!empty($locale_encoding) && $encoding != $locale_encoding)
) {
if (!empty($locale_encoding)) {
$encoding = strtoupper($locale_encoding);
} elseif (!empty($_SESSION['DEFAULT_CHARSET'])) {
// else set from session
$encoding = $_SESSION['DEFAULT_CHARSET'];
} else {
// else set from site encoding
$encoding = defined('SITE_ENCODING') && !empty(SITE_ENCODING) ?
SITE_ENCODING :
// or default encoding, if not 'UTF-8'
/** @phpstan-ignore-next-line DEFAULT_LOCALE could be empty */
(defined('DEFAULT_ENCODING') && !empty(DEFAULT_ENCODING) ?
DEFAULT_ENCODING : 'UTF-8');
}
}
// path checks if set, if not valid path unset to default BASE path
if (
empty($path) ||
!is_dir($path)
) {
$path = BASE . INCLUDES . LOCALE;
}
// extract lang & country from locale string, else set to en
if (
preg_match(
// lang
'/^(?P<lang>[a-z]{2,3})'
// country code
. '(?:_(?P<country>[A-Z]{2}))?/',
$locale,
$matches
)
) {
$lang = ($matches['lang'] ?? 'en')
// add country only if set
. (!empty($matches['country']) ? '_' . $matches['country'] : '');
} else {
$lang = 'en';
}
return [
'locale' => $locale,
'lang' => $lang,
'domain' => $domain,
'encoding' => $encoding,
'path' => $path,
];
}
}
// __END__

View File

@@ -1,123 +0,0 @@
<?php
/*
* Internal function for getting languange and encodig settings
*/
declare(strict_types=1);
namespace CoreLibs\Language;
class GetSettings
{
/**
* Sets encoding and language
* Can be overridden with language + path to mo file
* If language is set it must be in the format of:
* <lang>.<encoding>
* <lang>_<country>.<encoding>
* <lang>_<country>@<subset>.<encoding>
*
* @param string|null $language
* @param string|null $path
* @return array
*/
public static function setLangEncoding(
?string $language = null,
?string $domain = null,
?string $path = null
): array {
$lang = '';
$lang_short = '';
$encoding = '';
// if language is set, extract
if (!empty($language)) {
preg_match(
"/^(([a-z]{2,})(_[A-Z]{2,})?(@[a-z]{1,})?)(\.([\w-])+)?$/",
$language,
$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] ?? '';
}
// if domain is set, must be alphanumeric, if not unset
if (
!empty($domain) &&
!preg_match("/^\w+$/", $domain)
) {
$domain = '';
}
// path checks if set, if not valid path unset
if (
!empty($path) &&
!is_dir($path)
) {
$path = '';
}
// just emergency fallback for language
// set encoding
if (empty($encoding)) {
if (!empty($_SESSION['DEFAULT_CHARSET'])) {
$encoding = $_SESSION['DEFAULT_CHARSET'];
} else {
$encoding = DEFAULT_ENCODING;
}
}
// gobal override
if (empty($lang)) {
if (!empty($GLOBALS['OVERRIDE_LANG'])) {
$lang = $GLOBALS['OVERRIDE_LANG'];
} elseif (!empty($_SESSION['DEFAULT_LANG'])) {
// session (login)
$lang = $_SESSION['DEFAULT_LANG'];
} else {
// mostly default SITE LANG or DEFAULT LANG
$lang = defined('SITE_LANG') && !empty(SITE_LANG) ?
SITE_LANG :
DEFAULT_LANG;
}
}
// create the char lang encoding
if (empty($lang_short)) {
$lang_short = substr($lang, 0, 2);
}
// set the language folder
if (empty($path)) {
// LEGACY
$path = BASE . INCLUDES . LANG . CONTENT_PATH;
// will be BASE . INCLUDES . LANG . $language . /LC_MESSAGES/
// so CONTENT_PATH has to be removed
}
// if no domain is set, fall back to content path
if (empty($domain)) {
$domain = str_replace('/', '', CONTENT_PATH);
}
// return
return [
// as array
0 => $encoding,
1 => $lang,
2 => $lang_short,
3 => $domain,
4 => $path,
// with index name
// encoding
'encoding' => $encoding,
// language full string, eg en_US
'lang' => $lang,
// lang short, if eg en_US only en
'lang_short' => $lang_short,
// translation domain (CONTENT_PATH)
'domain' => $domain,
// folder BASE ONLY
'path' => $path,
];
}
}

View File

@@ -3,34 +3,26 @@
/*********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2004/11/18
* VERSION: 1.0.0
* VERSION: 3.0.0
* RELEASED LICENSE: GNU GPL 3
* SHORT DESCRIPTION:
* init class for gettext. Original was just a function & var setting include for wordpress.
* init class for gettext. Original was just a function &
* var setting include for wordpress.
* I changed that to a class to be more portable with my style of coding
*
* PUBLIC VARIABLES
*
* PRIVATE VARIABLES
*
* VERSION 3.0 (2022/4) removes all old folder layout and uses standard gettext
* PUBLIC METHODS
* __: returns string (translated or original if not found)
* __e: echos out string (translated or original if not found)
* __n: should return plural. never tested this.
*
* PRIVATE METHODS
* __ : returns string (translated or original if not found)
* __n : plural string
* __p : string with context
* __pb: string with context and plural
*
* HISTORY:
* 2022/4/15 (cs) drop all old folder layout support, new folder base
* in locale with standard gettext layout of
* locale/LC_MESSAGES/domain.mo
* 2005/10/17 (cs) made an on the fly switch method (reload of lang)
*********************************************************************/
// TODO: default path change to <base>/lang/LC_MESSAGES/domain.encoding.mo
// for example: lang: ja_JP.UTF-8, domain: admin
// <base>/ja_JP/LC_MESSAGES/admin.UTF-8.mo
// OLD: includes/lang/admin/ja_utf8.mo
// NEW: includes/lang/ja_JP/LC_MESSAGES/admin.UTF-8.mo
// or fallback: includes/lang/ja/LC_MESSAGES/admin.UTF-8.mo
declare(strict_types=1);
namespace CoreLibs\Language;
@@ -40,104 +32,516 @@ 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 = ['' => './'];
// files
/** @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 = '';
// errors
/** @var bool if load of mo file was unsuccessful */
private $load_failure = false;
// object holders
/** @var FileReader|bool reader class for file reading, false for short circuit */
private $input = false;
/** @var GetTextReader reader class for MO data */
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 $domain override CONTENT_PATH . $encoding name for mo file
* @param string $path path, if empty fallback on default internal path
*/
public function __construct(string $lang = '', string $path = '')
{
if (!$lang) {
$this->lang = 'en';
} else {
$this->lang = $lang;
public function __construct(
string $locale = '',
string $domain = '',
string $path = '',
) {
// auto load language only if at least locale and domain is set
if (!empty($locale) && !empty($domain)) {
// check hack if domain and path is switched
// Note this can be removed in future versions
if (strstr($domain, DIRECTORY_SEPARATOR) !== false) {
$_domain = $path;
$path = $domain;
$domain = $_domain;
}
$this->getTranslator($locale, $domain, $path);
}
// 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';
}
/**
* loads the mo file base on path, locale and domain set
*
* @param string $locale language name (optional), fallback is en
* @param string $domain override CONTENT_PATH . $encoding name for mo file
* @param string $path path, if empty fallback on default internal path
* @return GetTextReader the main gettext reader object
*/
public function getTranslator(
string $locale = '',
string $domain = '',
string $path = ''
): 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;
// if path is a dir
// 1) from a previous set domain
// 2) from method option as is
// 3) fallback if BASE/INCLUDES/LOCALE set
// 4) current dir
if (!empty($this->paths[$domain]) && is_dir($this->paths[$domain])) {
$this->base_locale_path = $this->paths[$domain];
} elseif (is_dir($path)) {
$this->base_locale_path = $path;
} elseif (
defined('BASE') && defined('INCLUDES') && defined('LOCALE')
) {
// set fallback base path if constant set
$this->base_locale_path = BASE . INCLUDES . LOCALE;
} else {
$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;
}
/**
* parse the locale string for further processing
*
* @param string $locale Locale to parse
* @return array<string,string|null> array with lang, country, charset, modifier
*/
public static function parseLocale(string $locale = ''): array
{
preg_match(
// language code
'/^(?P<lang>[a-z]{2,3})'
// country code
. '(?:_(?P<country>[A-Z]{2}))?'
// charset
. '(?:\\.(?P<charset>[-A-Za-z0-9_]+))?'
// @ modifier
. '(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/',
$locale,
$matches
);
return [
'lang' => $matches['lang'] ?? null,
'country' => $matches['country'] ?? null,
'charset' => $matches['charset'] ?? null,
'modifier' => $matches['modifier'] ?? null,
];
}
/**
* original:
* 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
$locale_detail = L10n::parseLocale($locale);
// all null = nothing mached, return locale as is
if ($locale_detail === array_filter($locale_detail, 'is_null')) {
return [$locale];
}
// write to innteral vars
$lang = $locale_detail['lang'];
$country = $locale_detail['country'];
$charset = $locale_detail['charset'];
$modifier = $locale_detail['modifier'];
// we need to add all possible cominations from not null set
// entries to the list, from longest to shortest
// %s_%s.%s@%s (lang _ country . encoding @ suffix)
// %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 +549,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 +625,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__

View 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
);
}

View File

@@ -299,23 +299,39 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
/**
* construct form generator
* @param array<mixed> $db_config db config array
* @param \CoreLibs\Debug\Logging|null $log Logging class
* @param \CoreLibs\Language\L10n|null $l10n l10n language class
* if null, auto set
* @param array<mixed> $db_config db config array, mandatory
* @param \CoreLibs\Debug\Logging|null $log Logging class, null auto set
* @param \CoreLibs\Language\L10n|null $l10n l10n language class, null auto set
* @param array<string,string>|null $locale locale array from ::setLocale,
* null auto set
*/
public function __construct(
array $db_config,
\CoreLibs\Debug\Logging $log = null,
?\CoreLibs\Language\L10n $l10n = null
?\CoreLibs\Debug\Logging $log = null,
?\CoreLibs\Language\L10n $l10n = null,
?array $locale = null
) {
global $table_arrays;
// replace any non valid variable names
// TODO extract only alphanumeric and _ after . to _ replacement
$this->my_page_name = str_replace(['.'], '_', System::getPageName(System::NO_EXTENSION));
$this->setLangEncoding();
// if pass on locale is null
if ($locale === null) {
$locale = \CoreLibs\Language\GetLocale::setLocale();
}
// init the language class
$this->l = $l10n ?? new \CoreLibs\Language\L10n($this->lang);
$this->l = $l10n ?? new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
);
// legacy lang vars set
$this->encoding = $locale['encoding'];
$this->lang = $locale['lang'];
// get first part from lang
$this->lang_short = explode('_', $locale['lang'])[0];
$this->domain = $this->l->getDomain();
$this->lang_dir = $this->l->getBaseLocalePath();
// load config array
// get table array definitions for current page name
@@ -443,29 +459,6 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
parent::__destruct();
}
// INTERNAL METHODS |===============================================>
/**
* ORIGINAL in \CoreLibs\Admin\Backend
* set the language encoding and language settings
* the default charset from _SESSION login or from
* config DEFAULT ENCODING
* the lang full name for mo loading from _SESSION login
* or SITE LANG or DEFAULT LANG from config
* creates short lang (only first two chars) from the lang
* @return void
*/
private function setLangEncoding(): void
{
list (
$this->encoding,
$this->lang,
$this->lang_short,
$this->domain,
$this->lang_dir
) = \CoreLibs\Language\GetSettings::setLangEncoding();
}
// PUBLIC METHODS |=================================================>
/**

View File

@@ -154,50 +154,36 @@ class SmartyExtend extends \Smarty
* constructor class, just sets the language stuff
* calls L10 for pass on internaly in smarty
* also registers the getvar caller plugin
* @param \CoreLibs\Language\L10n|null $l10n l10n language class
* if null, auto set
* @param \CoreLibs\Language\L10n $l10n l10n language class
* @param array<string,string> $locale locale data read from setLocale
*/
public function __construct(?\CoreLibs\Language\L10n $l10n = null)
public function __construct(\CoreLibs\Language\L10n $l10n, array $locale)
{
// call basic smarty
// or Smarty::__construct();
parent::__construct();
// set lang vars
$this->setLangEncoding();
// iinit lang
$this->l10n = $l10n ?? new \CoreLibs\Language\L10n($this->lang);
// Smarty 3.x
// $this->registerPlugin('modifier', 'getvar', [&$this, 'get_template_vars']);
$this->l10n = $l10n;
// opt load functions so we can use legacy init for smarty run perhaps
$this->l10n->loadFunctions();
// parse and read, legacy stuff
$this->encoding = $locale['encoding'];
$this->lang = $locale['lang'];
// get first part from lang
$this->lang_short = explode('_', $locale['lang'])[0];
$this->domain = $this->l10n->getDomain();
$this->lang_dir = $this->l10n->getBaseLocalePath();
// register smarty variable
$this->registerPlugin('modifier', 'getvar', [&$this, 'getTemplateVars']);
$this->page_name = pathinfo($_SERVER["PHP_SELF"])['basename'];
$this->page_name = \CoreLibs\Get\System::getPageName();
// set internal settings
$this->CACHE_ID = defined('CACHE_ID') ? CACHE_ID : '';
$this->COMPILE_ID = defined('COMPILE_ID') ? COMPILE_ID : '';
}
/**
* ORIGINAL in \CoreLibs\Admin\Backend
* set the language encoding and language settings
* the default charset from _SESSION login or from
* config DEFAULT ENCODING
* the lang full name for mo loading from _SESSION login
* or SITE LANG or DEFAULT LANG from config
* creates short lang (only first two chars) from the lang
* @return void
*/
private function setLangEncoding(): void
{
list (
$this->encoding,
$this->lang,
$this->lang_short,
$this->domain,
$this->lang_dir
) = \CoreLibs\Language\GetSettings::setLangEncoding();
}
/**
* @return void
*/

View File

@@ -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',
@@ -44,7 +47,7 @@ return array(
'CoreLibs\\Language\\Core\\StreamReader' => $baseDir . '/lib/CoreLibs/Language/Core/StreamReader.php',
'CoreLibs\\Language\\Core\\StringReader' => $baseDir . '/lib/CoreLibs/Language/Core/StringReader.php',
'CoreLibs\\Language\\Encoding' => $baseDir . '/lib/CoreLibs/Language/Encoding.php',
'CoreLibs\\Language\\GetSettings' => $baseDir . '/lib/CoreLibs/Language/GetSettings.php',
'CoreLibs\\Language\\GetLocale' => $baseDir . '/lib/CoreLibs/Language/GetLocale.php',
'CoreLibs\\Language\\L10n' => $baseDir . '/lib/CoreLibs/Language/L10n.php',
'CoreLibs\\Output\\Form\\Elements' => $baseDir . '/lib/CoreLibs/Output/Form/Elements.php',
'CoreLibs\\Output\\Form\\Generate' => $baseDir . '/lib/CoreLibs/Output/Form/Generate.php',

View File

@@ -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',
@@ -109,7 +112,7 @@ class ComposerStaticInit10fe8fe2ec4017b8644d2b64bcf398b9
'CoreLibs\\Language\\Core\\StreamReader' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/Core/StreamReader.php',
'CoreLibs\\Language\\Core\\StringReader' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/Core/StringReader.php',
'CoreLibs\\Language\\Encoding' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/Encoding.php',
'CoreLibs\\Language\\GetSettings' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/GetSettings.php',
'CoreLibs\\Language\\GetLocale' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/GetLocale.php',
'CoreLibs\\Language\\L10n' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/L10n.php',
'CoreLibs\\Output\\Form\\Elements' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/Form/Elements.php',
'CoreLibs\\Output\\Form\\Generate' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/Form/Generate.php',