39 #include "table/strings.h"
61 assert(this->
type !=
nullptr);
73 DEBUG(misc, 0,
"Trying to read invalid string parameter");
76 if (this->type !=
nullptr) {
77 if (this->type[this->
offset] != 0 && this->type[this->
offset] != type) {
78 DEBUG(misc, 0,
"Trying to read string parameter with wrong type");
107 while (max_value >= 10) {
125 uint64 val = count > 1 ? front : next;
126 for (; count > 1; count--) {
127 val = 10 * val + next;
165 GetString(buf,
string,
lastof(buf));
168 for (
int i = 0; i < num; i++) {
170 strings[i] =
stredup((
const char *)(
size_t)_global_string_params.GetParam(i));
171 dst[i] = (size_t)strings[i];
173 strings[i] =
nullptr;
178 static char *StationGetSpecialString(
char *buff,
int x,
const char *last);
179 static char *GetSpecialTownNameString(
char *buff,
int ind, uint32 seed,
const char *last);
180 static char *GetSpecialNameString(
char *buff,
int ind,
StringParameters *args,
const char *last);
182 static char *
FormatString(
char *buff,
const char *str,
StringParameters *args,
const char *last, uint case_index = 0,
bool game_script =
false,
bool dry_run =
false);
189 std::unique_ptr<LanguagePack> langpack;
191 std::vector<char *> offsets;
202 const char *GetStringPtr(
StringID string)
207 case TEXT_TAB_OLD_NEWGRF: NOT_REACHED();
232 if (index >= 0xC0 && !game_script) {
233 return GetSpecialTownNameString(buffr, index - 0xC0, args->
GetInt32(), last);
237 case TEXT_TAB_SPECIAL:
238 if (index >= 0xE4 && !game_script) {
239 return GetSpecialNameString(buffr, index - 0xE4, args, last);
243 case TEXT_TAB_OLD_CUSTOM:
246 error(
"Incorrect conversion of custom name string.");
253 case TEXT_TAB_OLD_NEWGRF:
267 error(
"String 0x%X is invalid. You are probably using an old version of the .lng file.\n",
string);
270 return FormatString(buffr, GetStringPtr(
string), args, last, case_index);
273 char *GetString(
char *buffr,
StringID string,
const char *last)
276 _global_string_params.
offset = 0;
311 static char *
FormatNumber(
char *buff, int64 number,
const char *last,
const char *separator,
int zerofill = 1,
int fractional_digits = 0)
313 static const int max_digits = 20;
314 uint64 divisor = 10000000000000000000ULL;
315 zerofill += fractional_digits;
316 int thousands_offset = (max_digits - fractional_digits - 1) % 3;
325 for (
int i = 0; i < max_digits; i++) {
326 if (i == max_digits - fractional_digits) {
328 if (decimal_separator ==
nullptr) decimal_separator = _langpack.langpack->digit_decimal_separator;
329 buff +=
seprintf(buff, last,
"%s", decimal_separator);
333 if (num >= divisor) {
334 quot = num / divisor;
337 if ((tot |= quot) || i >= max_digits - zerofill) {
338 buff +=
seprintf(buff, last,
"%i", (
int)quot);
339 if ((i % 3) == thousands_offset && i < max_digits - 1 - fractional_digits) buff =
strecpy(buff, separator, last);
350 static char *FormatCommaNumber(
char *buff, int64 number,
const char *last,
int fractional_digits = 0)
353 if (separator ==
nullptr) separator = _langpack.langpack->digit_group_separator;
354 return FormatNumber(buff, number, last, separator, 1, fractional_digits);
357 static char *FormatNoCommaNumber(
char *buff, int64 number,
const char *last)
362 static char *FormatZerofillNumber(
char *buff, int64 number, int64 count,
const char *last)
367 static char *FormatHexNumber(
char *buff, uint64 number,
const char *last)
369 return buff +
seprintf(buff, last,
"0x" OTTD_PRINTFHEX64, number);
379 static char *
FormatBytes(
char *buff, int64 number,
const char *last)
384 const char *
const iec_prefixes[] = {
"",
"Ki",
"Mi",
"Gi",
"Ti",
"Pi",
"Ei"};
386 while (number >= 1024 * 1024) {
392 if (decimal_separator ==
nullptr) decimal_separator = _langpack.langpack->digit_decimal_separator;
396 buff +=
seprintf(buff, last,
"%i", (
int)number);
397 }
else if (number < 1024 * 10) {
398 buff +=
seprintf(buff, last,
"%i%s%02i", (
int)number / 1024, decimal_separator, (
int)(number % 1024) * 100 / 1024);
399 }
else if (number < 1024 * 100) {
400 buff +=
seprintf(buff, last,
"%i%s%01i", (
int)number / 1024, decimal_separator, (
int)(number % 1024) * 10 / 1024);
402 assert(number < 1024 * 1024);
403 buff +=
seprintf(buff, last,
"%i", (
int)number / 1024);
406 assert(
id <
lengthof(iec_prefixes));
407 buff +=
seprintf(buff, last,
NBSP "%sB", iec_prefixes[
id]);
412 static char *FormatYmdString(
char *buff,
Date date,
const char *last, uint case_index)
417 int64 args[] = {ymd.
day + STR_DAY_NUMBER_1ST - 1, STR_MONTH_ABBREV_JAN + ymd.
month, ymd.
year};
419 return FormatString(buff, GetStringPtr(STR_FORMAT_DATE_LONG), &tmp_params, last, case_index);
422 static char *FormatMonthAndYear(
char *buff,
Date date,
const char *last, uint case_index)
427 int64 args[] = {STR_MONTH_JAN + ymd.
month, ymd.
year};
429 return FormatString(buff, GetStringPtr(STR_FORMAT_DATE_SHORT), &tmp_params, last, case_index);
432 static char *FormatTinyOrISODate(
char *buff,
Date date,
StringID str,
const char *last)
443 int64 args[] = {(int64)(
size_t)day, (int64)(
size_t)month, ymd.
year};
445 return FormatString(buff, GetStringPtr(str), &tmp_params, last);
448 static char *FormatGenericCurrency(
char *buff,
const CurrencySpec *spec,
Money number,
bool compact,
const char *last)
452 bool negative = number < 0;
453 const char *multiplier =
"";
455 number *= spec->rate;
459 if (buff +
Utf8CharLen(SCC_PUSH_COLOUR) > last)
return buff;
461 if (buff +
Utf8CharLen(SCC_RED) > last)
return buff;
463 buff =
strecpy(buff,
"-", last);
476 if (number >= 1000000000 - 500) {
477 number = (number + 500000) / 1000000;
478 multiplier =
NBSP "M";
479 }
else if (number >= 1000000) {
480 number = (number + 500) / 1000;
481 multiplier =
NBSP "k";
486 if (separator ==
nullptr && !
StrEmpty(_currency->separator)) separator = _currency->separator;
487 if (separator ==
nullptr) separator = _langpack.langpack->digit_group_separator_currency;
489 buff =
strecpy(buff, multiplier, last);
497 if (buff +
Utf8CharLen(SCC_POP_COLOUR) > last)
return buff;
514 uint64 n =
abs(count);
516 switch (plural_form) {
525 return n != 1 ? 1 : 0;
537 return n > 1 ? 1 : 0;
544 return n % 10 == 1 && n % 100 != 11 ? 0 : n != 0 ? 1 : 2;
550 return n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4;
556 return n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
562 return n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
568 return n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
574 return n % 100 == 1 ? 0 : n % 100 == 2 ? 1 : n % 100 == 3 || n % 100 == 4 ? 2 : 3;
580 return n % 10 == 1 && n % 100 != 11 ? 0 : 1;
586 return n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2;
617 return (n == 1 ? 0 : n == 0 || (n % 100 > 1 && n % 100 < 11) ? 1 : (n % 100 > 10 && n % 100 < 20) ? 2 : 3);
622 return ((n == 1 || n == 11) ? 0 : (n == 2 || n == 12) ? 1 : ((n > 2 && n < 11) || (n > 12 && n < 20)) ? 2 : 3);
628 return n == 1 ? 0 : (n == 0 || (n % 100 > 0 && n % 100 < 20)) ? 1 : 2;
632 static const char *ParseStringChoice(
const char *b, uint form,
char **dst,
const char *last)
636 uint pos, i, mypos = 0;
638 for (i = pos = 0; i != n; i++) {
639 uint len = (byte)*b++;
640 if (i == form) mypos = pos;
644 *dst +=
seprintf(*dst, last,
"%s", b + mypos);
661 return ((input * this->multiplier) + (round && this->shift != 0 ? 1 << (this->shift - 1) : 0)) >> this->
shift;
671 int64
FromDisplay(int64 input,
bool round =
true, int64 divider = 1)
const
673 return ((input << this->shift) + (round ? (this->multiplier * divider) - 1 : 0)) / (this->multiplier * divider);
693 { { 1, 0}, STR_UNITS_VELOCITY_IMPERIAL, 0 },
694 { { 103, 6}, STR_UNITS_VELOCITY_METRIC, 0 },
695 { { 1831, 12}, STR_UNITS_VELOCITY_SI, 0 },
696 { {37888, 16}, STR_UNITS_VELOCITY_GAMEUNITS, 1 },
701 { { 1, 0}, STR_UNITS_POWER_IMPERIAL, 0 },
702 { {4153, 12}, STR_UNITS_POWER_METRIC, 0 },
703 { {6109, 13}, STR_UNITS_POWER_SI, 0 },
708 { {4515, 12}, STR_UNITS_WEIGHT_SHORT_IMPERIAL, STR_UNITS_WEIGHT_LONG_IMPERIAL },
709 { { 1, 0}, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC },
710 { {1000, 0}, STR_UNITS_WEIGHT_SHORT_SI, STR_UNITS_WEIGHT_LONG_SI },
715 { {4227, 4}, STR_UNITS_VOLUME_SHORT_IMPERIAL, STR_UNITS_VOLUME_LONG_IMPERIAL },
716 { {1000, 0}, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC },
717 { { 1, 0}, STR_UNITS_VOLUME_SHORT_SI, STR_UNITS_VOLUME_LONG_SI },
722 { {3597, 4}, STR_UNITS_FORCE_IMPERIAL, 0 },
723 { {3263, 5}, STR_UNITS_FORCE_METRIC, 0 },
724 { { 1, 0}, STR_UNITS_FORCE_SI, 0 },
729 { { 3, 0}, STR_UNITS_HEIGHT_IMPERIAL, 0 },
730 { { 1, 0}, STR_UNITS_HEIGHT_METRIC, 0 },
731 { { 1, 0}, STR_UNITS_HEIGHT_SI, 0 },
786 uint orig_offset = args->
offset;
798 FormatString(buff, str_arg, args, last, case_index, game_script,
true);
801 FormatString(buff, str_arg, args, last, case_index, game_script,
true);
804 args->
offset = orig_offset;
807 uint next_substr_case_index = 0;
808 char *buf_start = buff;
809 std::stack<const char *, std::vector<const char *>> str_stack;
810 str_stack.push(str_arg);
813 while (!str_stack.empty() && (b = Utf8Consume(&str_stack.top())) ==
'\0') {
816 if (str_stack.empty())
break;
817 const char *&str = str_stack.top();
823 if (b == 0)
continue;
828 uint64 sub_args_data[20];
829 WChar sub_args_type[20];
830 bool sub_args_need_free[20];
834 memset(sub_args_need_free, 0,
sizeof(sub_args_need_free));
837 uint32 stringid = strtoul(str, &p, 16);
838 if (*p !=
':' && *p !=
'\0') {
839 while (*p !=
'\0') p++;
841 buff =
strecat(buff,
"(invalid SCC_ENCODED)", last);
845 while (*p !=
'\0') p++;
847 buff =
strecat(buff,
"(invalid StringID)", last);
852 while (*p !=
'\0' && i < 20) {
857 bool instring =
false;
864 if (*p ==
'"' && escape) {
871 instring = !instring;
878 if (*p ==
':')
break;
879 if (*p ==
'\0')
break;
886 bool lookup = (l == SCC_ENCODED);
887 if (lookup) s += len;
889 param = strtoull(s, &p, 16);
893 while (*p !=
'\0') p++;
895 buff =
strecat(buff,
"(invalid sub-StringID)", last);
901 sub_args.SetParam(i++, param);
906 sub_args_need_free[i] =
true;
907 sub_args.SetParam(i++, (uint64)(
size_t)g);
916 for (
int i = 0; i < 20; i++) {
917 if (sub_args_need_free[i])
free((
void *)sub_args.GetParam(i));
923 StringID substr = Utf8Consume(&str);
924 str_stack.push(GetStringPtr(substr));
930 str_stack.push(GetStringPtr(substr));
931 case_index = next_substr_case_index;
932 next_substr_case_index = 0;
937 case SCC_GENDER_LIST: {
939 uint offset = orig_offset + (byte)*str++;
960 WChar c = Utf8Consume(&s);
962 if (c == SCC_GENDER_INDEX) gender = (byte)s[0];
964 str = ParseStringChoice(str, gender, &buff, last);
970 case SCC_GENDER_INDEX:
979 case SCC_PLURAL_LIST: {
980 int plural_form = *str++;
981 uint offset = orig_offset + (byte)*str++;
987 case SCC_ARG_INDEX: {
988 args->
offset = orig_offset + (byte)*str++;
995 next_substr_case_index = (byte)*str++;
999 case SCC_SWITCH_CASE: {
1002 uint num = (byte)*str++;
1004 if ((
byte)str[0] == case_index) {
1010 str += 3 + (str[1] << 8) + str[2];
1017 buff =
strecpy(buff, _openttd_revision, last);
1020 case SCC_RAW_STRING_POINTER: {
1021 if (game_script)
break;
1022 const char *str = (
const char *)(
size_t)args->
GetInt64(SCC_RAW_STRING_POINTER);
1034 buff =
GetStringWithArgs(buff, str, &tmp_params, last, next_substr_case_index, game_script);
1035 next_substr_case_index = 0;
1049 uint size = b - SCC_STRING1 + 1;
1051 buff =
strecat(buff,
"(too many parameters)", last);
1054 buff =
GetStringWithArgs(buff, str, &sub_args, last, next_substr_case_index, game_script);
1056 next_substr_case_index = 0;
1061 buff = FormatCommaNumber(buff, args->
GetInt64(SCC_COMMA), last);
1065 int64 number = args->
GetInt64(SCC_DECIMAL);
1066 int digits = args->
GetInt32(SCC_DECIMAL);
1067 buff = FormatCommaNumber(buff, number, last, digits);
1072 buff = FormatNoCommaNumber(buff, args->
GetInt64(SCC_NUM), last);
1075 case SCC_ZEROFILL_NUM: {
1077 buff = FormatZerofillNumber(buff, num, args->
GetInt64(), last);
1082 buff = FormatHexNumber(buff, (uint64)args->
GetInt64(SCC_HEX), last);
1089 case SCC_CARGO_TINY: {
1098 switch (cargo_str) {
1113 buff = FormatCommaNumber(buff, amount, last);
1117 case SCC_CARGO_SHORT: {
1125 switch (cargo_str) {
1151 case SCC_CARGO_LONG: {
1162 case SCC_CARGO_LIST: {
1163 CargoTypes cmask = args->
GetInt64(SCC_CARGO_LIST);
1170 if (buff >= last - 2)
break;
1184 if (first) buff =
GetStringWithArgs(buff, STR_JUST_NOTHING, args, last, next_substr_case_index, game_script);
1187 next_substr_case_index = 0;
1190 assert(buff < last);
1194 case SCC_CURRENCY_SHORT:
1195 buff = FormatGenericCurrency(buff, _currency, args->
GetInt64(),
true, last);
1198 case SCC_CURRENCY_LONG:
1199 buff = FormatGenericCurrency(buff, _currency, args->
GetInt64(SCC_CURRENCY_LONG),
false, last);
1203 buff = FormatTinyOrISODate(buff, args->
GetInt32(SCC_DATE_TINY), STR_FORMAT_DATE_TINY, last);
1206 case SCC_DATE_SHORT:
1207 buff = FormatMonthAndYear(buff, args->
GetInt32(SCC_DATE_SHORT), last, next_substr_case_index);
1208 next_substr_case_index = 0;
1212 buff = FormatYmdString(buff, args->
GetInt32(SCC_DATE_LONG), last, next_substr_case_index);
1213 next_substr_case_index = 0;
1217 buff = FormatTinyOrISODate(buff, args->
GetInt32(), STR_FORMAT_DATE_ISO, last);
1244 case SCC_VELOCITY: {
1253 case SCC_VOLUME_SHORT: {
1261 case SCC_VOLUME_LONG: {
1269 case SCC_WEIGHT_SHORT: {
1277 case SCC_WEIGHT_LONG: {
1285 case SCC_COMPANY_NAME: {
1287 if (c ==
nullptr)
break;
1289 if (!c->
name.empty()) {
1290 int64 args_array[] = {(int64)(
size_t)c->
name.c_str()};
1294 int64 args_array[] = {c->
name_2};
1301 case SCC_COMPANY_NUM: {
1306 int64 args_array[] = {company + 1};
1313 case SCC_DEPOT_NAME: {
1316 uint64 args_array[] = {(uint64)args->
GetInt32()};
1317 WChar types_array[] = {SCC_STATION_NAME};
1319 buff =
GetStringWithArgs(buff, STR_FORMAT_DEPOT_NAME_AIRCRAFT, &tmp_params, last);
1324 if (!d->name.empty()) {
1325 int64 args_array[] = {(int64)(
size_t)d->name.c_str()};
1331 buff =
GetStringWithArgs(buff, STR_FORMAT_DEPOT_NAME_TRAIN + 2 * vt + (d->
town_cn == 0 ? 0 : 1), &tmp_params, last);
1336 case SCC_ENGINE_NAME: {
1338 if (e ==
nullptr)
break;
1341 int64 args_array[] = {(int64)(
size_t)e->
name.c_str()};
1351 case SCC_GROUP_NAME: {
1353 if (g ==
nullptr)
break;
1355 if (!g->
name.empty()) {
1356 int64 args_array[] = {(int64)(
size_t)g->
name.c_str()};
1360 int64 args_array[] = {g->
index};
1368 case SCC_INDUSTRY_NAME: {
1370 if (i ==
nullptr)
break;
1382 buff =
FormatString(buff, GetStringPtr(STR_FORMAT_INDUSTRY_NAME), &tmp_params, last, next_substr_case_index);
1384 next_substr_case_index = 0;
1388 case SCC_PRESIDENT_NAME: {
1390 if (c ==
nullptr)
break;
1404 case SCC_STATION_NAME: {
1405 StationID sid = args->
GetInt32(SCC_STATION_NAME);
1408 if (st ==
nullptr) {
1417 if (!st->
name.empty()) {
1418 int64 args_array[] = {(int64)(
size_t)st->
name.c_str()};
1423 if (st->
indtype != IT_INVALID) {
1435 uint64 args_array[] = {STR_TOWN_NAME, st->
town->
index, st->
index};
1436 WChar types_array[] = {0, SCC_TOWN_NAME, SCC_NUM};
1443 case SCC_TOWN_NAME: {
1445 if (t ==
nullptr)
break;
1447 if (!t->
name.empty()) {
1448 int64 args_array[] = {(int64)(
size_t)t->
name.c_str()};
1457 case SCC_WAYPOINT_NAME: {
1459 if (wp ==
nullptr)
break;
1461 if (!wp->
name.empty()) {
1462 int64 args_array[] = {(int64)(
size_t)wp->
name.c_str()};
1468 StringID str = ((wp->
string_id == STR_SV_STNAME_BUOY) ? STR_FORMAT_BUOY_NAME : STR_FORMAT_WAYPOINT_NAME);
1475 case SCC_VEHICLE_NAME: {
1477 if (v ==
nullptr)
break;
1479 if (!v->
name.empty()) {
1480 int64 args_array[] = {(int64)(
size_t)v->
name.c_str()};
1487 buff =
GetStringWithArgs(buff, STR_FORMAT_GROUP_VEHICLE_NAME, &tmp_params, last);
1494 default: str = STR_INVALID_VEHICLE;
break;
1495 case VEH_TRAIN: str = STR_SV_TRAIN_NAME;
break;
1496 case VEH_ROAD: str = STR_SV_ROAD_VEHICLE_NAME;
break;
1497 case VEH_SHIP: str = STR_SV_SHIP_NAME;
break;
1506 case SCC_SIGN_NAME: {
1508 if (si ==
nullptr)
break;
1510 if (!si->name.empty()) {
1511 int64 args_array[] = {(int64)(
size_t)si->name.c_str()};
1521 case SCC_STATION_FEATURES: {
1522 buff = StationGetSpecialString(buff, args->
GetInt32(SCC_STATION_FEATURES), last);
1536 static char *StationGetSpecialString(
char *buff,
int x,
const char *last)
1547 static char *GetSpecialTownNameString(
char *buff,
int ind, uint32 seed,
const char *last)
1552 static const char *
const _silly_company_names[] = {
1554 "Tiny Transport Ltd.",
1556 "Comfy-Coach & Co.",
1557 "Crush & Bump Ltd.",
1558 "Broken & Late Ltd.",
1560 "Supersonic Travel",
1562 "Lightning International",
1563 "Pannik & Loozit Ltd.",
1564 "Inter-City Transport",
1565 "Getout & Pushit Ltd."
1568 static const char *
const _surname_list[] = {
1600 static const char *
const _silly_surname_list[] = {
1615 static const char _initial_name_letters[] = {
1616 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
1617 'K',
'L',
'M',
'N',
'P',
'R',
'S',
'T',
'W',
1620 static char *GenAndCoName(
char *buff, uint32 arg,
const char *last)
1622 const char *
const *base;
1626 base = _silly_surname_list;
1627 num =
lengthof(_silly_surname_list);
1629 base = _surname_list;
1633 buff =
strecpy(buff, base[num *
GB(arg, 16, 8) >> 8], last);
1634 buff =
strecpy(buff,
" & Co.", last);
1639 static char *GenPresidentName(
char *buff, uint32 x,
const char *last)
1641 char initial[] =
"?. ";
1642 const char *
const *base;
1646 initial[0] = _initial_name_letters[
sizeof(_initial_name_letters) *
GB(x, 0, 8) >> 8];
1647 buff =
strecpy(buff, initial, last);
1649 i = (
sizeof(_initial_name_letters) + 35) *
GB(x, 8, 8) >> 8;
1650 if (i <
sizeof(_initial_name_letters)) {
1651 initial[0] = _initial_name_letters[i];
1652 buff =
strecpy(buff, initial, last);
1656 base = _silly_surname_list;
1657 num =
lengthof(_silly_surname_list);
1659 base = _surname_list;
1663 buff =
strecpy(buff, base[num *
GB(x, 16, 8) >> 8], last);
1668 static char *GetSpecialNameString(
char *buff,
int ind,
StringParameters *args,
const char *last)
1672 return strecpy(buff, _silly_company_names[std::min<uint>(args->
GetInt32() & 0xFFFF,
lengthof(_silly_company_names) - 1)], last);
1675 return GenAndCoName(buff, args->
GetInt32(), last);
1678 return GenPresidentName(buff, args->
GetInt32(), last);
1682 if (
IsInsideMM(ind - 6, 0, SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1)) {
1683 buff = GetSpecialTownNameString(buff, ind - 6, args->
GetInt32(), last);
1684 return strecpy(buff,
" Transport", last);
1690 extern void SortNetworkLanguages();
1699 this->
version == TO_LE32(LANGUAGE_PACK_VERSION) &&
1723 if (!lang_pack)
return false;
1726 const char *end = (
char *)lang_pack.get() + len + 1;
1729 if (end <= lang_pack->data || !lang_pack->IsValid()) {
1733 #if TTD_ENDIAN == TTD_BIG_ENDIAN
1735 lang_pack->offsets[i] = ReadLE16Aligned(&lang_pack->offsets[i]);
1739 std::array<uint, TEXT_TAB_END> tab_start, tab_num;
1743 uint16 num = lang_pack->offsets[i];
1746 tab_start[i] = count;
1752 std::vector<char *> offs(count);
1755 char *s = lang_pack->data;
1757 for (uint i = 0; i < count; i++) {
1758 if (s + len >= end)
return false;
1761 len = ((len & 0x3F) << 8) + (byte)*s++;
1762 if (s + len >= end)
return false;
1770 _langpack.langpack = std::move(lang_pack);
1771 _langpack.offsets = std::move(offs);
1782 extern void Win32SetCurrentLocaleName(
const char *iso_code);
1791 #ifdef WITH_ICU_I18N
1793 UErrorCode status = U_ZERO_ERROR;
1798 if (U_FAILURE(status)) {
1808 SortNetworkLanguages();
1823 #if !(defined(_WIN32) || defined(__APPLE__))
1836 env = getenv(
"LANGUAGE");
1837 if (env !=
nullptr)
return env;
1839 env = getenv(
"LC_ALL");
1840 if (env !=
nullptr)
return env;
1842 if (param !=
nullptr) {
1843 env = getenv(param);
1844 if (env !=
nullptr)
return env;
1847 return getenv(
"LANG");
1857 GetString(stra, a,
lastof(stra));
1858 GetString(strb, b,
lastof(strb));
1871 if (newgrflangid == lang.newgrflangid)
return ⟨
1885 FILE *f = fopen(file,
"rb");
1886 if (f ==
nullptr)
return false;
1888 size_t read = fread(hdr,
sizeof(*hdr), 1, f);
1891 bool ret = read == 1 && hdr->
IsValid();
1908 if (dir !=
nullptr) {
1909 struct dirent *dirent;
1910 while ((dirent = readdir(dir)) !=
nullptr) {
1911 const char *d_name =
FS2OTTD(dirent->d_name);
1912 const char *extension = strrchr(d_name,
'.');
1915 if (extension ==
nullptr || strcmp(extension,
".lng") != 0)
continue;
1922 DEBUG(misc, 3,
"%s is not a valid language file", lmd.
file);
1924 DEBUG(misc, 3,
"%s's language ID is already known", lmd.
file);
1942 std::string path = FioGetDirectory(sp,
LANG_DIR);
1949 if (lang ==
nullptr) lang =
"en_GB";
1960 const char *lang_file = strrchr(lng.file, PATHSEPCHAR) + 1;
1962 chosen_language = &lng;
1966 if (strcmp (lng.isocode,
"en_GB") == 0) en_GB_fallback = &lng;
1967 if (strncmp(lng.isocode, lang, 5) == 0) chosen_language = &lng;
1968 if (strncmp(lng.isocode, lang, 2) == 0) language_fallback = &lng;
1973 if (chosen_language ==
nullptr) {
1974 chosen_language = (language_fallback !=
nullptr) ? language_fallback : en_GB_fallback;
1986 return _langpack.langpack->isocode;
1996 const Sprite *question_mark[FS_END];
1999 question_mark[size] =
GetGlyph(size,
'?');
2005 for (
WChar c = Utf8Consume(&text); c !=
'\0'; c = Utf8Consume(&text)) {
2006 if (c >= SCC_FIRST_FONT && c <= SCC_LAST_FONT) {
2007 size = (
FontSize)(c - SCC_FIRST_FONT);
2010 std::string size_name;
2013 case 0: size_name =
"medium";
break;
2014 case 1: size_name =
"small";
break;
2015 case 2: size_name =
"large";
break;
2016 case 3: size_name =
"mono";
break;
2017 default: NOT_REACHED();
2020 DEBUG(freetype, 0,
"Font is missing glyphs to display char 0x%X in %s font size", c, size_name.c_str());
2048 const char *ret = _langpack.offsets[_langpack.
langtab_start[this->
i] + this->
j];
2051 while (this->i < TEXT_TAB_END && this->
j >= _langpack.
langtab_num[this->i]) {
2066 #if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
2071 settings->small.os_handle = os_data;
2072 settings->medium.os_handle = os_data;
2073 settings->large.os_handle = os_data;
2094 if (searcher ==
nullptr) searcher = &pack_searcher;
2096 #if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
2101 memcpy(&backup, &_freetype,
sizeof(backup));
2106 bad_font = !
SetFallbackFont(&_freetype, _langpack.langpack->isocode, _langpack.langpack->winlangid, searcher);
2108 memcpy(&_freetype, &backup,
sizeof(backup));
2117 static char *err_str =
stredup(
"XXXThe current font is missing some of the characters used in the texts for this language. Using system fallback font instead.");
2123 if (bad_font && base_font) {
2138 static char *err_str =
stredup(
"XXXThe current font is missing some of the characters used in the texts for this language. Read the readme to see how to solve this.");
2151 #if !defined(WITH_ICU_LX) && !defined(WITH_UNISCRIBE) && !defined(WITH_COCOA)
2166 static char *err_str =
stredup(
"XXXThis version of OpenTTD does not support right-to-left languages. Recompile with icu enabled.");