From cdc736839e65b5113413443c1f4b8ea337aead30 Mon Sep 17 00:00:00 2001 From: Ferywir <65760459+Ferywir@users.noreply.github.com> Date: Thu, 18 Jun 2026 09:22:15 +0200 Subject: [PATCH] i18n(alliance): render alliance news-feed notices in each reader's language (EN/FR/RO) (#238) --- GameEngine/Alliance.php | 43 +++++++++++++++++++------------------ GameEngine/Lang/en.php | 14 ++++++++++++ GameEngine/Lang/fr.php | 14 ++++++++++++ GameEngine/Lang/ro.php | 14 ++++++++++++ Templates/Alliance/news.tpl | 2 +- 5 files changed, 65 insertions(+), 22 deletions(-) diff --git a/GameEngine/Alliance.php b/GameEngine/Alliance.php index b2383ca6..c2d22434 100755 --- a/GameEngine/Alliance.php +++ b/GameEngine/Alliance.php @@ -263,11 +263,11 @@ class Alliance { // Log notice în alianță $database->insertAlliNotice( $session->alliance, - '' . - addslashes($session->username) . - ' has invited ' . - addslashes($UserData['username']) . - ' into the alliance.' + rc_tok( + 'MSG_INVITE_NOTICE', + '' . addslashes($session->username) . '', + '' . addslashes($UserData['username']) . '' + ) ); // Trimite invitație și prin mesaj în joc (dacă este activată funcționalitatea nouă) if (NEW_FUNCTIONS_ALLIANCE_INVITATION) { @@ -290,8 +290,8 @@ class Alliance { // Ștergem invitația din baza de date $database->removeInvitation($inviteID); // Adăugăm notice în logul alianței - $notice = '' . addslashes($session->username) . ' has rejected the invitation.'; - $database->insertAlliNotice($invite['alliance'], $notice); + $notice = rc_tok('MSG_NEWS_REJECTED', '' . addslashes($session->username) . ''); + $database->insertAlliNotice($invite['alliance'], $notice); break; // am găsit și procesat invitația → nu mai continuăm bucla } } @@ -318,7 +318,7 @@ class Alliance { // Ștergem invitația $database->removeInvitation($inviteID); // Adăugăm notice în logul alianței - $notice = '' . addslashes($session->username) . ' has deleted the invitation for ' . addslashes($invitename['username']) . '.'; + $notice = rc_tok('MSG_NEWS_DELETED_INVITE', '' . addslashes($session->username) . '', '' . addslashes($invitename['username']) . ''); $database->insertAlliNotice($session->alliance, $notice); break; // am procesat invitația → ieșim din buclă } @@ -349,7 +349,7 @@ class Alliance { $database->updateUserField($invite['uid'], "alliance", $invite['alliance'], 1); $database->createAlliPermissions($invite['uid'], $invite['alliance'], '', 0, 0, 0, 0, 0, 0, 0, 0); // Log notice în alianță - $notice = '' . addslashes($session->username) . ' has joined the alliance.'; + $notice = rc_tok('MSG_NEWS_JOINED', '' . addslashes($session->username) . ''); $database->insertAlliNotice($invite['alliance'], $notice); } else { // Alianța este plină @@ -397,7 +397,7 @@ class Alliance { $database->updateUserField($session->uid, "alliance", $aid, 1); $database->procAllyPop($aid); $database->createAlliPermissions($session->uid, $aid, 'Alliance founder', '1', '1', '1', '1', '1', '1', '1', '1'); - $notice = 'The alliance has been founded by ' . addslashes($session->username) . '.'; + $notice = rc_tok('MSG_ALLIANCE_FOUNDED', '' . addslashes($session->username) . ''); $database->insertAlliNotice($aid, $notice); header("Location: build.php?gid=18"); exit; @@ -421,7 +421,7 @@ class Alliance { // ==================== ERORI ? ==================== if ($form->returnErrors() == 0) { $database->setAlliName($session->alliance, $newName, $newTag); - $notice = '' . addslashes($session->username) . ' has changed the alliance name.'; + $notice = rc_tok('MSG_NEWS_NAME_CHANGED', '' . addslashes($session->username) . ''); $database->insertAlliNotice($session->alliance, $notice); $form->addError("perm", NAME_OR_TAG_CHANGED); $_SESSION['errorarray'] = $form->getErrors(); @@ -447,7 +447,7 @@ class Alliance { // ==================== ACTUALIZARE PROFIL ==================== $database->submitAlliProfile($session->alliance, $post['be2'] ?? '', $post['be1'] ?? ''); // Log notice în alianță - $notice = '' . addslashes($session->username) . ' has changed the alliance description.'; + $notice = rc_tok('MSG_NEWS_DESC_CHANGED', '' . addslashes($session->username) . ''); $database->insertAlliNotice($session->alliance, $notice); } } @@ -494,7 +494,7 @@ class Alliance { } else { // Log notice în alianță $username = $database->getUserField($targetUID, "username", 0); - $notice = '' . addslashes($session->username) . ' has changed permissions of ' . addslashes($username) . '.'; + $notice = rc_tok('MSG_NEWS_PERMS_CHANGED', '' . addslashes($session->username) . '', addslashes($username)); $database->insertAlliNotice($session->alliance, $notice); // Mesaj de succes (comportament original) $_SESSION['success'] = ALLY_PERMISSIONS_UPDATED; @@ -536,7 +536,7 @@ class Alliance { $kickedUsername = $UserData['username']; $database->evictUserFromAlliance($targetUID); $database->deleteAlliPermissions($targetUID); - $notice = '' . addslashes($kickedUsername) . ' has been expelled from the alliance by ' . addslashes($session->username) . '.'; + $notice = rc_tok('MSG_NEWS_EXPELLED', '' . addslashes($kickedUsername) . '', '' . addslashes($session->username) . ''); $database->insertAlliNotice($allyId, $notice); $database->deleteAlliance($allyId); $form->addError("perm", $kickedUsername . ALLY_USER_KICKED); @@ -606,7 +606,7 @@ class Alliance { $database->deleteAlliPermissions($uid); // șterge alianța dacă e goală (comportament original) $database->deleteAlliance($allyId); - $notice = '' . addslashes($session->username) . ' has quit the alliance.'; + $notice = rc_tok('MSG_NEWS_QUIT', '' . addslashes($session->username) . ''); $database->insertAlliNotice($allyId, $notice); header("Location: spieler.php?uid=" . $uid); exit; @@ -630,13 +630,14 @@ class Alliance { if (!$database->diplomacyCheckLimits($session->alliance, $diplType)) { $form->addError("name", ALLY_TOO_MUCH_PACTS); return; } $database->diplomacyInviteAdd($session->alliance, $targetAllianceID, $diplType); - if ($diplType == 1) $noticeText = OFFERED_CONFED_TO; - elseif ($diplType == 2) $noticeText = OFFERED_NON_AGGRESION_PACT_TO; - elseif ($diplType == 3) $noticeText = DECLARED_WAR_ON; - else $noticeText = ''; + if ($diplType == 1) $diploKey = 'MSG_NEWS_DIPLO_CONFED'; + elseif ($diplType == 2) $diploKey = 'MSG_NEWS_DIPLO_NAP'; + elseif ($diplType == 3) $diploKey = 'MSG_NEWS_DIPLO_WAR'; + else $diploKey = ''; $myAllianceName = $database->getAllianceName($session->alliance); - $database->insertAlliNotice($session->alliance, '' . $myAllianceName . ' ' . $noticeText . ' ' . $targetAllianceName . '.'); - $database->insertAlliNotice($targetAllianceID, '' . $myAllianceName . ' ' . $noticeText . ' ' . $targetAllianceName . '.'); + $notice = ($diploKey === '') ? '' : rc_tok($diploKey, '' . $myAllianceName . '', '' . $targetAllianceName . ''); + $database->insertAlliNotice($session->alliance, $notice); + $database->insertAlliNotice($targetAllianceID, $notice); $form->addError("name", INVITE_SENT); } } diff --git a/GameEngine/Lang/en.php b/GameEngine/Lang/en.php index d1b2281a..b0f47733 100755 --- a/GameEngine/Lang/en.php +++ b/GameEngine/Lang/en.php @@ -283,6 +283,20 @@ tz_def('MSG_QUIT_REPLACEMENT_BODY', "Hi!\n\nThis is to inform you that the forme // Embassy-destruction status lines, appended to the catapult battle report. tz_def('MSG_ALLIANCE_DISPERSED_STATUS', "This player's alliance has been dispersed."); tz_def('MSG_FORCED_LEAVE_STATUS', 'Player was forced to leave their alliance.'); +// Alliance news-feed notices (rendered in Templates/Alliance/news.tpl) +tz_def('MSG_INVITE_NOTICE', '%s has invited %s into the alliance.'); +tz_def('MSG_ALLIANCE_FOUNDED', 'The alliance has been founded by %s.'); +tz_def('MSG_NEWS_REJECTED', '%s has rejected the invitation.'); +tz_def('MSG_NEWS_DELETED_INVITE', '%s has deleted the invitation for %s.'); +tz_def('MSG_NEWS_JOINED', '%s has joined the alliance.'); +tz_def('MSG_NEWS_NAME_CHANGED', '%s has changed the alliance name.'); +tz_def('MSG_NEWS_DESC_CHANGED', '%s has changed the alliance description.'); +tz_def('MSG_NEWS_PERMS_CHANGED', '%s has changed permissions of %s.'); +tz_def('MSG_NEWS_EXPELLED', '%s has been expelled from the alliance by %s.'); +tz_def('MSG_NEWS_QUIT', '%s has quit the alliance.'); +tz_def('MSG_NEWS_DIPLO_CONFED', '%s offered a confederation to %s.'); +tz_def('MSG_NEWS_DIPLO_NAP', '%s offered non-aggression pact to %s.'); +tz_def('MSG_NEWS_DIPLO_WAR', '%s declared war to %s.'); tz_def('CARRY', 'carry'); tz_def('DEFENDER', 'Defender'); tz_def('VISITED', 'visited'); diff --git a/GameEngine/Lang/fr.php b/GameEngine/Lang/fr.php index a158622a..45210cd5 100644 --- a/GameEngine/Lang/fr.php +++ b/GameEngine/Lang/fr.php @@ -280,6 +280,20 @@ define('MSG_QUIT_REPLACEMENT_BODY', "Bonjour !\n\nNous vous informons que l'anci // Embassy-destruction status lines, appended to the catapult battle report. define('MSG_ALLIANCE_DISPERSED_STATUS', "L'alliance de ce joueur a été dispersée."); define('MSG_FORCED_LEAVE_STATUS', "Le joueur a été forcé de quitter son alliance."); +// Alliance news-feed notices (rendered in Templates/Alliance/news.tpl) +define('MSG_INVITE_NOTICE', "%s a invité %s à rejoindre l'alliance."); +define('MSG_ALLIANCE_FOUNDED', "L'alliance a été fondée par %s."); +define('MSG_NEWS_REJECTED', "%s a refusé l'invitation."); +define('MSG_NEWS_DELETED_INVITE', "%s a supprimé l'invitation de %s."); +define('MSG_NEWS_JOINED', "%s a rejoint l'alliance."); +define('MSG_NEWS_NAME_CHANGED', "%s a changé le nom de l'alliance."); +define('MSG_NEWS_DESC_CHANGED', "%s a changé la description de l'alliance."); +define('MSG_NEWS_PERMS_CHANGED', "%s a modifié les permissions de %s."); +define('MSG_NEWS_EXPELLED', "%s a été expulsé de l'alliance par %s."); +define('MSG_NEWS_QUIT', "%s a quitté l'alliance."); +define('MSG_NEWS_DIPLO_CONFED', "%s a proposé une confédération à %s."); +define('MSG_NEWS_DIPLO_NAP', "%s a proposé un pacte de non-agression à %s."); +define('MSG_NEWS_DIPLO_WAR', "%s a déclaré la guerre à %s."); define('CARRY', 'transporte'); define('DEFENDER', 'Défenseur'); define('VISITED', 'visité'); diff --git a/GameEngine/Lang/ro.php b/GameEngine/Lang/ro.php index 0b71ff85..5d2b5c8c 100644 --- a/GameEngine/Lang/ro.php +++ b/GameEngine/Lang/ro.php @@ -280,6 +280,20 @@ define('MSG_QUIT_REPLACEMENT_BODY', "Salut!\n\nTe informăm că fostul lider al // Embassy-destruction status lines, appended to the catapult battle report. define('MSG_ALLIANCE_DISPERSED_STATUS', 'Alianța acestui jucător a fost dispersată.'); define('MSG_FORCED_LEAVE_STATUS', 'Jucătorul a fost forțat să-și părăsească alianța.'); +// Alliance news-feed notices (rendered in Templates/Alliance/news.tpl) +define('MSG_INVITE_NOTICE', '%s l-a invitat pe %s în alianță.'); +define('MSG_ALLIANCE_FOUNDED', 'Alianța a fost fondată de %s.'); +define('MSG_NEWS_REJECTED', '%s a refuzat invitația.'); +define('MSG_NEWS_DELETED_INVITE', '%s a șters invitația pentru %s.'); +define('MSG_NEWS_JOINED', '%s s-a alăturat alianței.'); +define('MSG_NEWS_NAME_CHANGED', '%s a schimbat numele alianței.'); +define('MSG_NEWS_DESC_CHANGED', '%s a schimbat descrierea alianței.'); +define('MSG_NEWS_PERMS_CHANGED', '%s a modificat permisiunile lui %s.'); +define('MSG_NEWS_EXPELLED', '%s a fost exclus din alianță de către %s.'); +define('MSG_NEWS_QUIT', '%s a părăsit alianța.'); +define('MSG_NEWS_DIPLO_CONFED', '%s a oferit o confederație către %s.'); +define('MSG_NEWS_DIPLO_NAP', '%s a oferit un pact de neagresiune către %s.'); +define('MSG_NEWS_DIPLO_WAR', '%s a declarat război către %s.'); define('CARRY', 'transportă'); define('DEFENDER', 'Apărător'); define('VISITED', 'vizitat'); diff --git a/Templates/Alliance/news.tpl b/Templates/Alliance/news.tpl index 61746af4..dcf890c3 100644 --- a/Templates/Alliance/news.tpl +++ b/Templates/Alliance/news.tpl @@ -64,7 +64,7 @@ if (!empty($noticeArray)) { echo "