Add include localized file token

This commit is contained in:
GenevensiS
2025-03-11 02:31:22 +01:00
committed by GitHub
5 changed files with 31 additions and 3 deletions
+12 -1
View File
@@ -181,7 +181,18 @@ void TokenIterator::readToken() {
newline = true;
} else if (isSpace(c)) {
++pos;
// ignore
// ignore
} else if (is_substr(pos, end, "include localized file:")) {
pos += 23; // "include localized file:"
const char* newlines = "\r\n";
auto eol = find_first_of(pos, end, newlines, newlines + 2);
String include_file = trim(StringView(pos, eol)) + _("_") + settings.locale;
// include_file("filename_en")
addToken(TOK_NAME, "include_file", pos - 23);
addToken(TOK_LPAREN, "(", pos);
addToken(TOK_STRING, include_file, pos);
addToken(TOK_RPAREN, ")", eol);
pos = eol;
} else if (is_substr(pos, end, "include file:")) {
pos += 13; // "include file:"
const char* newlines = "\r\n";
+5
View File
@@ -12,6 +12,7 @@
#include <util/error.hpp>
#include <util/io/package_manager.hpp>
#include <boost/logic/tribool.hpp>
#include <data/settings.hpp>
#undef small
using boost::tribool;
@@ -356,6 +357,10 @@ template <> void Reader::handle(Vector2D& vec) {
template <> void Reader::handle(LocalFileName& f) {
f = LocalFileName::fromReadString(this->getValue());
}
String Reader::addLocale(String filename) {
return filename + _("_") + settings.locale;
}
// ----------------------------------------------------------------------------- : EnumReader
+5 -2
View File
@@ -116,7 +116,9 @@ public:
/// The package being read from
inline Packaged* getPackage() const { return package; }
String addLocale(String);
private:
// --------------------------------------------------- : Data
/// App version this file was made with
@@ -175,7 +177,8 @@ private:
/** Maybe the key is "include file" */
template <typename T>
void unknownKey(T& v) {
if (key == _("include_file")) {
if (key == _("include_file") || key == _("include_localized_file")) {
value = key == _("include_localized_file") ? addLocale(value) : value;
auto [stream, include_package] = openFileFromPackage(package, value);
Reader sub_reader(*stream, include_package, value, ignore_invalid);
if (sub_reader.file_app_version == 0) {