40 #include "table/strings.h"
62 assert(this->
type != NULL);
74 DEBUG(misc, 0,
"Trying to read invalid string parameter");
77 if (this->type != NULL) {
78 assert(this->type[this->
offset] == 0 || this->type[this->
offset] == type);
105 while (max_value >= 10) {
122 uint64 val = count > 1 ? front : next;
123 for (; count > 1; count--) {
124 val = 10 * val + next;
162 GetString(buf,
string,
lastof(buf));
165 for (
int i = 0; i < num; i++) {
167 strings[i] =
stredup((
const char *)(
size_t)_global_string_params.GetParam(i));
168 dst[i] = (size_t)strings[i];
175 static char *StationGetSpecialString(
char *buff,
int x,
const char *last);
176 static char *GetSpecialTownNameString(
char *buff,
int ind, uint32 seed,
const char *last);
177 static char *GetSpecialNameString(
char *buff,
int ind,
StringParameters *args,
const char *last);
179 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);
185 static char **_langpack_offs;
192 const char *GetStringPtr(
StringID string)
197 case 26: NOT_REACHED();
224 if (index >= 0xC0 && !game_script) {
225 return GetSpecialTownNameString(buffr, index - 0xC0, args->
GetInt32(), last);
230 if (index >= 0xE4 && !game_script) {
231 return GetSpecialNameString(buffr, index - 0xE4, args, last);
238 error(
"Incorrect conversion of custom name string.");
262 error(
"String 0x%X is invalid. You are probably using an old version of the .lng file.\n",
string);
265 return FormatString(buffr, GetStringPtr(
string), args, last, case_index);
268 char *GetString(
char *buffr,
StringID string,
const char *last)
271 _global_string_params.
offset = 0;
306 static char *
FormatNumber(
char *buff, int64 number,
const char *last,
const char *separator,
int zerofill = 1,
int fractional_digits = 0)
308 static const int max_digits = 20;
309 uint64 divisor = 10000000000000000000ULL;
310 zerofill += fractional_digits;
311 int thousands_offset = (max_digits - fractional_digits - 1) % 3;
320 for (
int i = 0; i < max_digits; i++) {
321 if (i == max_digits - fractional_digits) {
324 buff +=
seprintf(buff, last,
"%s", decimal_separator);
328 if (num >= divisor) {
329 quot = num / divisor;
332 if ((tot |= quot) || i >= max_digits - zerofill) {
333 buff +=
seprintf(buff, last,
"%i", (
int)quot);
334 if ((i % 3) == thousands_offset && i < max_digits - 1 - fractional_digits) buff =
strecpy(buff, separator, last);
345 static char *FormatCommaNumber(
char *buff, int64 number,
const char *last,
int fractional_digits = 0)
349 return FormatNumber(buff, number, last, separator, 1, fractional_digits);
352 static char *FormatNoCommaNumber(
char *buff, int64 number,
const char *last)
357 static char *FormatZerofillNumber(
char *buff, int64 number, int64 count,
const char *last)
362 static char *FormatHexNumber(
char *buff, uint64 number,
const char *last)
364 return buff +
seprintf(buff, last,
"0x" OTTD_PRINTFHEX64, number);
374 static char *
FormatBytes(
char *buff, int64 number,
const char *last)
379 const char *
const iec_prefixes[] = {
"",
"Ki",
"Mi",
"Gi",
"Ti",
"Pi",
"Ei"};
381 while (number >= 1024 * 1024) {
391 buff +=
seprintf(buff, last,
"%i", (
int)number);
392 }
else if (number < 1024 * 10) {
393 buff +=
seprintf(buff, last,
"%i%s%02i", (
int)number / 1024, decimal_separator, (
int)(number % 1024) * 100 / 1024);
394 }
else if (number < 1024 * 100) {
395 buff +=
seprintf(buff, last,
"%i%s%01i", (
int)number / 1024, decimal_separator, (
int)(number % 1024) * 10 / 1024);
397 assert(number < 1024 * 1024);
398 buff +=
seprintf(buff, last,
"%i", (
int)number / 1024);
401 assert(
id <
lengthof(iec_prefixes));
402 buff +=
seprintf(buff, last,
NBSP "%sB", iec_prefixes[
id]);
407 static char *FormatYmdString(
char *buff,
Date date,
const char *last, uint case_index)
412 int64 args[] = {ymd.
day + STR_DAY_NUMBER_1ST - 1, STR_MONTH_ABBREV_JAN + ymd.
month, ymd.
year};
414 return FormatString(buff, GetStringPtr(STR_FORMAT_DATE_LONG), &tmp_params, last, case_index);
417 static char *FormatMonthAndYear(
char *buff,
Date date,
const char *last, uint case_index)
422 int64 args[] = {STR_MONTH_JAN + ymd.
month, ymd.
year};
424 return FormatString(buff, GetStringPtr(STR_FORMAT_DATE_SHORT), &tmp_params, last, case_index);
427 static char *FormatTinyOrISODate(
char *buff,
Date date,
StringID str,
const char *last)
438 int64 args[] = {(int64)(
size_t)day, (int64)(
size_t)month, ymd.year};
440 return
FormatString(buff, GetStringPtr(str), &tmp_params, last);
443 static
char *FormatGenericCurrency(
char *buff, const
CurrencySpec *spec,
Money number,
bool compact, const
char *last)
447 bool negative = number < 0;
448 const char *multiplier =
"";
450 number *= spec->rate;
454 if (buff +
Utf8CharLen(SCC_RED) > last)
return buff;
456 buff =
strecpy(buff,
"-", last);
463 if (spec->symbol_pos != 1) buff =
strecpy(buff, spec->prefix, last);
469 if (number >= 1000000000 - 500) {
470 number = (number + 500000) / 1000000;
471 multiplier =
NBSP "M";
472 }
else if (number >= 1000000) {
473 number = (number + 500) / 1000;
474 multiplier =
NBSP "k";
479 if (separator == NULL && !
StrEmpty(_currency->separator)) separator = _currency->separator;
482 buff =
strecpy(buff, multiplier, last);
487 if (spec->symbol_pos != 0) buff =
strecpy(buff, spec->suffix, last);
490 if (buff +
Utf8CharLen(SCC_PREVIOUS_COLOUR) > last)
return buff;
491 buff +=
Utf8Encode(buff, SCC_PREVIOUS_COLOUR);
507 uint64 n =
abs(count);
509 switch (plural_form) {
518 return n != 1 ? 1 : 0;
530 return n > 1 ? 1 : 0;
537 return n % 10 == 1 && n % 100 != 11 ? 0 : n != 0 ? 1 : 2;
543 return n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4;
549 return n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
555 return n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
561 return n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
567 return n % 100 == 1 ? 0 : n % 100 == 2 ? 1 : n % 100 == 3 || n % 100 == 4 ? 2 : 3;
573 return n % 10 == 1 && n % 100 != 11 ? 0 : 1;
579 return n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2;
610 return (n == 1 ? 0 : n == 0 || (n % 100 > 1 && n % 100 < 11) ? 1 : (n % 100 > 10 && n % 100 < 20) ? 2 : 3);
615 return ((n == 1 || n == 11) ? 0 : (n == 2 || n == 12) ? 1 : ((n > 2 && n < 11) || (n > 12 && n < 20)) ? 2 : 3);
619 static const char *ParseStringChoice(
const char *b, uint form,
char **dst,
const char *last)
623 uint pos, i, mypos = 0;
625 for (i = pos = 0; i != n; i++) {
626 uint len = (byte)*b++;
627 if (i == form) mypos = pos;
631 *dst +=
seprintf(*dst, last,
"%s", b + mypos);
648 return ((input * this->multiplier) + (round && this->
shift != 0 ? 1 << (this->
shift - 1) : 0)) >> this->
shift;
658 int64
FromDisplay(int64 input,
bool round =
true, int64 divider = 1)
const
660 return ((input << this->
shift) + (round ? (this->multiplier * divider) - 1 : 0)) / (this->multiplier * divider);
679 { { 1, 0}, STR_UNITS_VELOCITY_IMPERIAL },
680 { { 103, 6}, STR_UNITS_VELOCITY_METRIC },
681 { {1831, 12}, STR_UNITS_VELOCITY_SI },
686 { { 1, 0}, STR_UNITS_POWER_IMPERIAL },
687 { {4153, 12}, STR_UNITS_POWER_METRIC },
688 { {6109, 13}, STR_UNITS_POWER_SI },
693 { {4515, 12}, STR_UNITS_WEIGHT_SHORT_IMPERIAL, STR_UNITS_WEIGHT_LONG_IMPERIAL },
694 { { 1, 0}, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC },
695 { {1000, 0}, STR_UNITS_WEIGHT_SHORT_SI, STR_UNITS_WEIGHT_LONG_SI },
700 { {4227, 4}, STR_UNITS_VOLUME_SHORT_IMPERIAL, STR_UNITS_VOLUME_LONG_IMPERIAL },
701 { {1000, 0}, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC },
702 { { 1, 0}, STR_UNITS_VOLUME_SHORT_SI, STR_UNITS_VOLUME_LONG_SI },
707 { {3597, 4}, STR_UNITS_FORCE_IMPERIAL },
708 { {3263, 5}, STR_UNITS_FORCE_METRIC },
709 { { 1, 0}, STR_UNITS_FORCE_SI },
714 { { 3, 0}, STR_UNITS_HEIGHT_IMPERIAL },
715 { { 1, 0}, STR_UNITS_HEIGHT_METRIC },
716 { { 1, 0}, STR_UNITS_HEIGHT_SI },
772 uint orig_offset = args->
offset;
784 FormatString(buff, str_arg, args, last, case_index, game_script,
true);
787 FormatString(buff, str_arg, args, last, case_index, game_script,
true);
790 args->
offset = orig_offset;
793 uint next_substr_case_index = 0;
794 char *buf_start = buff;
795 std::stack<const char *> str_stack;
796 str_stack.push(str_arg);
799 while (!str_stack.empty() && (b = Utf8Consume(&str_stack.top())) ==
'\0') {
802 if (str_stack.empty())
break;
803 const char *&str = str_stack.top();
809 if (b == 0)
continue;
814 uint64 sub_args_data[20];
815 WChar sub_args_type[20];
816 bool sub_args_need_free[20];
820 memset(sub_args_need_free, 0,
sizeof(sub_args_need_free));
825 stringid = strtol(str, &p, 16);
826 if (*p !=
':' && *p !=
'\0') {
827 while (*p !=
'\0') p++;
829 buff =
strecat(buff,
"(invalid SCC_ENCODED)", last);
833 while (*p !=
'\0') p++;
835 buff =
strecat(buff,
"(invalid StringID)", last);
840 while (*p !=
'\0' && i < 20) {
845 bool instring =
false;
852 if (*p ==
'"' && escape) {
859 instring = !instring;
866 if (*p ==
':')
break;
867 if (*p ==
'\0')
break;
874 bool lookup = (l == SCC_ENCODED);
875 if (lookup) s += len;
877 param = strtoull(s, &p, 16);
881 while (*p !=
'\0') p++;
883 buff =
strecat(buff,
"(invalid sub-StringID)", last);
889 sub_args.SetParam(i++, param);
894 sub_args_need_free[i] =
true;
895 sub_args.SetParam(i++, (uint64)(
size_t)g);
904 for (
int i = 0; i < 20; i++) {
905 if (sub_args_need_free[i])
free((
void *)sub_args.GetParam(i));
911 StringID substr = Utf8Consume(&str);
912 str_stack.push(GetStringPtr(substr));
918 str_stack.push(GetStringPtr(substr));
919 case_index = next_substr_case_index;
920 next_substr_case_index = 0;
925 case SCC_GENDER_LIST: {
927 uint offset = orig_offset + (byte)*str++;
948 WChar c = Utf8Consume(&s);
950 if (c == SCC_GENDER_INDEX) gender = (byte)s[0];
952 str = ParseStringChoice(str, gender, &buff, last);
958 case SCC_GENDER_INDEX:
967 case SCC_PLURAL_LIST: {
968 int plural_form = *str++;
969 uint offset = orig_offset + (byte)*str++;
975 case SCC_ARG_INDEX: {
976 args->
offset = orig_offset + (byte)*str++;
983 next_substr_case_index = (byte)*str++;
987 case SCC_SWITCH_CASE: {
990 uint num = (byte)*str++;
992 if ((byte)str[0] == case_index) {
998 str += 3 + (str[1] << 8) + str[2];
1005 buff =
strecpy(buff, _openttd_revision, last);
1008 case SCC_RAW_STRING_POINTER: {
1009 if (game_script)
break;
1010 const char *str = (
const char *)(
size_t)args->
GetInt64(SCC_RAW_STRING_POINTER);
1022 buff =
GetStringWithArgs(buff, str, &tmp_params, last, next_substr_case_index, game_script);
1023 next_substr_case_index = 0;
1037 uint size = b - SCC_STRING1 + 1;
1039 buff =
strecat(buff,
"(too many parameters)", last);
1042 buff =
GetStringWithArgs(buff, str, &sub_args, last, next_substr_case_index, game_script);
1044 next_substr_case_index = 0;
1049 buff = FormatCommaNumber(buff, args->
GetInt64(SCC_COMMA), last);
1053 int64 number = args->
GetInt64(SCC_DECIMAL);
1054 int digits = args->
GetInt32(SCC_DECIMAL);
1055 buff = FormatCommaNumber(buff, number, last, digits);
1060 buff = FormatNoCommaNumber(buff, args->
GetInt64(SCC_NUM), last);
1063 case SCC_ZEROFILL_NUM: {
1065 buff = FormatZerofillNumber(buff, num, args->
GetInt64(), last);
1070 buff = FormatHexNumber(buff, (uint64)args->
GetInt64(SCC_HEX), last);
1077 case SCC_CARGO_TINY: {
1086 switch (cargo_str) {
1101 buff = FormatCommaNumber(buff, amount, last);
1105 case SCC_CARGO_SHORT: {
1113 switch (cargo_str) {
1139 case SCC_CARGO_LONG: {
1150 case SCC_CARGO_LIST: {
1151 uint32 cmask = args->
GetInt32(SCC_CARGO_LIST);
1158 if (buff >= last - 2)
break;
1172 if (first) buff =
GetStringWithArgs(buff, STR_JUST_NOTHING, args, last, next_substr_case_index, game_script);
1175 next_substr_case_index = 0;
1178 assert(buff < last);
1182 case SCC_CURRENCY_SHORT:
1183 buff = FormatGenericCurrency(buff, _currency, args->
GetInt64(),
true, last);
1186 case SCC_CURRENCY_LONG:
1187 buff = FormatGenericCurrency(buff, _currency, args->
GetInt64(SCC_CURRENCY_LONG),
false, last);
1191 buff = FormatTinyOrISODate(buff, args->
GetInt32(SCC_DATE_TINY), STR_FORMAT_DATE_TINY, last);
1194 case SCC_DATE_SHORT:
1195 buff = FormatMonthAndYear(buff, args->
GetInt32(SCC_DATE_SHORT), last, next_substr_case_index);
1196 next_substr_case_index = 0;
1200 buff = FormatYmdString(buff, args->
GetInt32(SCC_DATE_LONG), last, next_substr_case_index);
1201 next_substr_case_index = 0;
1205 buff = FormatTinyOrISODate(buff, args->
GetInt32(), STR_FORMAT_DATE_ISO, last);
1232 case SCC_VELOCITY: {
1240 case SCC_VOLUME_SHORT: {
1248 case SCC_VOLUME_LONG: {
1256 case SCC_WEIGHT_SHORT: {
1264 case SCC_WEIGHT_LONG: {
1272 case SCC_COMPANY_NAME: {
1274 if (c == NULL)
break;
1276 if (c->
name != NULL) {
1277 int64 args_array[] = {(uint64)(
size_t)c->
name};
1281 int64 args_array[] = {c->
name_2};
1288 case SCC_COMPANY_NUM: {
1293 int64 args_array[] = {company + 1};
1300 case SCC_DEPOT_NAME: {
1303 uint64 args_array[] = {args->
GetInt32()};
1304 WChar types_array[] = {SCC_STATION_NAME};
1306 buff =
GetStringWithArgs(buff, STR_FORMAT_DEPOT_NAME_AIRCRAFT, &tmp_params, last);
1311 if (d->name != NULL) {
1312 int64 args_array[] = {(uint64)(
size_t)d->name};
1318 buff =
GetStringWithArgs(buff, STR_FORMAT_DEPOT_NAME_TRAIN + 2 * vt + (d->
town_cn == 0 ? 0 : 1), &tmp_params, last);
1323 case SCC_ENGINE_NAME: {
1325 if (e == NULL)
break;
1328 int64 args_array[] = {(uint64)(
size_t)e->
name};
1338 case SCC_GROUP_NAME: {
1340 if (g == NULL)
break;
1342 if (g->
name != NULL) {
1343 int64 args_array[] = {(uint64)(
size_t)g->
name};
1347 int64 args_array[] = {g->
index};
1355 case SCC_INDUSTRY_NAME: {
1357 if (i == NULL)
break;
1369 buff =
FormatString(buff, GetStringPtr(STR_FORMAT_INDUSTRY_NAME), &tmp_params, last, next_substr_case_index);
1371 next_substr_case_index = 0;
1375 case SCC_PRESIDENT_NAME: {
1377 if (c == NULL)
break;
1391 case SCC_STATION_NAME: {
1392 StationID sid = args->
GetInt32(SCC_STATION_NAME);
1404 if (st->
name != NULL) {
1405 int64 args_array[] = {(uint64)(
size_t)st->
name};
1410 if (st->
indtype != IT_INVALID) {
1422 int64 args_array[] = {STR_TOWN_NAME, st->
town->
index, st->
index};
1429 case SCC_TOWN_NAME: {
1431 if (t == NULL)
break;
1433 if (t->
name != NULL) {
1434 int64 args_array[] = {(uint64)(
size_t)t->
name};
1443 case SCC_WAYPOINT_NAME: {
1445 if (wp == NULL)
break;
1447 if (wp->
name != NULL) {
1448 int64 args_array[] = {(uint64)(
size_t)wp->
name};
1454 StringID str = ((wp->
string_id == STR_SV_STNAME_BUOY) ? STR_FORMAT_BUOY_NAME : STR_FORMAT_WAYPOINT_NAME);
1461 case SCC_VEHICLE_NAME: {
1463 if (v == NULL)
break;
1465 if (v->
name != NULL) {
1466 int64 args_array[] = {(uint64)(
size_t)v->
name};
1475 default: str = STR_INVALID_VEHICLE;
break;
1476 case VEH_TRAIN: str = STR_SV_TRAIN_NAME;
break;
1477 case VEH_ROAD: str = STR_SV_ROAD_VEHICLE_NAME;
break;
1478 case VEH_SHIP: str = STR_SV_SHIP_NAME;
break;
1487 case SCC_SIGN_NAME: {
1489 if (si == NULL)
break;
1491 if (si->name != NULL) {
1492 int64 args_array[] = {(uint64)(
size_t)si->name};
1502 case SCC_STATION_FEATURES: {
1503 buff = StationGetSpecialString(buff, args->
GetInt32(SCC_STATION_FEATURES), last);
1517 static char *StationGetSpecialString(
char *buff,
int x,
const char *last)
1528 static char *GetSpecialTownNameString(
char *buff,
int ind, uint32 seed,
const char *last)
1533 static const char *
const _silly_company_names[] = {
1535 "Tiny Transport Ltd.",
1537 "Comfy-Coach & Co.",
1538 "Crush & Bump Ltd.",
1539 "Broken & Late Ltd.",
1541 "Supersonic Travel",
1543 "Lightning International",
1544 "Pannik & Loozit Ltd.",
1545 "Inter-City Transport",
1546 "Getout & Pushit Ltd."
1549 static const char *
const _surname_list[] = {
1581 static const char *
const _silly_surname_list[] = {
1596 static const char _initial_name_letters[] = {
1597 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
1598 'K',
'L',
'M',
'N',
'P',
'R',
'S',
'T',
'W',
1601 static char *GenAndCoName(
char *buff, uint32 arg,
const char *last)
1603 const char *
const *base;
1607 base = _silly_surname_list;
1608 num =
lengthof(_silly_surname_list);
1610 base = _surname_list;
1614 buff =
strecpy(buff, base[num *
GB(arg, 16, 8) >> 8], last);
1615 buff =
strecpy(buff,
" & Co.", last);
1620 static char *GenPresidentName(
char *buff, uint32 x,
const char *last)
1622 char initial[] =
"?. ";
1623 const char *
const *base;
1627 initial[0] = _initial_name_letters[
sizeof(_initial_name_letters) *
GB(x, 0, 8) >> 8];
1628 buff =
strecpy(buff, initial, last);
1630 i = (
sizeof(_initial_name_letters) + 35) *
GB(x, 8, 8) >> 8;
1631 if (i <
sizeof(_initial_name_letters)) {
1632 initial[0] = _initial_name_letters[i];
1633 buff =
strecpy(buff, initial, last);
1637 base = _silly_surname_list;
1638 num =
lengthof(_silly_surname_list);
1640 base = _surname_list;
1644 buff =
strecpy(buff, base[num *
GB(x, 16, 8) >> 8], last);
1649 static char *GetSpecialNameString(
char *buff,
int ind,
StringParameters *args,
const char *last)
1656 return GenAndCoName(buff, args->
GetInt32(), last);
1659 return GenPresidentName(buff, args->
GetInt32(), last);
1663 if (
IsInsideMM(ind - 6, 0, SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1)) {
1664 buff = GetSpecialTownNameString(buff, ind - 6, args->
GetInt32(), last);
1665 return strecpy(buff,
" Transport", last);
1669 if (
IsInsideMM(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) {
1670 int i = ind - (SPECSTR_LANGUAGE_START - 0x70E4);
1672 &_languages[i] == _current_language ? _current_language->
own_name : _languages[i].name, last);
1676 if (
IsInsideMM(ind, (SPECSTR_RESOLUTION_START - 0x70E4), (SPECSTR_RESOLUTION_END - 0x70E4) + 1)) {
1677 int i = ind - (SPECSTR_RESOLUTION_START - 0x70E4);
1687 #ifdef ENABLE_NETWORK
1688 extern void SortNetworkLanguages();
1690 static inline void SortNetworkLanguages() {}
1700 this->
version == TO_LE32(LANGUAGE_PACK_VERSION) &&
1724 if (lang_pack == NULL)
return false;
1727 const char *end = (
char *)lang_pack + len + 1;
1730 if (end <= lang_pack->data || !lang_pack->
IsValid()) {
1735 #if TTD_ENDIAN == TTD_BIG_ENDIAN
1743 uint16 num = lang_pack->
offsets[i];
1755 char **langpack_offs = MallocT<char *>(count);
1758 char *s = lang_pack->data;
1760 for (uint i = 0; i < count; i++) {
1761 if (s + len >= end) {
1763 free(langpack_offs);
1767 len = ((len & 0x3F) << 8) + (byte)*s++;
1768 if (s + len >= end) {
1770 free(langpack_offs);
1774 langpack_offs[i] = s;
1781 _langpack = lang_pack;
1783 free(_langpack_offs);
1784 _langpack_offs = langpack_offs;
1786 _current_language = lang;
1788 const char *c_file = strrchr(_current_language->
file, PATHSEPCHAR) + 1;
1800 UErrorCode status = U_ZERO_ERROR;
1805 if (U_FAILURE(status)) {
1816 SortNetworkLanguages();
1830 #if !(defined(WIN32) || defined(__APPLE__))
1843 env = getenv(
"LANGUAGE");
1844 if (env != NULL)
return env;
1846 env = getenv(
"LC_ALL");
1847 if (env != NULL)
return env;
1849 if (param != NULL) {
1850 env = getenv(param);
1851 if (env != NULL)
return env;
1854 return getenv(
"LANG");
1864 GetString(stra, *a,
lastof(stra));
1865 GetString(strb, *b,
lastof(strb));
1878 if (newgrflangid == lang->newgrflangid)
return lang;
1892 FILE *f = fopen(file,
"rb");
1893 if (f == NULL)
return false;
1895 size_t read = fread(hdr,
sizeof(*hdr), 1, f);
1898 bool ret = read == 1 && hdr->
IsValid();
1916 struct dirent *dirent;
1917 while ((dirent = readdir(dir)) != NULL) {
1918 const char *d_name =
FS2OTTD(dirent->d_name);
1919 const char *extension = strrchr(d_name,
'.');
1922 if (extension == NULL || strcmp(extension,
".lng") != 0)
continue;
1929 DEBUG(misc, 3,
"%s is not a valid language file", lmd.
file);
1931 DEBUG(misc, 3,
"%s's language ID is already known", lmd.
file);
1933 *_languages.
Append() = lmd;
1949 char path[MAX_PATH];
1953 if (_languages.
Length() == 0)
usererror(
"No available language packs (invalid versions?)");
1957 if (lang == NULL) lang =
"en_GB";
1968 const char *lang_file = strrchr(lng->file, PATHSEPCHAR) + 1;
1970 chosen_language = lng;
1974 if (strcmp (lng->isocode,
"en_GB") == 0) en_GB_fallback = lng;
1975 if (strncmp(lng->isocode, lang, 5) == 0) chosen_language = lng;
1976 if (strncmp(lng->isocode, lang, 2) == 0) language_fallback = lng;
1981 if (chosen_language == NULL) {
1982 chosen_language = (language_fallback != NULL) ? language_fallback : en_GB_fallback;
2006 const Sprite *question_mark[FS_END];
2009 question_mark[size] =
GetGlyph(size,
'?');
2015 if (str != NULL) *str = text;
2016 for (
WChar c = Utf8Consume(&text); c !=
'\0'; c = Utf8Consume(&text)) {
2046 const char *NextString()
2053 while (this->i < TAB_COUNT && this->
j >=
_langtab_num[this->i]) {
2068 #ifdef WITH_FREETYPE
2092 if (searcher == NULL) searcher = &pack_searcher;
2094 #ifdef WITH_FREETYPE
2099 memcpy(&backup, &_freetype,
sizeof(backup));
2103 memcpy(&_freetype, &backup,
sizeof(backup));
2105 if (bad_font && base_font) {
2120 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.");
2133 #if !defined(WITH_ICU)
2148 static char *err_str =
stredup(
"XXXThis version of OpenTTD does not support right-to-left languages. Recompile with icu enabled.");