Add per-user language selection (issue #166)

The profile already had a language selector (Templates/Profile/preference.tpl)
that saved the choice into users.lang and $_SESSION['lang'], but the saved
preference was never used to actually load the language: every page loads
include("Lang/".LANG.".php") with the server-wide LANG constant, so changing
the language in the profile had no visible effect.

This wires it up:

- Introduce SERVER_LANG (the server default) and make LANG the EFFECTIVE
  display language, resolved from the player's saved preference
  ($_SESSION['lang']) with a fallback to SERVER_LANG
  (install/data/constant_format.tpl).
  SECURITY: the value is sanitized to [a-z_] and the target Lang/<x>.php
  file must exist, otherwise we fall back to the server default. This
  prevents Local File Inclusion via include("Lang/".LANG.".php").

- Seed $_SESSION['lang'] from users.lang on login (GameEngine/Session.php,
  PopulateVar), so the chosen language applies right after logging in.

- Keep the SERVER default intact when an admin saves settings: the admin
  config regenerators and the "Server Settings"/config displays now use
  SERVER_LANG (the server default) instead of the per-user LANG, so an
  admin browsing in their own language can't accidentally overwrite the
  server default (6 Admin/Mods/edit*.php + editServerSet.tpl + config.tpl).

Note: existing installs must also add SERVER_LANG + the LANG resolution to
their generated GameEngine/config.php (and the Admin/Mods/constant_format.tpl
copy) since config is generated at install time.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
TravianZ Patcher
2026-06-04 09:07:57 +02:00
parent 11ce6e6052
commit 421915f774
10 changed files with 38 additions and 15 deletions
+6 -6
View File
@@ -70,12 +70,12 @@ function refresh(tz) {
<td><?php echo CONF_SERV_LANG ?> <em class="tooltip">?<span class="classic"><?php echo CONF_SERV_LANG_TOOLTIP ?></span></em></td>
<td>
<select name="lang">
<option value="en" <?php if (LANG=="en") echo "selected";?>>English</option>
<option value="fr" <?php if (LANG=="fr") echo "selected";?>>French</option>
<option value="es" <?php if (LANG=="es") echo "selected";?>>Spain</option>
<option value="rs" <?php if (LANG=="rs") echo "selected";?>>Serbian</option>
<option value="ru" <?php if (LANG=="ro") echo "selected";?>>Romanian</option>
<option value="zh_tw" <?php if (LANG=="zh_tw") echo "selected";?>>Taiwanese</option>
<option value="en" <?php if ((defined('SERVER_LANG') ? SERVER_LANG : LANG)=="en") echo "selected";?>>English</option>
<option value="fr" <?php if ((defined('SERVER_LANG') ? SERVER_LANG : LANG)=="fr") echo "selected";?>>French</option>
<option value="es" <?php if ((defined('SERVER_LANG') ? SERVER_LANG : LANG)=="es") echo "selected";?>>Spain</option>
<option value="rs" <?php if ((defined('SERVER_LANG') ? SERVER_LANG : LANG)=="rs") echo "selected";?>>Serbian</option>
<option value="ru" <?php if ((defined('SERVER_LANG') ? SERVER_LANG : LANG)=="ro") echo "selected";?>>Romanian</option>
<option value="zh_tw" <?php if ((defined('SERVER_LANG') ? SERVER_LANG : LANG)=="zh_tw") echo "selected";?>>Taiwanese</option>
</select>
</td>
</tr>