mirror of
https://github.com/1dot13/source.git
synced 2026-07-22 13:40:22 +02:00
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>
141 lines
3.0 KiB
C++
141 lines
3.0 KiB
C++
// All eight languages' string tables in one translation unit (docs/plans/
|
|
// language-design.md): each base + Ja2.5-carryover text file is included inside its
|
|
// own per-language namespace, the game-facing table symbols are the pointer globals
|
|
// below (statically bound to the build default), and BindLanguageStrings rebinds all
|
|
// of them to the language resolved at startup from the LANGUAGE ini key.
|
|
|
|
#include "Text.h"
|
|
#include "FileMan.h"
|
|
#include "Scheduling.h"
|
|
#include "EditorMercs.h"
|
|
#include "Item Statistics.h"
|
|
|
|
#include <language.hpp>
|
|
|
|
#include <type_traits>
|
|
|
|
// Recipe R1 (docs/plans/language-design.md): the loose _<LANG>Text.cpp files are still
|
|
// compiled standalone until Cn+2, and #include the headers declaring the now-pointer
|
|
// externs themselves; this guard keeps their array definitions out of those standalone
|
|
// TUs (which would collide with the pointer extern) while still compiling them here.
|
|
|
|
namespace lang_en {
|
|
#include "_EnglishText.cpp"
|
|
#include "_Ja25EnglishText.cpp"
|
|
}
|
|
|
|
namespace lang_de {
|
|
#include "_GermanText.cpp"
|
|
#include "_Ja25GermanText.cpp"
|
|
}
|
|
|
|
namespace lang_ru {
|
|
#include "_RussianText.cpp"
|
|
#include "_Ja25RussianText.cpp"
|
|
}
|
|
|
|
namespace lang_nl {
|
|
#include "_DutchText.cpp"
|
|
#include "_Ja25DutchText.cpp"
|
|
}
|
|
|
|
namespace lang_pl {
|
|
#include "_PolishText.cpp"
|
|
#include "_Ja25PolishText.cpp"
|
|
}
|
|
|
|
namespace lang_fr {
|
|
#include "_FrenchText.cpp"
|
|
#include "_Ja25FrenchText.cpp"
|
|
}
|
|
|
|
namespace lang_it {
|
|
#include "_ItalianText.cpp"
|
|
#include "_Ja25ItalianText.cpp"
|
|
}
|
|
|
|
namespace lang_zh {
|
|
#include "_ChineseText.cpp"
|
|
#include "_Ja25ChineseText.cpp"
|
|
}
|
|
|
|
namespace lang_default = lang_en;
|
|
|
|
// definitions (default language)
|
|
#define X(NAME) \
|
|
std::decay_t<decltype(lang_default::NAME)> NAME = lang_default::NAME;
|
|
#include "text.def"
|
|
#undef X
|
|
|
|
namespace {
|
|
auto bind_en() -> void {
|
|
#define X(NAME) NAME = lang_en::NAME;
|
|
#include "text.def"
|
|
#undef X
|
|
}
|
|
auto bind_de() -> void {
|
|
#define X(NAME) NAME = lang_de::NAME;
|
|
#include "text.def"
|
|
#undef X
|
|
}
|
|
auto bind_ru() -> void {
|
|
#define X(NAME) NAME = lang_ru::NAME;
|
|
#include "text.def"
|
|
#undef X
|
|
}
|
|
auto bind_nl() -> void {
|
|
#define X(NAME) NAME = lang_nl::NAME;
|
|
#include "text.def"
|
|
#undef X
|
|
}
|
|
auto bind_pl() -> void {
|
|
#define X(NAME) NAME = lang_pl::NAME;
|
|
#include "text.def"
|
|
#undef X
|
|
}
|
|
auto bind_fr() -> void {
|
|
#define X(NAME) NAME = lang_fr::NAME;
|
|
#include "text.def"
|
|
#undef X
|
|
}
|
|
auto bind_it() -> void {
|
|
#define X(NAME) NAME = lang_it::NAME;
|
|
#include "text.def"
|
|
#undef X
|
|
}
|
|
auto bind_zh() -> void {
|
|
#define X(NAME) NAME = lang_zh::NAME;
|
|
#include "text.def"
|
|
#undef X
|
|
}
|
|
} // namespace
|
|
|
|
auto BindLanguageStrings(i18n::Lang lang) -> void {
|
|
switch (lang) {
|
|
case i18n::Lang::en:
|
|
bind_en();
|
|
break;
|
|
case i18n::Lang::de:
|
|
bind_de();
|
|
break;
|
|
case i18n::Lang::ru:
|
|
bind_ru();
|
|
break;
|
|
case i18n::Lang::nl:
|
|
bind_nl();
|
|
break;
|
|
case i18n::Lang::pl:
|
|
bind_pl();
|
|
break;
|
|
case i18n::Lang::fr:
|
|
bind_fr();
|
|
break;
|
|
case i18n::Lang::it:
|
|
bind_it();
|
|
break;
|
|
case i18n::Lang::zh:
|
|
bind_zh();
|
|
break;
|
|
}
|
|
}
|