OpenTTD Source  14.0-RC1
strgen.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "../stdafx.h"
11 #include "../core/endian_func.hpp"
12 #include "../core/mem_func.hpp"
13 #include "../error_func.h"
14 #include "../string_func.h"
15 #include "../strings_type.h"
16 #include "../misc/getoptdata.h"
17 #include "../table/control_codes.h"
18 #include "../3rdparty/fmt/std.h"
19 
20 #include "strgen.h"
21 
22 #include <filesystem>
23 #include <fstream>
24 
25 #include "../table/strgen_tables.h"
26 
27 #include "../safeguards.h"
28 
29 
30 #ifdef _MSC_VER
31 # define LINE_NUM_FMT(s) "{} ({}): warning: {} (" s ")\n"
32 #else
33 # define LINE_NUM_FMT(s) "{}:{}: " s ": {}\n"
34 #endif
35 
36 void StrgenWarningI(const std::string &msg)
37 {
38  if (_show_todo > 0) {
39  fmt::print(stderr, LINE_NUM_FMT("warning"), _file, _cur_line, msg);
40  } else {
41  fmt::print(stderr, LINE_NUM_FMT("info"), _file, _cur_line, msg);
42  }
43  _warnings++;
44 }
45 
46 void StrgenErrorI(const std::string &msg)
47 {
48  fmt::print(stderr, LINE_NUM_FMT("error"), _file, _cur_line, msg);
49  _errors++;
50 }
51 
52 [[noreturn]] void StrgenFatalI(const std::string &msg)
53 {
54  fmt::print(stderr, LINE_NUM_FMT("FATAL"), _file, _cur_line, msg);
55 #ifdef _MSC_VER
56  fmt::print(stderr, LINE_NUM_FMT("warning"), _file, _cur_line, "language is not compiled");
57 #endif
58  throw std::exception();
59 }
60 
61 [[noreturn]] void FatalErrorI(const std::string &msg)
62 {
63  fmt::print(stderr, LINE_NUM_FMT("FATAL"), _file, _cur_line, msg);
64 #ifdef _MSC_VER
65  fmt::print(stderr, LINE_NUM_FMT("warning"), _file, _cur_line, "language is not compiled");
66 #endif
67  exit(2);
68 }
69 
72  std::ifstream input_stream;
73 
81  FileStringReader(StringData &data, const std::filesystem::path &file, bool master, bool translation) :
82  StringReader(data, file.generic_string(), master, translation)
83  {
84  this->input_stream.open(file, std::ifstream::binary);
85  }
86 
87  std::optional<std::string> ReadLine() override
88  {
89  std::string result;
90  if (!std::getline(this->input_stream, result)) return std::nullopt;
91  return result;
92  }
93 
94  void HandlePragma(char *str) override;
95 
96  void ParseFile() override
97  {
99 
101  FatalError("Language must include ##name, ##ownname and ##isocode");
102  }
103  }
104 };
105 
107 {
108  if (!memcmp(str, "id ", 3)) {
109  this->data.next_string_id = std::strtoul(str + 3, nullptr, 0);
110  } else if (!memcmp(str, "name ", 5)) {
111  strecpy(_lang.name, str + 5, lastof(_lang.name));
112  } else if (!memcmp(str, "ownname ", 8)) {
114  } else if (!memcmp(str, "isocode ", 8)) {
115  strecpy(_lang.isocode, str + 8, lastof(_lang.isocode));
116  } else if (!memcmp(str, "textdir ", 8)) {
117  if (!memcmp(str + 8, "ltr", 3)) {
119  } else if (!memcmp(str + 8, "rtl", 3)) {
121  } else {
122  FatalError("Invalid textdir {}", str + 8);
123  }
124  } else if (!memcmp(str, "numberformat ", 13)) {
125  str += 13;
126 
127  NumberFormatSeparators separators;
128  auto result = ParseNumberFormatSeparators(separators, str);
129  if (result.has_value()) FatalError("Invalid number format: {}", *result);
130 
132  } else if (!memcmp(str, "numberabbreviations ", 20)) {
133  str += 20;
134 
135  NumberAbbreviations abbreviations;
136  auto result = ParseNumberAbbreviations(abbreviations, str);
137  if (result.has_value()) FatalError("Invalid number abbreviations: {}", *result);
138 
140  } else if (!memcmp(str, "decimalsep ", 11)) {
141  str += 11;
142  strecpy(_lang.digit_decimal_separator, strcmp(str, "{NBSP}") == 0 ? NBSP : str, lastof(_lang.digit_decimal_separator));
143  } else if (!memcmp(str, "winlangid ", 10)) {
144  const char *buf = str + 10;
145  long langid = std::strtol(buf, nullptr, 16);
146  if (langid > (long)UINT16_MAX || langid < 0) {
147  FatalError("Invalid winlangid {}", buf);
148  }
149  _lang.winlangid = (uint16_t)langid;
150  } else if (!memcmp(str, "grflangid ", 10)) {
151  const char *buf = str + 10;
152  long langid = std::strtol(buf, nullptr, 16);
153  if (langid >= 0x7F || langid < 0) {
154  FatalError("Invalid grflangid {}", buf);
155  }
156  _lang.newgrflangid = (uint8_t)langid;
157  } else if (!memcmp(str, "gender ", 7)) {
158  if (this->master) FatalError("Genders are not allowed in the base translation.");
159  char *buf = str + 7;
160 
161  for (;;) {
162  const char *s = ParseWord(&buf);
163 
164  if (s == nullptr) break;
165  if (_lang.num_genders >= MAX_NUM_GENDERS) FatalError("Too many genders, max {}", MAX_NUM_GENDERS);
167  _lang.num_genders++;
168  }
169  } else if (!memcmp(str, "case ", 5)) {
170  if (this->master) FatalError("Cases are not allowed in the base translation.");
171  char *buf = str + 5;
172 
173  for (;;) {
174  const char *s = ParseWord(&buf);
175 
176  if (s == nullptr) break;
177  if (_lang.num_cases >= MAX_NUM_CASES) FatalError("Too many cases, max {}", MAX_NUM_CASES);
179  _lang.num_cases++;
180  }
181  } else {
183  }
184 }
185 
186 bool CompareFiles(const std::filesystem::path &path1, const std::filesystem::path &path2)
187 {
188  /* Check for equal size, but ignore the error code for cases when a file does not exist. */
189  std::error_code error_code;
190  if (std::filesystem::file_size(path1, error_code) != std::filesystem::file_size(path2, error_code)) return false;
191 
192  std::ifstream stream1(path1, std::ifstream::binary);
193  std::ifstream stream2(path2, std::ifstream::binary);
194 
195  return std::equal(std::istreambuf_iterator<char>(stream1.rdbuf()),
196  std::istreambuf_iterator<char>(),
197  std::istreambuf_iterator<char>(stream2.rdbuf()));
198 }
199 
201 struct FileWriter {
202  std::ofstream output_stream;
203  const std::filesystem::path path;
204 
210  FileWriter(const std::filesystem::path &path, std::ios_base::openmode openmode) : path(path)
211  {
212  this->output_stream.open(path, openmode);
213  }
214 
216  void Finalise()
217  {
218  this->output_stream.close();
219  }
220 
222  virtual ~FileWriter()
223  {
224  /* If we weren't closed an exception was thrown, so remove the temporary file. */
225  if (this->output_stream.is_open()) {
226  this->output_stream.close();
227  std::filesystem::remove(this->path);
228  }
229  }
230 };
231 
234  const std::filesystem::path real_path;
236  int prev;
237  uint total_strings;
238 
243  HeaderFileWriter(const std::filesystem::path &path) : FileWriter("tmp.xxx", std::ofstream::out),
244  real_path(path), prev(0), total_strings(0)
245  {
246  this->output_stream << "/* This file is automatically generated. Do not modify */\n\n";
247  this->output_stream << "#ifndef TABLE_STRINGS_H\n";
248  this->output_stream << "#define TABLE_STRINGS_H\n";
249  }
250 
251  void WriteStringID(const std::string &name, int stringid) override
252  {
253  if (prev + 1 != stringid) this->output_stream << "\n";
254  fmt::print(this->output_stream, "static const StringID {} = 0x{:X};\n", name, stringid);
255  prev = stringid;
256  total_strings++;
257  }
258 
259  void Finalise(const StringData &data) override
260  {
261  /* Find the plural form with the most amount of cases. */
262  int max_plural_forms = 0;
263  for (uint i = 0; i < lengthof(_plural_forms); i++) {
264  max_plural_forms = std::max(max_plural_forms, _plural_forms[i].plural_count);
265  }
266 
267  fmt::print(this->output_stream,
268  "\n"
269  "static const uint LANGUAGE_PACK_VERSION = 0x{:X};\n"
270  "static const uint LANGUAGE_MAX_PLURAL = {};\n"
271  "static const uint LANGUAGE_MAX_PLURAL_FORMS = {};\n"
272  "static const uint LANGUAGE_TOTAL_STRINGS = {};\n"
273  "\n",
274  data.Version(), lengthof(_plural_forms), max_plural_forms, total_strings
275  );
276 
277  this->output_stream << "#endif /* TABLE_STRINGS_H */\n";
278 
279  this->FileWriter::Finalise();
280 
281  std::error_code error_code;
282  if (CompareFiles(this->path, this->real_path)) {
283  /* files are equal. tmp.xxx is not needed */
284  std::filesystem::remove(this->path, error_code); // Just ignore the error
285  } else {
286  /* else rename tmp.xxx into filename */
287 # if defined(_WIN32)
288  std::filesystem::remove(this->real_path, error_code); // Just ignore the error, file probably doesn't exist
289 # endif
290  std::filesystem::rename(this->path, this->real_path, error_code);
291  if (error_code) FatalError("rename({}, {}) failed: {}", this->path, this->real_path, error_code.message());
292  }
293  }
294 };
295 
302  LanguageFileWriter(const std::filesystem::path &path) : FileWriter(path, std::ofstream::binary | std::ofstream::out)
303  {
304  }
305 
306  void WriteHeader(const LanguagePackHeader *header) override
307  {
308  this->Write((const byte *)header, sizeof(*header));
309  }
310 
311  void Finalise() override
312  {
313  this->output_stream.put(0);
314  this->FileWriter::Finalise();
315  }
316 
317  void Write(const byte *buffer, size_t length) override
318  {
319  this->output_stream.write((const char *)buffer, length);
320  }
321 };
322 
324 static const OptionData _opts[] = {
325  GETOPT_GENERAL('C', '\0', "-export-commands", ODF_NO_VALUE),
326  GETOPT_GENERAL('L', '\0', "-export-plurals", ODF_NO_VALUE),
327  GETOPT_GENERAL('P', '\0', "-export-pragmas", ODF_NO_VALUE),
328  GETOPT_NOVAL( 't', "--todo"),
329  GETOPT_NOVAL( 'w', "--warning"),
330  GETOPT_NOVAL( 'h', "--help"),
331  GETOPT_GENERAL('h', '?', nullptr, ODF_NO_VALUE),
332  GETOPT_VALUE( 's', "--source_dir"),
333  GETOPT_VALUE( 'd', "--dest_dir"),
334  GETOPT_END(),
335 };
336 
337 int CDECL main(int argc, char *argv[])
338 {
339  std::filesystem::path src_dir(".");
340  std::filesystem::path dest_dir;
341 
342  GetOptData mgo(argc - 1, argv + 1, _opts);
343  for (;;) {
344  int i = mgo.GetOpt();
345  if (i == -1) break;
346 
347  switch (i) {
348  case 'C':
349  fmt::print("args\tflags\tcommand\treplacement\n");
350  for (const CmdStruct *cs = _cmd_structs; cs < endof(_cmd_structs); cs++) {
351  char flags;
352  if (cs->proc == EmitGender) {
353  flags = 'g'; // Command needs number of parameters defined by number of genders
354  } else if (cs->proc == EmitPlural) {
355  flags = 'p'; // Command needs number of parameters defined by plural value
356  } else if (cs->flags & C_DONTCOUNT) {
357  flags = 'i'; // Command may be in the translation when it is not in base
358  } else {
359  flags = '0'; // Command needs no parameters
360  }
361  fmt::print("{}\t{:c}\t\"{}\"\t\"{}\"\n", cs->consumes, flags, cs->cmd, strstr(cs->cmd, "STRING") ? "STRING" : cs->cmd);
362  }
363  return 0;
364 
365  case 'L':
366  fmt::print("count\tdescription\tnames\n");
367  for (const PluralForm *pf = _plural_forms; pf < endof(_plural_forms); pf++) {
368  fmt::print("{}\t\"{}\"\t{}\n", pf->plural_count, pf->description, pf->names);
369  }
370  return 0;
371 
372  case 'P':
373  fmt::print("name\tflags\tdefault\tdescription\n");
374  for (size_t j = 0; j < lengthof(_pragmas); j++) {
375  fmt::print("\"{}\"\t{}\t\"{}\"\t\"{}\"\n",
376  _pragmas[j][0], _pragmas[j][1], _pragmas[j][2], _pragmas[j][3]);
377  }
378  return 0;
379 
380  case 't':
381  _show_todo |= 1;
382  break;
383 
384  case 'w':
385  _show_todo |= 2;
386  break;
387 
388  case 'h':
389  fmt::print(
390  "strgen\n"
391  " -t | --todo replace any untranslated strings with '<TODO>'\n"
392  " -w | --warning print a warning for any untranslated strings\n"
393  " -h | -? | --help print this help message and exit\n"
394  " -s | --source_dir search for english.txt in the specified directory\n"
395  " -d | --dest_dir put output file in the specified directory, create if needed\n"
396  " -export-commands export all commands and exit\n"
397  " -export-plurals export all plural forms and exit\n"
398  " -export-pragmas export all pragmas and exit\n"
399  " Run without parameters and strgen will search for english.txt and parse it,\n"
400  " creating strings.h. Passing an argument, strgen will translate that language\n"
401  " file using english.txt as a reference and output <language>.lng.\n"
402  );
403  return 0;
404 
405  case 's':
406  src_dir = mgo.opt;
407  break;
408 
409  case 'd':
410  dest_dir = mgo.opt;
411  break;
412 
413  case -2:
414  fmt::print(stderr, "Invalid arguments\n");
415  return 0;
416  }
417  }
418 
419  if (dest_dir.empty()) dest_dir = src_dir; // if dest_dir is not specified, it equals src_dir
420 
421  try {
422  /* strgen has two modes of operation. If no (free) arguments are passed
423  * strgen generates strings.h to the destination directory. If it is supplied
424  * with a (free) parameter the program will translate that language to destination
425  * directory. As input english.txt is parsed from the source directory */
426  if (mgo.numleft == 0) {
427  std::filesystem::path input_path = src_dir;
428  input_path /= "english.txt";
429 
430  /* parse master file */
431  StringData data(TEXT_TAB_END);
432  FileStringReader master_reader(data, input_path, true, false);
433  master_reader.ParseFile();
434  if (_errors != 0) return 1;
435 
436  /* write strings.h */
437  std::filesystem::path output_path = dest_dir;
438  std::filesystem::create_directories(dest_dir);
439  output_path /= "strings.h";
440 
441  HeaderFileWriter writer(output_path);
442  writer.WriteHeader(data);
443  writer.Finalise(data);
444  if (_errors != 0) return 1;
445  } else if (mgo.numleft >= 1) {
446  std::filesystem::path input_path = src_dir;
447  input_path /= "english.txt";
448 
449  StringData data(TEXT_TAB_END);
450  /* parse master file and check if target file is correct */
451  FileStringReader master_reader(data, input_path, true, false);
452  master_reader.ParseFile();
453 
454  for (int i = 0; i < mgo.numleft; i++) {
455  data.FreeTranslation();
456 
457  std::filesystem::path lang_file = mgo.argv[i];
458  FileStringReader translation_reader(data, lang_file, false, lang_file.filename() != "english.txt");
459  translation_reader.ParseFile(); // target file
460  if (_errors != 0) return 1;
461 
462  /* get the targetfile, strip any directories and append to destination path */
463  std::filesystem::path output_file = dest_dir;
464  output_file /= lang_file.filename();
465  output_file.replace_extension("lng");
466 
467  LanguageFileWriter writer(output_file);
468  writer.WriteLang(data);
469  writer.Finalise();
470 
471  /* if showing warnings, print a summary of the language */
472  if ((_show_todo & 2) != 0) {
473  fmt::print("{} warnings and {} errors for {}\n", _warnings, _errors, output_file);
474  }
475  }
476  }
477  } catch (...) {
478  return 2;
479  }
480 
481  return 0;
482 }
_file
const char * _file
The filename of the input, so we can refer to it in errors/warnings.
Definition: strgen_base.cpp:29
LanguageFileWriter::WriteHeader
void WriteHeader(const LanguagePackHeader *header) override
Write the header metadata.
Definition: strgen.cpp:306
LanguagePackHeader::text_dir
byte text_dir
default direction of the text
Definition: language.h:42
StringReader::HandlePragma
virtual void HandlePragma(char *str)
Handle the pragma of the file.
Definition: strgen_base.cpp:729
CompareFiles
static bool CompareFiles(const char *n1, const char *n2)
Compare two files for identity.
Definition: settingsgen.cpp:356
LanguageFileWriter::Write
void Write(const byte *buffer, size_t length) override
Write a number of bytes.
Definition: strgen.cpp:317
TEXT_TAB_END
@ TEXT_TAB_END
End of language files.
Definition: strings_type.h:38
FileWriter::output_stream
std::ofstream output_stream
The stream to write all the output to.
Definition: strgen.cpp:202
LanguagePackHeader::num_cases
uint8_t num_cases
the number of cases of this language
Definition: language.h:54
_opts
static const OptionData _opts[]
Options of strgen.
Definition: strgen.cpp:324
TD_LTR
@ TD_LTR
Text is written left-to-right by default.
Definition: strings_type.h:23
LanguageFileWriter
Class for writing a language to disk.
Definition: strgen.cpp:297
PluralForm
Description of a plural form.
Definition: strgen_tables.h:161
LanguageFileWriter::LanguageFileWriter
LanguageFileWriter(const std::filesystem::path &path)
Open a file to write to.
Definition: strgen.cpp:302
GETOPT_VALUE
#define GETOPT_VALUE(shortname, longname)
Short option with value.
Definition: getoptdata.h:76
HeaderWriter
Base class for writing the header, i.e.
Definition: strgen.h:87
HeaderFileWriter::HeaderFileWriter
HeaderFileWriter(const std::filesystem::path &path)
Open a file to write to.
Definition: strgen.cpp:243
LanguagePackHeader::genders
char genders[MAX_NUM_GENDERS][CASE_GENDER_LEN]
the genders used by this translation
Definition: language.h:57
LanguagePackHeader::num_genders
uint8_t num_genders
the number of genders of this language
Definition: language.h:53
LanguagePackHeader::newgrflangid
uint8_t newgrflangid
newgrf language id
Definition: language.h:52
_lang
LanguagePackHeader _lang
Header information about a language.
Definition: strgen_base.cpp:32
C_DONTCOUNT
@ C_DONTCOUNT
These commands aren't counted for comparison.
Definition: strgen_tables.h:14
_cur_line
int _cur_line
The current line we're parsing in the input file.
Definition: strgen_base.cpp:30
FileStringReader::HandlePragma
void HandlePragma(char *str) override
Handle the pragma of the file.
Definition: strgen.cpp:106
StrEmpty
bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:56
HeaderFileWriter::prev
int prev
The previous string ID that was printed.
Definition: strgen.cpp:236
StringReader::master
bool master
Are we reading the master file?
Definition: strgen.h:61
NumberAbbreviations
std::vector< NumberAbbreviation > NumberAbbreviations
Lookup for abbreviated formats for different powers of ten.
Definition: language.h:126
StringData::next_string_id
size_t next_string_id
The next string ID to allocate.
Definition: strgen.h:46
NBSP
#define NBSP
A non-breaking space.
Definition: string_type.h:16
FileWriter::FileWriter
FileWriter(const std::filesystem::path &path, std::ios_base::openmode openmode)
Open a file to write to.
Definition: strgen.cpp:210
LanguagePackHeader::cases
char cases[MAX_NUM_CASES][CASE_GENDER_LEN]
the cases used by this translation
Definition: language.h:58
StringData::Version
uint Version() const
Make a hash of the file to get a unique "version number".
Definition: strgen_base.cpp:128
MAX_NUM_CASES
static const uint8_t MAX_NUM_CASES
Maximum number of supported cases.
Definition: language.h:21
HeaderFileWriter
Definition: strgen.cpp:232
StringData
Information about the currently known strings.
Definition: strgen.h:41
GETOPT_NOVAL
#define GETOPT_NOVAL(shortname, longname)
Short option without value.
Definition: getoptdata.h:69
HeaderFileWriter::WriteStringID
void WriteStringID(const std::string &name, int stringid) override
Write the string ID.
Definition: strgen.cpp:251
GETOPT_END
#define GETOPT_END()
Option terminator.
Definition: getoptdata.h:107
FatalErrorI
void FatalErrorI(const std::string &msg)
Error handling for fatal non-user errors.
Definition: strgen.cpp:61
strgen.h
ParseNumberFormatSeparators
std::optional< std::string > ParseNumberFormatSeparators(NumberFormatSeparators &separators, std::string_view format, size_t length=DIGITS_IN_UINT64_T)
Parse the NumberFormatSeparators out of the given format string, with the expected number of digits.
Definition: strgen_base.cpp:1022
GETOPT_GENERAL
#define GETOPT_GENERAL(id, shortname, longname, flags)
General macro for creating an option.
Definition: getoptdata.h:62
MAX_NUM_GENDERS
static const uint8_t MAX_NUM_GENDERS
Maximum number of supported genders.
Definition: language.h:20
LanguagePackHeader::name
char name[32]
the international name of this language
Definition: language.h:29
HeaderFileWriter::Finalise
void Finalise(const StringData &data) override
Finalise writing the file.
Definition: strgen.cpp:259
CmdStruct
Definition: strgen_tables.h:23
FileStringReader
A reader that simply reads using fopen.
Definition: strgen.cpp:71
OptionData
Data of an option.
Definition: getoptdata.h:22
LanguagePackHeader::digit_decimal_separator
char digit_decimal_separator[8]
Decimal separator.
Definition: language.h:39
LanguagePackHeader::own_name
char own_name[32]
the localized name of this language
Definition: language.h:30
GetOptData
Data storage for parsing command line options.
Definition: getoptdata.h:30
LanguagePackHeader::isocode
char isocode[16]
the ISO code for the language (not country code)
Definition: language.h:31
main
int CDECL main(int argc, char *argv[])
And the main program (what else?)
Definition: settingsgen.cpp:433
FileStringReader::ParseFile
void ParseFile() override
Start parsing the file.
Definition: strgen.cpp:96
_pragmas
static const char *const _pragmas[][4]
All pragmas used.
Definition: strgen_tables.h:202
endof
#define endof(x)
Get the end element of an fixed size array.
Definition: stdafx.h:308
FileStringReader::ReadLine
std::optional< std::string > ReadLine() override
Read a single line from the source of strings.
Definition: strgen.cpp:87
StringReader::data
StringData & data
The data to fill during reading.
Definition: strgen.h:59
HeaderFileWriter::real_path
const std::filesystem::path real_path
The real path we eventually want to write to.
Definition: strgen.cpp:234
LanguagePackHeader::number_abbreviations
char number_abbreviations[256]
The raw formatting string for number abbreviations.
Definition: language.h:37
StringReader::translation
bool translation
Are we reading a translation, implies !master. However, the base translation will have this false.
Definition: strgen.h:62
StringReader::ParseFile
virtual void ParseFile()
Start parsing the file.
Definition: strgen_base.cpp:746
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:300
LanguageWriter
Base class for all language writers.
Definition: strgen.h:108
LanguagePackHeader::number_format
char number_format[64]
The raw formatting string for numbers.
Definition: language.h:35
LanguagePackHeader::winlangid
uint16_t winlangid
Windows language ID: Windows cannot and will not convert isocodes to something it can use to determin...
Definition: language.h:51
FileStringReader::FileStringReader
FileStringReader(StringData &data, const std::filesystem::path &file, bool master, bool translation)
Create the reader.
Definition: strgen.cpp:81
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: string.cpp:65
FileWriter::~FileWriter
virtual ~FileWriter()
Make sure the file is closed.
Definition: strgen.cpp:222
FileWriter::Finalise
void Finalise()
Finalise the writing.
Definition: strgen.cpp:216
FileWriter::path
const std::filesystem::path path
The file name we're writing to.
Definition: strgen.cpp:203
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:316
ParseNumberAbbreviations
std::optional< std::string > ParseNumberAbbreviations(NumberAbbreviations &abbreviations, std::string_view input)
Parse the NumberAbbreviations out of the given input string.
Definition: strgen_base.cpp:1063
_plural_forms
static const PluralForm _plural_forms[]
All plural forms used.
Definition: strgen_tables.h:171
LanguageFileWriter::Finalise
void Finalise() override
Finalise writing the file.
Definition: strgen.cpp:311
ODF_NO_VALUE
@ ODF_NO_VALUE
A plain option (no value attached to it).
Definition: getoptdata.h:15
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
StringReader
Helper for reading strings.
Definition: strgen.h:58
NumberFormatSeparators
std::array< std::string, DIGITS_IN_UINT64_T > NumberFormatSeparators
Table with the text to place after each of the digits of a number.
Definition: language.h:118
StringReader::file
const std::string file
The file we are reading.
Definition: strgen.h:60
LanguagePackHeader
Header of a language file.
Definition: language.h:24
FileWriter
Yes, simply writing to a file.
Definition: saveload.cpp:2207