Make LANGUAGE switchable in runtime (#653)

squashed into a single commit because doing it in steps that all
compiled involved a lot of boilerplate that is pointless to commit to
the repository. GH still has the PR for reference.

g_lang, MAX_MESSAGES_ON_MAP_BOTTOM, and GetLanguagePrefix() were
compile-time constants selected by the ENGLISH/GERMAN/... build
define. They're now runtime, defaulting to the same per-exe value the
define used to pick, and overridable at startup from [Ja2 Settings]
LANGUAGE in Ja2.ini.

-

XMLTacticalMessages is filled at runtime from NewTacticalMessages.xml,
never from compiled-in per-language data: all 8 per-language definitions
were the identical all-zero { L"" }. Delete them and define one shared
buffer in Utils/XML_Language.cpp (the loader) instead of pointer-rebinding
it like the static tables — this drops 9 dead 800KB zero-buffers (8
namespaced copies in LanguageStrings.cpp plus the standalone one) and
leaves no bind-ordering hazard for the XML load path.

-

ExportStrings.cpp privately recompiled one language's full text table
by #including the raw _<LANG>Text.cpp inside namespace Loc, keyed off
the exe-level ENGLISH/GERMAN/... compile macro (whichever the build
happened to select). That's redundant with the pointer globals every
other subsystem already uses (Text.h / LanguageStrings.cpp).

Drop the private copy; the unqualified table names in Loc::ExportStrings
now resolve to the global pointer externs, which BindLanguageStrings has
already rebound to the runtime g_lang by the time this runs (EXPORT_STRINGS
ini flag, checked after GetRuntimeSettings in sgp.cpp). gs_Lang (used only
by Loc::Translate for the Polish/Russian byte remap on raw .edt exports) is
now derived from g_lang via ToLocLanguage, so the export always matches
whatever language is actually active instead of a compile-time pick.

-

Editor/popupmenu.cpp and Strategic/Scheduling.cpp kept their own
call-site extern of gszScheduleActions as CHAR16[NUM_SCHEDULE_ACTIONS][20]
after the real definition changed into a rebindable pointer
(CHAR16 (*)[20], LanguageStrings.cpp). MSVC decays the outer array
dimension when mangling globals, so both declarations produce the same
symbol (?gszScheduleActions@@3PAY0BE@_WA) and the mismatch linked
silently -- but the array-typed TUs then indexed the 4-byte pointer
slot itself as string data, so the editor schedule popup and the map
schedule message text read garbage.

-

add text.def to be single-source of truth on symbol names and use it
 .much simpler, less error prone if adding more strings

-

add pseudo interface for language state. MAX_SAGES_ON_BOTTOM must always
 change in lockstep with g_lang. this isn't foolproof but better

---------

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
majcosta
2026-07-21 05:33:03 -03:00
committed by GitHub
co-authored by Claude Fable 5
parent ba64ed53c6
commit fd2c74727e
56 changed files with 1826 additions and 1482 deletions
+1 -1
View File
@@ -186,7 +186,7 @@ REPAIR_PASS_SLOTS_TYPE gRepairPassSlotList[ NUM_REPAIR_PASS_TYPES ] =
{ /* HEADROCK HAM B2.8: LBE Slot pass */ 0, 5, VESTPOCKPOS, LTHIGHPOCKPOS, RTHIGHPOCKPOS, CPACKPOCKPOS, BPACKPOCKPOS, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
};
extern STR16 sRepairsDoneString[];
extern STR16* sRepairsDoneString;
// PopUp Box Handles
INT32 ghAssignmentBox = -1;
+1 -1
View File
@@ -194,7 +194,7 @@ INT32 iHeightOfInitFastHelpText = 0;
extern INT32 giMapContractButton;
extern INT32 giCharInfoButton[];
extern STR16 pUpdatePanelButtons[];
extern STR16* pUpdatePanelButtons;
// the list of soldiers that are moving
SOLDIERTYPE * pSoldierMovingList[ CODE_MAXIMUM_NUMBER_OF_PLAYER_SLOTS ];
+1 -1
View File
@@ -49,7 +49,7 @@ extern "C" {
extern CHAR16 gzUserDefinedButton1[ 128 ];
extern CHAR16 gzUserDefinedButton2[ 128 ];
extern CHAR16 pTownNames[MAX_TOWNS][MAX_TOWN_NAME_LENGHT];
extern CHAR16 (*pTownNames)[MAX_TOWN_NAME_LENGHT];
static size_t MAX_BUTTON_LENGTH = 60;
static size_t MAX_BODY_LENGTH = 450;
+2 -2
View File
@@ -2,8 +2,8 @@
#define _QUEST_TEXT_H_
STR16 QuestDescText[];
STR16 FactDescText[];
extern STR16 *QuestDescText;
extern STR16 *FactDescText;
#endif
+1 -1
View File
@@ -31,7 +31,7 @@ class SOLDIERTYPE;
#ifdef JA2EDITOR
extern CHAR16 gszScheduleActions[ NUM_SCHEDULE_ACTIONS ][20];
extern CHAR16 (*gszScheduleActions)[20]; // NUM_SCHEDULE_ACTIONS entries
#endif
BOOLEAN GetEarliestMorningScheduleEvent( SCHEDULENODE *pSchedule, UINT32 * puiTime );
+1 -1
View File
@@ -180,7 +180,7 @@ INT16 sWorldSectorLocationOfFirstBattle = 0;
// preprocess sector for mercs in it
extern BOOLEAN fSectorsWithSoldiers[ MAP_WORLD_X * MAP_WORLD_X ][ 4 ];
extern CHAR16 pTownNames[MAX_TOWNS][MAX_TOWN_NAME_LENGHT];
extern CHAR16 (*pTownNames)[MAX_TOWN_NAME_LENGHT];
+2 -2
View File
@@ -613,8 +613,8 @@ extern BOOLEAN gfAutoAIAware;
extern void HandlePreBattleInterfaceStates();
// the title for the contract button on the character info panel in the upper left portion of the mapscreen
extern STR16 pContractButtonString[];
extern STR16 pBullseyeStrings[];
extern STR16* pContractButtonString;
extern STR16* pBullseyeStrings;
extern OBJECTTYPE *gpItemDescObject;
+1 -1
View File
@@ -357,7 +357,7 @@ extern HVSURFACE ghFrameBuffer;
extern BOOLEAN gfOverrideSector;
extern BOOLEAN sBadSectorsList[WORLD_MAP_X][WORLD_MAP_X];
extern STR16 pBullseyeStrings[];
extern STR16* pBullseyeStrings;
extern void HandleRPCDescription( );