Updates for language auto detect, fixes for PHP 7.4

There was a bug in ther SQL interface class where the folder was just
called "Interface" which is not an allowed Namespace name. Renamed to
SqlInterface

Moved the detect lang/etc function used in Form/Generate,
Template/SmartyExtend and Admin/Backend to Language/GetSettings.

Fixed some test class calls
This commit is contained in:
Clemens Schwaighofer
2022-04-07 10:49:28 +09:00
parent f8ee6044f9
commit e463f48ad4
13 changed files with 255 additions and 109 deletions

View File

@@ -16,7 +16,7 @@
* PUBLIC METHODS
* __: returns string (translated or original if not found)
* __e: echos out string (translated or original if not found)
* __ngettext: should return plural. never tested this.
* __n: should return plural. never tested this.
*
* PRIVATE METHODS
*
@@ -24,6 +24,13 @@
* 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;
@@ -106,12 +113,30 @@ class L10n
return $success;
}
/**
* get current set language
* @return string current set language string
*/
public function __getLang(): string
{
return $this->lang;
}
/**
* get current set mo file
* @return string current set mo language file
*/
public function __getMoFile(): string
{
return $this->mofile;
}
/**
* translates a string and returns translated text
* @param string $text text to translate
* @return string translated text
*/
public function __($text): string
public function __(string $text): string
{
return $this->l10n->translate($text);
}
@@ -121,7 +146,7 @@ class L10n
* @param string $text text to translate
* @return void has no return
*/
public function __e($text): void
public function __e(string $text): void
{
echo $this->l10n->translate($text);
}
@@ -129,33 +154,46 @@ class L10n
// Return the plural form.
/**
* Return the plural form.
* @param string $single string for single word
* @param string $plural string for plural word
* @param string $number number value
* @return string translated plural string
* @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
*/
public function __ngettext($single, $plural, $number)
public function __n(string $single, string $plural, $number): string
{
return $this->l10n->ngettext($single, $plural, $number);
}
// alias functions to mimic gettext calls
/**
* get current set language
* @return string current set language string
* Undocumented function
*
* @param string $text
* @return string
*/
public function __getLang()
public function gettext(string $text): string
{
return $this->lang;
return $this->__($text);
}
/**
* get current set mo file
* @return string current set mo language file
* Undocumented function
*
* @param string $single
* @param string $plural
* @param int|float $number
* @return string
*/
public function __getMoFile()
public function ngettext(string $single, string $plural, $number): string
{
return $this->mofile;
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
}
// __END__