Vigiar
1
0
Derivar
Você já tinha feito uma derivação do repositório whmcs-domains-module, anteriormente
0
whmcs-domains-module/modules/registrars/mozout_domains/lib/I18n.php
2026-11-28 15:28:08 +02:00

135 linhas
4,3 KiB
PHP

<?php
/**
* Language files of the module: lang/english.php and lang/portuguese.php.
* Any WHMCS language whose name starts with "portuguese" (portuguese-pt,
* portuguese-br, portuguese-mz...) uses portuguese.php; every other language
* uses english.php. A key missing in portuguese.php falls back to English.
* In the admin area the texts follow the admin's language, in the client area
* the client's language, and elsewhere (cron) the WHMCS default language.
*/
namespace MozoutDomains;
if (!defined('WHMCS')) {
die('This file cannot be accessed directly');
}
class I18n
{
private static $files = array();
/** 'pt' for a language name that starts with "portuguese" (or is "pt"), 'en' for the rest. */
public static function code($name)
{
$name = strtolower(trim((string) $name));
return ($name === 'pt' || strpos($name, 'portugu') === 0) ? 'pt' : 'en';
}
/** Text of a key in 'en' or 'pt'; falls back to English, then to the key itself. */
public static function t($lang, $key)
{
if ($lang === 'pt') {
$pt = self::file('portuguese');
if (isset($pt[$key])) {
return $pt[$key];
}
}
$en = self::file('english');
return isset($en[$key]) ? $en[$key] : $key;
}
private static function file($name)
{
if (!isset(self::$files[$name])) {
$path = dirname(__DIR__) . '/lang/' . $name . '.php';
$data = is_file($path) ? include $path : array();
self::$files[$name] = is_array($data) ? $data : array();
}
return self::$files[$name];
}
/** The WHMCS default language (General Settings). */
public static function system()
{
try {
if (class_exists('\WHMCS\Config\Setting')) {
$v = \WHMCS\Config\Setting::getValue('Language');
if ($v) {
return self::code($v);
}
}
} catch (\Throwable $e) {
/* no database yet: English */
}
return 'en';
}
/** The language of the admin who is logged in. */
public static function admin()
{
if (!empty($_SESSION['adminlang'])) {
return self::code($_SESSION['adminlang']);
}
if (!empty($_SESSION['adminid'])) {
try {
$l = \WHMCS\Database\Capsule::table('tbladmins')->where('id', (int) $_SESSION['adminid'])->value('language');
if ($l) {
return self::code($l);
}
} catch (\Throwable $e) {
/* falls back to the default language */
}
}
return self::system();
}
/** The language of the client: the one chosen in the session, the active one or the profile one. */
public static function client(array $params = array())
{
if (!empty($_SESSION['Language'])) {
return self::code($_SESSION['Language']);
}
try {
if (class_exists('\Lang') && is_callable(array('\Lang', 'getName'))) {
$l = \Lang::getName();
if ($l) {
return self::code($l);
}
}
} catch (\Throwable $e) {
/* older WHMCS */
}
if (!empty($params['clientsdetails']['language'])) {
return self::code($params['clientsdetails']['language']);
}
return self::system();
}
/** Admin language in the admin area, client language in the client area, default language elsewhere. */
public static function context(array $params = array())
{
if (defined('ADMINAREA')) {
return self::admin();
}
if (defined('CLIENTAREA')) {
return self::client($params);
}
return self::system();
}
/**
* The "Message language" setting of the module: "auto" follows the context;
* "en" or "pt" forces it. Older values ("English", "Português") still work.
*/
public static function setting($value, array $params = array())
{
$v = strtolower(trim((string) $value));
if ($v === 'en' || $v === 'english') {
return 'en';
}
if ($v === 'pt' || strpos($v, 'portugu') === 0) {
return 'pt';
}
return self::context($params);
}
}