Skip to content

Commit

Permalink
Move LanguageStrings.cmake to a C Macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Nopey committed Jan 4, 2025
1 parent a842f5a commit 4624a25
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 123 deletions.
33 changes: 4 additions & 29 deletions cmake-scripts/BuildLanguages.cmake
Original file line number Diff line number Diff line change
@@ -1,39 +1,12 @@
#
# BuildLanguages.cmake has two jobs:
# - it generates src/resources/generated_languages.h from LanguageStrings.cmake, and
# - if option BUILD_LANGUAGES is on, builds the .LNG files from resources/translations/*.TXT
# BuildLanguages.cmake has one job:
# if option BUILD_LANGUAGES is on, builds the .LNG files from resources/translations/*.TXT
#

macro(lang_str enum_name)
if(${ARGC} GREATER 1)
set(count "${ARGV1}")

if(${count} LESS 1)
message(FATAL_ERROR "Cannot add less than 1 of lang_str '${enum_name}'.")
endif()

string(APPEND LANG_ENUM "\n ${enum_name} = ${Lang_Count},")
string(APPEND LANG_ENUM "\n ${enum_name}_Last = ${Lang_Count} + (${count} - 1),\n")
math(EXPR Lang_Count "${Lang_Count} + ${count}")
else()
string(APPEND LANG_ENUM "\n ${enum_name} = ${Lang_Count},\n")
math(EXPR Lang_Count "${Lang_Count} + 1")
endif()
endmacro()
set(Lang_Count 0)
set(LANG_ENUM "")
include("cmake-scripts/LanguageStrings.cmake")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/resources/generated_languages.h.in" "${CMAKE_CURRENT_BINARY_DIR}/src/resources/generated_languages.h")

message(STATUS "BuildLanguages' Lang_Count: ${Lang_Count}")


if(NOT BUILD_LANGUAGES)
# early out, having written generated_languages.h
return()
endif()


if(WIN32)
set(LANGUAGE_INSTALL_PATH "openomf/resources/")
else()
Expand All @@ -48,6 +21,8 @@ file(GLOB OPENOMF_LANGS
"${LANG_SRC}/*.TXT"
)

file(READ "${LANG_SRC}/langstr_count" Lang_Count)

# generate custom target info
set(BUILD_LANG_COMMANDS)
set(BUILD_LANG_SOURCES)
Expand Down
77 changes: 0 additions & 77 deletions cmake-scripts/LanguageStrings.cmake

This file was deleted.

16 changes: 0 additions & 16 deletions src/resources/generated_languages.h.in

This file was deleted.

93 changes: 92 additions & 1 deletion src/resources/languages.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef LANGUAGES_H
#define LANGUAGES_H

#include "resources/generated_languages.h"
#include <stdbool.h>

/*
Expand Down Expand Up @@ -31,4 +30,96 @@ const char *lang_get(int id);
#define lang_get_offset(LangStr, offset) lang_get_offset_impl(LangStr, LangStr##_Last, (offset))
const char *lang_get_offset_impl(int id, int last, int offset);

#define lang_str(enum_variant) enum_variant
#define lang_str_range(enum_variant, count) enum_variant, enum_variant##_Last = enum_variant + (count - 1)

/*! \brief OpenOMF String ID
*
* These string IDs are generated by BuildLanguages.cmake from the list in LanguageStrings.cmake,
* and match the generated .LNG files.
*/
enum
{
// lang_str(<enum variant> [<str count>]),
// The <enum variant> is what's used in the C code to refer to this language string.
// Specifying a <str count> allows for a range of lang strs to be added under one name

// strings from OMF 2097
lang_str_range(LangPilot, 11),
lang_str_range(LangPilotDescription, 11),
lang_str_range(LangRobot, 11),
lang_str_range(LangRobotDescription, 11),
lang_str_range(LangArena, 5),
lang_str_range(LangArenaDescription, 5),
lang_str_range(LangPronoun, 6),
lang_str(LangNewsroomUnrankedChallengerDialog),
lang_str_range(LangNewsroomUnrankedChallenger, 2),
lang_str(LangNewsroomNewChampion),
lang_str_range(LangNewsroomReport, 48),
lang_str_range(LangCpuDifficulty, 7),
lang_str(LangTooPatheticDialog),
lang_str(LangTooPatheticInsult),
lang_str_range(LangVsInsult1, 121),
lang_str_range(LangVsInsult2, 121),
lang_str_range(LangPlug, 16),
lang_str(LangPilotStatPower),
lang_str(LangPilotStatSpeed),
lang_str(LangPilotStatEndurance),
lang_str(LangChooseYourPilot),
lang_str(LangChooseYourRobot),
lang_str(LangSceneEnd),
lang_str_range(LangSceneEnd1, 10),
lang_str_range(LangSceneEnd2, 10),
lang_str(LangSelectTournament),
lang_str(LangSelectPhotoForChr),
lang_str(LangSelectChrToLoad),
lang_str(LangSelectChrToDelete),
lang_str(LangSelectOpponent),
lang_str_range(LangTrainingTitle, 3),
lang_str_range(LangTrainingConfirmation, 3),
lang_str_range(LangTrainingHelp, 3),
lang_str(LangTrainingDone),
lang_str(LangTradeGainCash),
lang_str(LangTradeSpendCash),
lang_str(LangTradeEquitable),
lang_str(LangButtonSelect),
lang_str(LangTournamentFight),
lang_str(LangEnterTrainingHelp),
lang_str(LangBuyUpgradesHelp),
lang_str(LangSellUpgradesHelp),
lang_str(LangChrLoadHelp),
lang_str(LangChrCreateHelp),
lang_str(LangChrDeleteHelp),
lang_str(LangTournamentSimHelp),
lang_str(LangTournamentQuitHelp),
lang_str(LangTournamentRegisterHelp),
lang_str_range(LangTournamentDifficulty, 4),
lang_str(LangNo),
lang_str(LangYes),
lang_str(LangPromptChrName),
lang_str(LangCustomizeColor1),
lang_str(LangCustomizeColor2),
lang_str(LangCustomizeColor3),
lang_str(LangUpgradePowerSell),
lang_str(LangUpgradePowerBuy),
lang_str(LangUpgradeSpeedSell),
lang_str(LangUpgradeSpeedBuy),
lang_str(LangUpgradeArmorSell),
lang_str(LangUpgradeArmorBuy),
lang_str(LangUpgradeStunResistanceSell),
lang_str(LangUpgradeStunResistanceBuy),
lang_str(LangTradeHelp),
lang_str(LangTradeNoneAvailable),
lang_str(LangTradeAvailable),
lang_str(LangUpgradeQuitSell),
lang_str(LangUpgradeQuitBuy),
// strings new in OpenOMF
lang_str(LangLanguage),

Lang_Count,
};

#undef lang_str
#undef lang_str_range

#endif // LANGUAGES_H

0 comments on commit 4624a25

Please sign in to comment.