mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Add include localized file token
This commit is contained in:
@@ -33,6 +33,13 @@ A heirachical file can contain a reference to another file:
|
|||||||
Where filename must be an absolute or relative [[type:filename]].
|
Where filename must be an absolute or relative [[type:filename]].
|
||||||
|
|
||||||
That file is included literally into the current one; except for indentation, the included file never escapes from the level the 'include file' line is on.
|
That file is included literally into the current one; except for indentation, the included file never escapes from the level the 'include file' line is on.
|
||||||
|
|
||||||
|
If the file to be included can vary depending on the locale that is selected, use:
|
||||||
|
>>>include localized file: <em>filename</em>
|
||||||
|
|
||||||
|
MSE will take the filename and add "_" followed by the name of the currently selected locale at the end of it.
|
||||||
|
So for example, if the locale used is the folder "en.mse-locale", the file that will be included is "filename_en"
|
||||||
|
You must provide a version of the file for each locale found in the data folder, even if it is simply a copy of the english one.
|
||||||
|
|
||||||
--Example--
|
--Example--
|
||||||
For example, a [[type:set]] might look like this:
|
For example, a [[type:set]] might look like this:
|
||||||
|
|||||||
+12
-1
@@ -181,7 +181,18 @@ void TokenIterator::readToken() {
|
|||||||
newline = true;
|
newline = true;
|
||||||
} else if (isSpace(c)) {
|
} else if (isSpace(c)) {
|
||||||
++pos;
|
++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:")) {
|
} else if (is_substr(pos, end, "include file:")) {
|
||||||
pos += 13; // "include file:"
|
pos += 13; // "include file:"
|
||||||
const char* newlines = "\r\n";
|
const char* newlines = "\r\n";
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <util/error.hpp>
|
#include <util/error.hpp>
|
||||||
#include <util/io/package_manager.hpp>
|
#include <util/io/package_manager.hpp>
|
||||||
#include <boost/logic/tribool.hpp>
|
#include <boost/logic/tribool.hpp>
|
||||||
|
#include <data/settings.hpp>
|
||||||
#undef small
|
#undef small
|
||||||
using boost::tribool;
|
using boost::tribool;
|
||||||
|
|
||||||
@@ -356,6 +357,10 @@ template <> void Reader::handle(Vector2D& vec) {
|
|||||||
template <> void Reader::handle(LocalFileName& f) {
|
template <> void Reader::handle(LocalFileName& f) {
|
||||||
f = LocalFileName::fromReadString(this->getValue());
|
f = LocalFileName::fromReadString(this->getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String Reader::addLocale(String filename) {
|
||||||
|
return filename + _("_") + settings.locale;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : EnumReader
|
// ----------------------------------------------------------------------------- : EnumReader
|
||||||
|
|
||||||
|
|||||||
@@ -116,7 +116,9 @@ public:
|
|||||||
|
|
||||||
/// The package being read from
|
/// The package being read from
|
||||||
inline Packaged* getPackage() const { return package; }
|
inline Packaged* getPackage() const { return package; }
|
||||||
|
|
||||||
|
String addLocale(String);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// --------------------------------------------------- : Data
|
// --------------------------------------------------- : Data
|
||||||
/// App version this file was made with
|
/// App version this file was made with
|
||||||
@@ -175,7 +177,8 @@ private:
|
|||||||
/** Maybe the key is "include file" */
|
/** Maybe the key is "include file" */
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void unknownKey(T& v) {
|
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);
|
auto [stream, include_package] = openFileFromPackage(package, value);
|
||||||
Reader sub_reader(*stream, include_package, value, ignore_invalid);
|
Reader sub_reader(*stream, include_package, value, ignore_invalid);
|
||||||
if (sub_reader.file_app_version == 0) {
|
if (sub_reader.file_app_version == 0) {
|
||||||
|
|||||||
@@ -177,6 +177,8 @@ function highlight_script($code) {
|
|||||||
. "<span class='hl-num'>" . $matches[4] . "</span>)</span>";
|
. "<span class='hl-num'>" . $matches[4] . "</span>)</span>";
|
||||||
} else if (preg_match("@^(if|then|else|for( each)?|in(?= )|do|div|mod|and|or|xor|not|rgb|rgba|from|to|min|max)\b(?!:)@",$code, $matches)) {
|
} else if (preg_match("@^(if|then|else|for( each)?|in(?= )|do|div|mod|and|or|xor|not|rgb|rgba|from|to|min|max)\b(?!:)@",$code, $matches)) {
|
||||||
$ret .= "<span class='hl-kw'>" . $matches[0] . "</span>";
|
$ret .= "<span class='hl-kw'>" . $matches[0] . "</span>";
|
||||||
|
} else if (preg_match("@^(include localized file:)(.*)@",$code, $matches)) {
|
||||||
|
$ret .= "<span class='hl-key'>" . $matches[1] . "</span>" . $matches[2];
|
||||||
} else if (preg_match("@^(include file:)(.*)@",$code, $matches)) {
|
} else if (preg_match("@^(include file:)(.*)@",$code, $matches)) {
|
||||||
$ret .= "<span class='hl-key'>" . $matches[1] . "</span>" . $matches[2];
|
$ret .= "<span class='hl-key'>" . $matches[1] . "</span>" . $matches[2];
|
||||||
} else if (preg_match("@^([0-9][0-9.]*|true|false)@",$code, $matches)) {
|
} else if (preg_match("@^([0-9][0-9.]*|true|false)@",$code, $matches)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user