Fix Italian and Spanish locale handling (#394)

This commit is contained in:
Fabian
2026-10-18 07:21:28 +03:00
committed by GitHub
parent 17acbd3bc0
commit 43e0c9dfa7
4 changed files with 117 additions and 6 deletions
+2 -2
View File
@@ -58,7 +58,7 @@ trait DatabaseUserQueries {
? strtolower(trim((string) SERVER_LANG))
: 'en';
$allowedLanguages = ['en', 'fr', 'it', 'ro', 'zh'];
$allowedLanguages = ['en', 'es', 'fr', 'it', 'ro', 'zh'];
if (!in_array($serverLang, $allowedLanguages, true)) {
$serverLang = 'en';
@@ -923,4 +923,4 @@ trait DatabaseUserQueries {
}
return empty($errors) ? true : $errors;
}
}
}
-2
View File
@@ -2257,6 +2257,4 @@ tz_def('MANUAL_INTRO', "Questo aiuto di gioco ti permette di consultare informaz
tz_def('MANUAL_NEW_FEATURES_DESC', "Queste sono novità che non troverai nella versione reale del gioco Travian T3.6. Qui puoi conoscere tutte le novità in dettaglio.");
tz_def('MANUAL_FAQ', 'FAQ Travian');
tz_def('MANUAL_FAQ_DESC', "Questo aiuto di gioco fornisce solo brevi informazioni. Maggiori informazioni sono disponibili sul");
?>
tz_def('ADM_SPANISH', 'Spagnolo');
+19 -2
View File
@@ -30,10 +30,16 @@ function run_language_case($language)
'tribe' => 'Romains',
'welcome' => 'Bienvenue sur le Test Server!',
],
'es' => [
'tribe' => 'Romanos',
'welcome' => 'Welcome to Test Server',
'spanish_label' => 'Espanol',
],
'it' => [
'tribe' => 'Romani',
'welcome' => 'Benvenuto in Test Server',
'fallback' => ['TRIBE7', 'Egyptians'],
'spanish_label' => 'Spagnolo',
],
'ro' => [
'tribe' => 'Romani',
@@ -60,8 +66,11 @@ function run_language_case($language)
define('SPEED', 1);
require dirname(__DIR__) . '/GameEngine/Lang/loader.php';
ob_start();
$loaded = tz_load_language($language);
$unexpectedOutput = ob_get_clean();
assert_same('', $unexpectedOutput, $language . ': loading a locale must not emit output');
assert_same($expected[$language]['tribe'], TRIBE1, $language . ': selected constants must win');
assert_same(
$expected[$language]['welcome'],
@@ -75,6 +84,14 @@ function run_language_case($language)
assert_same($value, constant($constant), $language . ': missing constant must fall back to English');
}
if (isset($expected[$language]['spanish_label'])) {
assert_same(
$expected[$language]['spanish_label'],
ADM_SPANISH,
$language . ': selected locale must define the Spanish language label'
);
}
$fixtureDirectory = __DIR__ . '/fixtures/languages';
$fixture = tz_load_language('xx', $fixtureDirectory);
assert_same(
@@ -118,7 +135,7 @@ if (isset($argv[1])) {
exit(0);
}
$languages = ['en', 'fr', 'it', 'ro', 'zh'];
$languages = ['en', 'es', 'fr', 'it', 'ro', 'zh'];
foreach ($languages as $language) {
$pipes = [];
$process = proc_open(
@@ -149,4 +166,4 @@ foreach ($languages as $language) {
echo $stdout;
}
echo "PASS language loader: 5 locales\n";
echo "PASS language loader: 6 locales\n";
@@ -0,0 +1,96 @@
<?php
if (!isset($argv[1])) {
foreach (['es' => 'es', 'invalid' => 'en'] as $configured => $expected) {
$command = escapeshellarg(PHP_BINARY)
. ' '
. escapeshellarg(__FILE__)
. ' '
. escapeshellarg($configured)
. ' '
. escapeshellarg($expected);
passthru($command, $status);
if ($status !== 0) {
exit($status);
}
}
fwrite(STDOUT, "Registration language regression test passed.\n");
exit(0);
}
define('USER', 2);
define('TB_PREFIX', 'test_');
define('SERVER_LANG', $argv[1]);
define('START_DATE', date('d.m.Y'));
define('START_TIME', '00:00');
define('PROTECTION', 0);
require_once __DIR__ . '/../../GameEngine/Database/DatabaseUserQueries.php';
final class RegistrationLanguageStatement
{
public $insert_id = 42;
public function bind_param($types, &...$values)
{
}
public function execute()
{
return true;
}
public function close()
{
}
}
final class RegistrationLanguageConnection
{
public function prepare($query)
{
return new RegistrationLanguageStatement();
}
}
final class RegistrationLanguageHarness
{
use DatabaseUserQueries;
public $dblink;
public $language;
public function __construct()
{
$this->dblink = new RegistrationLanguageConnection();
}
public function updateUserField($ref, $field, $value, $switch)
{
if ($field === 'lang') {
$this->language = $value;
}
}
private function grantRegistrationGold($id)
{
}
}
$database = new RegistrationLanguageHarness();
$id = $database->register('player', 'password', '[email protected]', 1, '');
if ($id !== 42) {
fwrite(STDERR, "Registration did not return the inserted account ID.\n");
exit(1);
}
if ($database->language !== $argv[2]) {
fwrite(
STDERR,
"Expected registration language {$argv[2]}; got {$database->language}.\n"
);
exit(1);
}