mirror of https://github.com/OpenTTD/OpenTTD
Add: Translatable list separator. (#13149)
Some languages should use a separator other than ", " to separate list items, so it is now a translatable string.pull/13152/head
parent
ef76f0e758
commit
cba329d9e2
|
@ -268,6 +268,8 @@ uint64_t CargoSpec::WeightOfNUnitsInTrain(uint32_t n) const
|
||||||
*/
|
*/
|
||||||
std::optional<std::string> BuildCargoAcceptanceString(const CargoArray &acceptance, StringID label)
|
std::optional<std::string> BuildCargoAcceptanceString(const CargoArray &acceptance, StringID label)
|
||||||
{
|
{
|
||||||
|
std::string_view list_separator = GetListSeparator();
|
||||||
|
|
||||||
/* Cargo acceptance is displayed in a extra multiline */
|
/* Cargo acceptance is displayed in a extra multiline */
|
||||||
std::stringstream line;
|
std::stringstream line;
|
||||||
line << GetString(label);
|
line << GetString(label);
|
||||||
|
@ -277,7 +279,7 @@ std::optional<std::string> BuildCargoAcceptanceString(const CargoArray &acceptan
|
||||||
CargoID cid = cs->Index();
|
CargoID cid = cs->Index();
|
||||||
if (acceptance[cid] > 0) {
|
if (acceptance[cid] > 0) {
|
||||||
/* Add a comma between each item. */
|
/* Add a comma between each item. */
|
||||||
if (found) line << ", ";
|
if (found) line << list_separator;
|
||||||
found = true;
|
found = true;
|
||||||
|
|
||||||
/* If the accepted value is less than 8, show it in 1/8:ths */
|
/* If the accepted value is less than 8, show it in 1/8:ths */
|
||||||
|
|
|
@ -266,6 +266,8 @@ STR_UNITS_MINUTES :{NUM}{NBSP}minu
|
||||||
STR_UNITS_YEARS :{NUM}{NBSP}year{P "" s}
|
STR_UNITS_YEARS :{NUM}{NBSP}year{P "" s}
|
||||||
STR_UNITS_PERIODS :{NUM}{NBSP}period{P "" s}
|
STR_UNITS_PERIODS :{NUM}{NBSP}period{P "" s}
|
||||||
|
|
||||||
|
STR_LIST_SEPARATOR :,{SPACE}
|
||||||
|
|
||||||
# Common window strings
|
# Common window strings
|
||||||
STR_LIST_FILTER_TITLE :{BLACK}Filter:
|
STR_LIST_FILTER_TITLE :{BLACK}Filter:
|
||||||
STR_LIST_FILTER_OSKTITLE :{BLACK}Enter one or more keywords to filter the list for
|
STR_LIST_FILTER_OSKTITLE :{BLACK}Enter one or more keywords to filter the list for
|
||||||
|
|
|
@ -739,6 +739,7 @@ public:
|
||||||
SetDParam(0, this->selected->filesize);
|
SetDParam(0, this->selected->filesize);
|
||||||
tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_FILESIZE);
|
tr.top = DrawStringMultiLine(tr, STR_CONTENT_DETAIL_FILESIZE);
|
||||||
|
|
||||||
|
std::string_view list_separator = GetListSeparator();
|
||||||
if (!this->selected->dependencies.empty()) {
|
if (!this->selected->dependencies.empty()) {
|
||||||
/* List dependencies */
|
/* List dependencies */
|
||||||
std::string buf;
|
std::string buf;
|
||||||
|
@ -749,7 +750,7 @@ public:
|
||||||
const ContentInfo *ci = *iter;
|
const ContentInfo *ci = *iter;
|
||||||
if (ci->id != cid) continue;
|
if (ci->id != cid) continue;
|
||||||
|
|
||||||
if (!buf.empty()) buf += ", ";
|
if (!buf.empty()) buf += list_separator;
|
||||||
buf += (*iter)->name;
|
buf += (*iter)->name;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -762,7 +763,7 @@ public:
|
||||||
/* List all tags */
|
/* List all tags */
|
||||||
std::string buf;
|
std::string buf;
|
||||||
for (auto &tag : this->selected->tags) {
|
for (auto &tag : this->selected->tags) {
|
||||||
if (!buf.empty()) buf += ", ";
|
if (!buf.empty()) buf += list_separator;
|
||||||
buf += tag;
|
buf += tag;
|
||||||
}
|
}
|
||||||
SetDParamStr(0, buf);
|
SetDParamStr(0, buf);
|
||||||
|
@ -778,7 +779,7 @@ public:
|
||||||
for (const ContentInfo *ci : tree) {
|
for (const ContentInfo *ci : tree) {
|
||||||
if (ci == this->selected || ci->state != ContentInfo::SELECTED) continue;
|
if (ci == this->selected || ci->state != ContentInfo::SELECTED) continue;
|
||||||
|
|
||||||
if (!buf.empty()) buf += ", ";
|
if (!buf.empty()) buf += list_separator;
|
||||||
buf += ci->name;
|
buf += ci->name;
|
||||||
}
|
}
|
||||||
if (!buf.empty()) {
|
if (!buf.empty()) {
|
||||||
|
|
|
@ -51,12 +51,13 @@ void DrawRoadVehDetails(const Vehicle *v, const Rect &r)
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string capacity = GetString(STR_VEHICLE_DETAILS_TRAIN_ARTICULATED_RV_CAPACITY);
|
std::string capacity = GetString(STR_VEHICLE_DETAILS_TRAIN_ARTICULATED_RV_CAPACITY);
|
||||||
|
std::string_view list_separator = GetListSeparator();
|
||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (const CargoSpec *cs : _sorted_cargo_specs) {
|
for (const CargoSpec *cs : _sorted_cargo_specs) {
|
||||||
CargoID cid = cs->Index();
|
CargoID cid = cs->Index();
|
||||||
if (max_cargo[cid] > 0) {
|
if (max_cargo[cid] > 0) {
|
||||||
if (!first) capacity += ", ";
|
if (!first) capacity += list_separator;
|
||||||
|
|
||||||
SetDParam(0, cid);
|
SetDParam(0, cid);
|
||||||
SetDParam(1, max_cargo[cid]);
|
SetDParam(1, max_cargo[cid]);
|
||||||
|
|
|
@ -214,12 +214,22 @@ struct LoadedLanguagePack {
|
||||||
|
|
||||||
std::array<uint, TEXT_TAB_END> langtab_num; ///< Offset into langpack offs
|
std::array<uint, TEXT_TAB_END> langtab_num; ///< Offset into langpack offs
|
||||||
std::array<uint, TEXT_TAB_END> langtab_start; ///< Offset into langpack offs
|
std::array<uint, TEXT_TAB_END> langtab_start; ///< Offset into langpack offs
|
||||||
|
|
||||||
|
std::string list_separator; ///< Current list separator string.
|
||||||
};
|
};
|
||||||
|
|
||||||
static LoadedLanguagePack _langpack;
|
static LoadedLanguagePack _langpack;
|
||||||
|
|
||||||
static bool _scan_for_gender_data = false; ///< Are we scanning for the gender of the current string? (instead of formatting it)
|
static bool _scan_for_gender_data = false; ///< Are we scanning for the gender of the current string? (instead of formatting it)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list separator string for the current language.
|
||||||
|
* @returns string containing list separator to use.
|
||||||
|
*/
|
||||||
|
std::string_view GetListSeparator()
|
||||||
|
{
|
||||||
|
return _langpack.list_separator;
|
||||||
|
}
|
||||||
|
|
||||||
const char *GetStringPtr(StringID string)
|
const char *GetStringPtr(StringID string)
|
||||||
{
|
{
|
||||||
|
@ -1311,6 +1321,7 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara
|
||||||
CargoTypes cmask = args.GetNextParameter<CargoTypes>();
|
CargoTypes cmask = args.GetNextParameter<CargoTypes>();
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
|
||||||
|
std::string_view list_separator = GetListSeparator();
|
||||||
for (const auto &cs : _sorted_cargo_specs) {
|
for (const auto &cs : _sorted_cargo_specs) {
|
||||||
if (!HasBit(cmask, cs->Index())) continue;
|
if (!HasBit(cmask, cs->Index())) continue;
|
||||||
|
|
||||||
|
@ -1318,7 +1329,7 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
/* Add a comma if this is not the first item */
|
/* Add a comma if this is not the first item */
|
||||||
builder += ", ";
|
builder += list_separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetStringWithArgs(builder, cs->name, args, next_substr_case_index, game_script);
|
GetStringWithArgs(builder, cs->name, args, next_substr_case_index, game_script);
|
||||||
|
@ -1964,6 +1975,7 @@ bool ReadLanguagePack(const LanguageMetadata *lang)
|
||||||
_current_text_dir = (TextDirection)_current_language->text_dir;
|
_current_text_dir = (TextDirection)_current_language->text_dir;
|
||||||
_config_language_file = FS2OTTD(_current_language->file.filename());
|
_config_language_file = FS2OTTD(_current_language->file.filename());
|
||||||
SetCurrentGrfLangID(_current_language->newgrflangid);
|
SetCurrentGrfLangID(_current_language->newgrflangid);
|
||||||
|
_langpack.list_separator = GetString(STR_LIST_SEPARATOR);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
extern void Win32SetCurrentLocaleName(std::string iso_code);
|
extern void Win32SetCurrentLocaleName(std::string iso_code);
|
||||||
|
|
|
@ -109,6 +109,7 @@ extern TextDirection _current_text_dir; ///< Text direction of the currently sel
|
||||||
|
|
||||||
void InitializeLanguagePacks();
|
void InitializeLanguagePacks();
|
||||||
const char *GetCurrentLanguageIsoCode();
|
const char *GetCurrentLanguageIsoCode();
|
||||||
|
std::string_view GetListSeparator();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A searcher for missing glyphs.
|
* A searcher for missing glyphs.
|
||||||
|
|
|
@ -127,6 +127,7 @@ static const CmdStruct _cmd_structs[] = {
|
||||||
{"COMPANY_NUM", EmitSingleChar, SCC_COMPANY_NUM, 1, -1, C_NONE},
|
{"COMPANY_NUM", EmitSingleChar, SCC_COMPANY_NUM, 1, -1, C_NONE},
|
||||||
{"PRESIDENT_NAME", EmitSingleChar, SCC_PRESIDENT_NAME, 1, -1, C_NONE | C_GENDER},
|
{"PRESIDENT_NAME", EmitSingleChar, SCC_PRESIDENT_NAME, 1, -1, C_NONE | C_GENDER},
|
||||||
|
|
||||||
|
{"SPACE", EmitSingleChar, ' ', 0, -1, C_DONTCOUNT},
|
||||||
{"", EmitSingleChar, '\n', 0, -1, C_DONTCOUNT},
|
{"", EmitSingleChar, '\n', 0, -1, C_DONTCOUNT},
|
||||||
{"{", EmitSingleChar, '{', 0, -1, C_DONTCOUNT},
|
{"{", EmitSingleChar, '{', 0, -1, C_DONTCOUNT},
|
||||||
{"UP_ARROW", EmitSingleChar, SCC_UP_ARROW, 0, -1, C_DONTCOUNT},
|
{"UP_ARROW", EmitSingleChar, SCC_UP_ARROW, 0, -1, C_DONTCOUNT},
|
||||||
|
|
Loading…
Reference in New Issue