Add Localizable hint

This commit is contained in:
Jupeyy 2022-12-09 16:15:19 +01:00
parent abba8bacd1
commit dff876d58c
5 changed files with 27 additions and 14 deletions

View file

@ -1950,6 +1950,7 @@ set_src(ENGINE_SHARED GLOB_RECURSE src/engine/shared
kernel.cpp kernel.cpp
linereader.cpp linereader.cpp
linereader.h linereader.h
localization.h
map.cpp map.cpp
map.h map.h
masterserver.cpp masterserver.cpp

View file

@ -69,7 +69,7 @@ def decode(fileobj, elements_per_key):
def check_file(path): def check_file(path):
with open(path, encoding="utf-8") as fileobj: with open(path, encoding="utf-8") as fileobj:
matches = re.findall(r"Localize\s*\(\s*\"([^\"]+)\"(?:\s*,\s*\"([^\"]+)\")?\s*\)", fileobj.read()) matches = re.findall(r"(Localize|Localizable)\s*\(\s*\"([^\"]+)\"(?:\s*,\s*\"([^\"]+)\")?\s*\)", fileobj.read())
return matches return matches
@ -81,7 +81,7 @@ def check_folder(path):
if not any(f.endswith(x) for x in ".cpp .c .h".split()): if not any(f.endswith(x) for x in ".cpp .c .h".split()):
continue continue
for sentence in check_file(os.path.join(path2, f)): for sentence in check_file(os.path.join(path2, f)):
englishlist[sentence] = None englishlist[sentence[1:]] = None
return englishlist return englishlist

View file

@ -0,0 +1,12 @@
#ifndef ENGINE_SHARED_LOCALIZATION_H
#define ENGINE_SHARED_LOCALIZATION_H
/**
* An empty function that suits as a helper to identify strings that might get localized later
*/
static constexpr const char *Localizable(const char *pStr, const char *pContext = "")
{
return pStr;
}
#endif

View file

@ -7,6 +7,7 @@
#include <engine/keys.h> #include <engine/keys.h>
#include <engine/serverbrowser.h> #include <engine/serverbrowser.h>
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include <engine/shared/localization.h>
#include <engine/textrender.h> #include <engine/textrender.h>
#include <game/client/components/console.h> #include <game/client/components/console.h>
@ -38,13 +39,13 @@ void FormatServerbrowserPing(char *pBuffer, int BufferLength, const CServerInfo
} }
static const char *LOCATION_NAMES[CServerInfo::NUM_LOCS] = { static const char *LOCATION_NAMES[CServerInfo::NUM_LOCS] = {
"", // LOC_UNKNOWN "", // LOC_UNKNOWN
"AFR", // LOC_AFRICA // Localize("AFR") Localizable("AFR"), // LOC_AFRICA
"ASI", // LOC_ASIA // Localize("ASI") Localizable("ASI"), // LOC_ASIA
"AUS", // LOC_AUSTRALIA // Localize("AUS") Localizable("AUS"), // LOC_AUSTRALIA
"EUR", // LOC_EUROPE // Localize("EUR") Localizable("EUR"), // LOC_EUROPE
"NA", // LOC_NORTH_AMERICA // Localize("NA") Localizable("NA"), // LOC_NORTH_AMERICA
"SA", // LOC_SOUTH_AMERICA // Localize("SA") Localizable("SA"), // LOC_SOUTH_AMERICA
"CHN", // LOC_CHINA // Localize("CHN") Localizable("CHN"), // LOC_CHINA
}; };
dbg_assert(0 <= pInfo->m_Location && pInfo->m_Location < CServerInfo::NUM_LOCS, "location out of range"); dbg_assert(0 <= pInfo->m_Location && pInfo->m_Location < CServerInfo::NUM_LOCS, "location out of range");
str_copy(pBuffer, Localize(LOCATION_NAMES[pInfo->m_Location]), BufferLength); str_copy(pBuffer, Localize(LOCATION_NAMES[pInfo->m_Location]), BufferLength);
@ -92,14 +93,12 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
{COL_FLAG_FAV, -1, " ", -1, 14.0f, {0}, {0}}, {COL_FLAG_FAV, -1, " ", -1, 14.0f, {0}, {0}},
{COL_FLAG_OFFICIAL, -1, " ", -1, 14.0f, {0}, {0}}, {COL_FLAG_OFFICIAL, -1, " ", -1, 14.0f, {0}, {0}},
{COL_NAME, IServerBrowser::SORT_NAME, "Name", 0, 50.0f, {0}, {0}}, // Localize - these strings are localized within CLocConstString {COL_NAME, IServerBrowser::SORT_NAME, "Name", 0, 50.0f, {0}, {0}}, // Localize - these strings are localized within CLocConstString
{COL_GAMETYPE, IServerBrowser::SORT_GAMETYPE, "Type", 1, 50.0f, {0}, {0}}, {COL_GAMETYPE, IServerBrowser::SORT_GAMETYPE, Localizable("Type"), 1, 50.0f, {0}, {0}},
{COL_MAP, IServerBrowser::SORT_MAP, "Map", 1, 120.0f + (Headers.w - 480) / 8, {0}, {0}}, {COL_MAP, IServerBrowser::SORT_MAP, "Map", 1, 120.0f + (Headers.w - 480) / 8, {0}, {0}},
{COL_PLAYERS, IServerBrowser::SORT_NUMPLAYERS, "Players", 1, 85.0f, {0}, {0}}, {COL_PLAYERS, IServerBrowser::SORT_NUMPLAYERS, "Players", 1, 85.0f, {0}, {0}},
{-1, -1, " ", 1, 10.0f, {0}, {0}}, {-1, -1, " ", 1, 10.0f, {0}, {0}},
{COL_PING, IServerBrowser::SORT_PING, "Ping", 1, 40.0f, {0}, {0}}, {COL_PING, IServerBrowser::SORT_PING, "Ping", 1, 40.0f, {0}, {0}},
}; };
// This is just for scripts/update_localization.py to work correctly (all other strings are already Localize()'d somewhere else). Don't remove!
// Localize("Type");
int NumCols = std::size(s_aCols); int NumCols = std::size(s_aCols);

View file

@ -10,6 +10,7 @@
#include <engine/graphics.h> #include <engine/graphics.h>
#include <engine/serverbrowser.h> #include <engine/serverbrowser.h>
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include <engine/shared/localization.h>
#include <engine/textrender.h> #include <engine/textrender.h>
#include <game/generated/client_data.h> #include <game/generated/client_data.h>
@ -985,8 +986,8 @@ void CMenus::RenderGhost(CUIRect MainView)
static CColumn s_aCols[] = { static CColumn s_aCols[] = {
{" ", -1, 2.0f, {0}, {0}}, {" ", -1, 2.0f, {0}, {0}},
{" ", COL_ACTIVE, 30.0f, {0}, {0}}, {" ", COL_ACTIVE, 30.0f, {0}, {0}},
{"Name", COL_NAME, 300.0f, {0}, {0}}, // Localize("Name") {Localizable("Name"), COL_NAME, 300.0f, {0}, {0}},
{"Time", COL_TIME, 200.0f, {0}, {0}}, // Localize("Time") {Localizable("Time"), COL_TIME, 200.0f, {0}, {0}},
}; };
int NumCols = std::size(s_aCols); int NumCols = std::size(s_aCols);