mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-14 03:11:19 +00:00
Add orca-translations Claude skill and PO tool (#16436)
* Add orca-translations Claude skill and PO tool
Add a .claude skill that guides translation passes over the localization/i18n gettext catalogs. It covers the workflow: run gettext, settle new glossary terms, translate in batches, verify, and report.
Includes translation-rules.md, which condenses the placeholder, line-break and glossary rules plus the guidance on review notes.
Also adds scripts/po_tool.py (standard library only). It lists pending entries with glossary hints, validates and applies translations, adding '# AI Translated' and '# Needs human review' comments, and rewrites only the entries it changes. It can also check catalogs, look up existing translations, suggest glossary candidates and update the wiki glossary TSV.
* Let po_tool apply translations by entry id
pending now gives each entry a short id, so a translation file can name
entries by id instead of repeating the English msgid. apply accepts either.
A "review": "" item clears an earlier review note when overwriting an
entry, and check gives each msgfmt run its own temporary output file so
parallel checks do not collide.
* Fill all empty translations
Regenerate the template with run_gettext --full and translate every empty
entry in the 22 catalogs (7,089 entries) with the orca-translations skill,
following the localization glossary, including the new belt printer,
IDEX/IQEX and plugin terms. Every new entry is marked "# AI Translated";
122 also carry "# Needs human review" with what to check.
* Show entry ids in po_tool lookup and search translations
lookup now prints each entry's id, so an entry found there can be
rewritten with apply --overwrite without repeating the English, and
--msgstr searches the translations instead of the msgids, which finds
every entry that still uses a term being changed.
SKILL.md describes how to change an established term: check the
catalog's usage first, update the glossary cell, then rewrite only the
entries where the term has that meaning.
* Fix mistranslated terms and align catalogs with the glossary
Correct labels that the glossary had copied, and the entries that used
them:
- ca: Raft was rendered as the Brim term; it is now "Rai". Exhaust fan,
Monotonic line, Unretract, Slice, Lateral Honeycomb and PA Tower
labels fixed.
- cs: Lightning infill is "Blesk", not "Osvětlení" (illumination).
- sv: Retraction is "Retraktion", not "Reduktion"; Unretract,
Lagerhöjd, Delkylningsfläkt, Utsugsfläkt, Aligned Rectilinear and the
Preset label fixed.
- de: Brim is "Rand" and Skirt is "Umrandung", as most entries already
had them.
- lt: brim entries used the Skirt word "apvadas"; they now use "kraštas".
- es: Sparse infill is "relleno de baja densidad", the catalog majority.
- eu: nozzle wipe is "garbiketa", not purge.
- th: the project plate is "เพลต", distinct from the bed.
- uk: Quarter Cubic, Latin "PA" in PA Tower, and Belt purge tower.
- pl: Cross Hatch, Tri-hexagon, Volumetric speed and Raft labels.
- zh_TW: Brim stays "Brim", as the existing labels have it.
- tr: "Prime Tower" read "Prime Minister Tower".
- ko: the plugin "Capabilities" label read "performance".
- Build Volume labels fixed in tr, de, cs and eu.
All 242 rewritten entries are marked "# AI Translated".
* Make more UI text translatable and fix pluralization and context
Audit the sources for text that translators could not translate
correctly and fix it.
Mark text that reached users in English only: IDEX/IQEX role names,
plugin permission prompts and errors, 3MF/preset loading errors, G-code
placeholder parser errors, calibration and device messages, notification
texts, file dialog filters, and the config validation messages.
Replace sentences built from translated fragments, such as the prime
tower warnings, "left"/"right" nozzle names, and "Filament " + number,
with single msgids that have placeholders, so translators can reorder
and inflect them.
Use plural forms for texts with a count ("%1% mixed filaments",
"%d objects", "%1% triangles") instead of "(s)" and mismatched verbs.
Fix the swapped singular/plural pair in "The following presets inherit
this preset".
Add translation contexts where one English word has several meanings
(Subscribed/Local, Standard, Pause, View, Step, Model, Camera, Flow,
Filter, Others, Prepare, the Design tools). Show "Size" instead of
"Build Volume" in the Cut tool, which displays the object size.
Fix code that compared translated text with English (the Edit G-code
dialog group, the plugin registration failure check), and add the
bundled web pages' missing string-table entries. Use the single
character for degrees Celsius, say "G-code", and describe the head
filament map without internal jargon.
Install the libslic3r translate callback before the presets load, so
their load errors are translated, and list the 28 source files that had
marked strings but were never extracted into localization/i18n/list.txt.
* Suggest earlier translations and list fuzzy entries in po_tool pending
pending now attaches the closest earlier translation of a similar
English text (from obsolete or translated entries), so a reworded or
split string keeps its wording, and it lists fuzzy entries by default,
since users never see them. A fuzzy entry also carries its stale
translation as previous_translation.
* Fix wording of the non-boolean operands error
The logical operation error said "operators" where it means the
operands the operation was applied to.
* Translate the newly translatable strings in all languages
Regenerate the template after the translatability changes and fill every
new or changed entry in the 22 catalogs (about 12,800 entries): the
strings that became translatable, the plural forms, the entries split by
context, and the previously fuzzy singular entries that became plurals.
Every new entry is marked "# AI Translated", and about 360 also carry a
"# Needs human review" note saying what to check. Terms follow the
localization glossary. Earlier translations of reworded strings were
reused where the meaning was unchanged. Existing entries were not
changed, and obsolete entries are kept.
* Document the source translatability audit in the orca-translations skill
Add a reference describing how strings reach translators, what to look
for (untranslated text, spliced sentences, missing plurals, ambiguous
words), what not to translate, where a context cannot be carried, and
what to do after the edits, plus a scanner that lists untranslated
user-facing string literals.
* Document how to write translatable strings in AGENTS.md
Tell developers to keep each message complete in one msgid: use
placeholders instead of concatenating translated fragments, plural forms
for counts, and contexts for ambiguous words, and to list new source
files in localization/i18n/list.txt. Add a matching code review item.
* Translate the strings added since the rebase
Regenerate the template against the current main and translate the 26
new entries per language: the Fix Model commands and messages, and the
texture displacement image adjustment panel. Each new entry is marked
"# AI Translated"; existing entries are unchanged.
* tidy
This commit is contained in:
+133
-132
@@ -5,6 +5,8 @@
|
||||
#include "PrintConfig.hpp"
|
||||
#include "Point.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "I18N.hpp"
|
||||
#include "format.hpp"
|
||||
#include "libslic3r_version.h"
|
||||
#include <cassert>
|
||||
#include <boost/range/iterator_range_core.hpp>
|
||||
@@ -383,7 +385,7 @@ namespace client
|
||||
case TYPE_DOUBLE:
|
||||
return expr(- this->d(), start_pos, this->it_range.end());
|
||||
default:
|
||||
this->throw_exception("Cannot apply unary minus operator.");
|
||||
this->throw_exception(L("Cannot apply unary minus operator."));
|
||||
}
|
||||
assert(false);
|
||||
// Suppress compiler warnings.
|
||||
@@ -401,7 +403,7 @@ namespace client
|
||||
case TYPE_DOUBLE:
|
||||
return expr(static_cast<int>(this->d()), start_pos, this->it_range.end());
|
||||
default:
|
||||
this->throw_exception("Cannot convert to integer.");
|
||||
this->throw_exception(L("Cannot convert to integer."));
|
||||
}
|
||||
assert(false);
|
||||
// Suppress compiler warnings.
|
||||
@@ -419,7 +421,7 @@ namespace client
|
||||
case TYPE_DOUBLE:
|
||||
return expr(static_cast<int>(std::round(this->d())), start_pos, this->it_range.end());
|
||||
default:
|
||||
this->throw_exception("Cannot round a non-numeric value.");
|
||||
this->throw_exception(L("Cannot round a non-numeric value."));
|
||||
}
|
||||
assert(false);
|
||||
// Suppress compiler warnings.
|
||||
@@ -434,7 +436,7 @@ namespace client
|
||||
case TYPE_DOUBLE:
|
||||
return expr(static_cast<int>(std::floor(this->d())), start_pos, this->it_range.end());
|
||||
default:
|
||||
this->throw_exception("Cannot floor a non-numeric value.");
|
||||
this->throw_exception(L("Cannot floor a non-numeric value."));
|
||||
}
|
||||
assert(false);
|
||||
// Suppress compiler warnings.
|
||||
@@ -449,7 +451,7 @@ namespace client
|
||||
case TYPE_DOUBLE:
|
||||
return expr(static_cast<int>(std::ceil(this->d())), start_pos, this->it_range.end());
|
||||
default:
|
||||
this->throw_exception("Cannot ceil a non-numeric value.");
|
||||
this->throw_exception(L("Cannot ceil a non-numeric value."));
|
||||
}
|
||||
assert(false);
|
||||
// Suppress compiler warnings.
|
||||
@@ -465,7 +467,7 @@ namespace client
|
||||
case TYPE_BOOL:
|
||||
return expr(! this->b(), start_pos, this->it_range.end());
|
||||
default:
|
||||
this->throw_exception("Cannot apply a not operator.");
|
||||
this->throw_exception(L("Cannot apply a not operator."));
|
||||
}
|
||||
assert(false);
|
||||
// Suppress compiler warnings.
|
||||
@@ -483,7 +485,7 @@ namespace client
|
||||
// Conver the left hand side to string, append rhs.
|
||||
this->set_s(this->to_string() + rhs.s());
|
||||
} else {
|
||||
const char *err_msg = "Cannot add non-numeric types.";
|
||||
const char *err_msg = L("Cannot add non-numeric types.");
|
||||
this->throw_if_not_numeric(err_msg);
|
||||
rhs.throw_if_not_numeric(err_msg);
|
||||
if (this->type() == TYPE_DOUBLE || rhs.type() == TYPE_DOUBLE)
|
||||
@@ -501,7 +503,7 @@ namespace client
|
||||
// Inside an if / else block to be skipped.
|
||||
this->reset();
|
||||
} else {
|
||||
const char *err_msg = "Cannot subtract non-numeric types.";
|
||||
const char *err_msg = L("Cannot subtract non-numeric types.");
|
||||
this->throw_if_not_numeric(err_msg);
|
||||
rhs.throw_if_not_numeric(err_msg);
|
||||
if (this->type() == TYPE_DOUBLE || rhs.type() == TYPE_DOUBLE)
|
||||
@@ -519,7 +521,7 @@ namespace client
|
||||
// Inside an if / else block to be skipped.
|
||||
this->reset();
|
||||
} else {
|
||||
const char *err_msg = "Cannot multiply with non-numeric type.";
|
||||
const char *err_msg = L("Cannot multiply with non-numeric type.");
|
||||
this->throw_if_not_numeric(err_msg);
|
||||
rhs.throw_if_not_numeric(err_msg);
|
||||
if (this->type() == TYPE_DOUBLE || rhs.type() == TYPE_DOUBLE)
|
||||
@@ -537,10 +539,10 @@ namespace client
|
||||
// Inside an if / else block to be skipped.
|
||||
this->reset();
|
||||
} else {
|
||||
this->throw_if_not_numeric("Cannot divide a non-numeric type.");
|
||||
rhs.throw_if_not_numeric("Cannot divide with a non-numeric type.");
|
||||
this->throw_if_not_numeric(L("Cannot divide a non-numeric type."));
|
||||
rhs.throw_if_not_numeric(L("Cannot divide with a non-numeric type."));
|
||||
if (rhs.type() == TYPE_INT ? (rhs.i() == 0) : (rhs.d() == 0.))
|
||||
rhs.throw_exception("Division by zero");
|
||||
rhs.throw_exception(L("Division by zero"));
|
||||
if (this->type() == TYPE_DOUBLE || rhs.type() == TYPE_DOUBLE)
|
||||
this->set_d_lite(this->as_d() / rhs.as_d());
|
||||
else
|
||||
@@ -556,10 +558,10 @@ namespace client
|
||||
// Inside an if / else block to be skipped.
|
||||
this->reset();
|
||||
} else {
|
||||
this->throw_if_not_numeric("Cannot divide a non-numeric type.");
|
||||
rhs.throw_if_not_numeric("Cannot divide with a non-numeric type.");
|
||||
this->throw_if_not_numeric(L("Cannot divide a non-numeric type."));
|
||||
rhs.throw_if_not_numeric(L("Cannot divide with a non-numeric type."));
|
||||
if (rhs.type() == TYPE_INT ? (rhs.i() == 0) : (rhs.d() == 0.))
|
||||
rhs.throw_exception("Division by zero");
|
||||
rhs.throw_exception(L("Division by zero"));
|
||||
if (this->type() == TYPE_DOUBLE || rhs.type() == TYPE_DOUBLE)
|
||||
this->set_d_lite(std::fmod(this->as_d(), rhs.as_d()));
|
||||
else
|
||||
@@ -581,7 +583,7 @@ namespace client
|
||||
if (self.type() != TYPE_EMPTY) {
|
||||
// Not inside an if / else block to be skipped
|
||||
if (self.type() != TYPE_BOOL)
|
||||
self.throw_exception("Not a boolean expression");
|
||||
self.throw_exception(L("Not a boolean expression"));
|
||||
out = self.b();
|
||||
}
|
||||
}
|
||||
@@ -590,7 +592,7 @@ namespace client
|
||||
{
|
||||
assert(self.type() != TYPE_EMPTY);
|
||||
if (self.type() != TYPE_BOOL)
|
||||
self.throw_exception("Not a boolean expression");
|
||||
self.throw_exception(L("Not a boolean expression"));
|
||||
out = self.b() ? "true" : "false";
|
||||
}
|
||||
|
||||
@@ -622,7 +624,7 @@ namespace client
|
||||
// Both type are bool.
|
||||
if (op != '=')
|
||||
boost::throw_exception(qi::expectation_failure<Iterator>(
|
||||
lhs.it_range.begin(), rhs.it_range.end(), spirit::info("*Cannot compare the types.")));
|
||||
lhs.it_range.begin(), rhs.it_range.end(), spirit::info(std::string("*") + L("Cannot compare the types."))));
|
||||
value = lhs.b() == rhs.b();
|
||||
} else if (lhs.type() == TYPE_STRING || rhs.type() == TYPE_STRING) {
|
||||
// One type is string, the other could be converted to string.
|
||||
@@ -630,7 +632,7 @@ namespace client
|
||||
(op == '<') ? (lhs.to_string() < rhs.to_string()) : (lhs.to_string() > rhs.to_string());
|
||||
} else {
|
||||
boost::throw_exception(qi::expectation_failure<Iterator>(
|
||||
lhs.it_range.begin(), rhs.it_range.end(), spirit::info("*Cannot compare the types.")));
|
||||
lhs.it_range.begin(), rhs.it_range.end(), spirit::info(std::string("*") + L("Cannot compare the types."))));
|
||||
}
|
||||
lhs.reset();
|
||||
lhs.set_b_lite(invert ? ! value : value);
|
||||
@@ -645,7 +647,7 @@ namespace client
|
||||
|
||||
static void throw_if_not_numeric(const expr ¶m)
|
||||
{
|
||||
const char *err_msg = "Not a numeric type.";
|
||||
const char *err_msg = L("Not a numeric type.");
|
||||
param.throw_if_not_numeric(err_msg);
|
||||
}
|
||||
|
||||
@@ -707,10 +709,10 @@ namespace client
|
||||
return;
|
||||
throw_if_not_numeric(param1);
|
||||
if (param2.type() != TYPE_INT)
|
||||
param2.throw_exception("digits: second parameter must be integer");
|
||||
param2.throw_exception(L("digits: second parameter must be integer"));
|
||||
bool has_decimals = param3.type() != TYPE_EMPTY;
|
||||
if (has_decimals && param3.type() != TYPE_INT)
|
||||
param3.throw_exception("digits: third parameter must be integer");
|
||||
param3.throw_exception(L("digits: third parameter must be integer"));
|
||||
|
||||
char buf[256];
|
||||
int ndigits = std::clamp(param2.as_i(), 0, 64);
|
||||
@@ -734,7 +736,7 @@ namespace client
|
||||
// One type is string, the other could be converted to string.
|
||||
subject = &lhs.s();
|
||||
} else {
|
||||
lhs.throw_exception("Left hand side of a regex match must be a string.");
|
||||
lhs.throw_exception(L("Left hand side of a regex match must be a string."));
|
||||
}
|
||||
try {
|
||||
std::string pattern(++ rhs.begin(), -- rhs.end());
|
||||
@@ -745,7 +747,7 @@ namespace client
|
||||
} catch (SLIC3R_REGEX_NAMESPACE::regex_error &ex) {
|
||||
// Syntax error in the regular expression
|
||||
boost::throw_exception(qi::expectation_failure<Iterator>(
|
||||
rhs.begin(), rhs.end(), spirit::info(std::string("*Regular expression compilation failed: ") + ex.what())));
|
||||
rhs.begin(), rhs.end(), spirit::info("*" + Slic3r::format(_u8L("Regular expression compilation failed: %1%"), ex.what()))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -760,7 +762,7 @@ namespace client
|
||||
// Inside an if / else block to be skipped
|
||||
return;
|
||||
if (subject.type() != TYPE_STRING)
|
||||
subject.throw_exception("regex_replace() first parameter must be a string.");
|
||||
subject.throw_exception(L("regex_replace() first parameter must be a string."));
|
||||
try {
|
||||
std::string re(++ pattern.begin(), -- pattern.end());
|
||||
std::string result = SLIC3R_REGEX_NAMESPACE::regex_replace(subject.s(), SLIC3R_REGEX_NAMESPACE::regex(re), replacement.to_string());
|
||||
@@ -768,7 +770,7 @@ namespace client
|
||||
} catch (SLIC3R_REGEX_NAMESPACE::regex_error &ex) {
|
||||
// Syntax error in the regular expression
|
||||
boost::throw_exception(qi::expectation_failure<Iterator>(
|
||||
pattern.begin(), pattern.end(), spirit::info(std::string("*Regular expression compilation failed: ") + ex.what())));
|
||||
pattern.begin(), pattern.end(), spirit::info("*" + Slic3r::format(_u8L("Regular expression compilation failed: %1%"), ex.what()))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -784,15 +786,15 @@ namespace client
|
||||
}
|
||||
if (! out.b()) {
|
||||
if (match.type() != TYPE_STRING)
|
||||
match.throw_exception("one_of(): First parameter (the string to match against) has to be a string value");
|
||||
match.throw_exception(L("one_of(): First parameter (the string to match against) has to be a string value"));
|
||||
if (pattern.type() != TYPE_STRING)
|
||||
match.throw_exception("one_of(): Pattern has to be a string value");
|
||||
match.throw_exception(L("one_of(): Pattern has to be a string value"));
|
||||
if (RegEx) {
|
||||
try {
|
||||
out.set_b(SLIC3R_REGEX_NAMESPACE::regex_match(match.s(), SLIC3R_REGEX_NAMESPACE::regex(pattern.s())));
|
||||
} catch (SLIC3R_REGEX_NAMESPACE::regex_error &) {
|
||||
// Syntax error in the regular expression
|
||||
pattern.throw_exception("Regular expression compilation failed");
|
||||
pattern.throw_exception(L("Regular expression compilation failed"));
|
||||
}
|
||||
} else
|
||||
out.set_b(match.s() == pattern.s());
|
||||
@@ -806,7 +808,7 @@ namespace client
|
||||
}
|
||||
if (! out.b()) {
|
||||
if (match.type() != TYPE_STRING)
|
||||
match.throw_exception("one_of(): First parameter (the string to match against) has to be a string value");
|
||||
match.throw_exception(L("one_of(): First parameter (the string to match against) has to be a string value"));
|
||||
regex_op(match, pattern, '=', out);
|
||||
}
|
||||
}
|
||||
@@ -821,7 +823,7 @@ namespace client
|
||||
value = (op == '|') ? (lhs.b() || rhs.b()) : (lhs.b() && rhs.b());
|
||||
} else {
|
||||
boost::throw_exception(qi::expectation_failure<Iterator>(
|
||||
lhs.it_range.begin(), rhs.it_range.end(), spirit::info("*Cannot apply logical operation to non-boolean operators.")));
|
||||
lhs.it_range.begin(), rhs.it_range.end(), spirit::info(std::string("*") + L("Cannot apply logical operation to non-boolean operands."))));
|
||||
}
|
||||
lhs.set_b_lite(value);
|
||||
}
|
||||
@@ -984,30 +986,30 @@ namespace client
|
||||
opt = ctx->resolve_symbol(opt_key_str.substr(0, idx));
|
||||
if (opt != nullptr) {
|
||||
if (! opt->is_vector())
|
||||
ctx->throw_exception("Trying to index a scalar variable", opt_key);
|
||||
ctx->throw_exception(L("Trying to index a scalar variable"), opt_key);
|
||||
char *endptr = nullptr;
|
||||
idx = strtol(opt_key_str.c_str() + idx + 1, &endptr, 10);
|
||||
if (endptr == nullptr || *endptr != 0)
|
||||
ctx->throw_exception("Invalid vector index", IteratorRange(opt_key.begin() + idx + 1, opt_key.end()));
|
||||
ctx->throw_exception(L("Invalid vector index"), IteratorRange(opt_key.begin() + idx + 1, opt_key.end()));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (opt == nullptr)
|
||||
ctx->throw_exception(ctx->skipping() ? "Variable does not exist (in an inactive branch)" : "Variable does not exist", opt_key);
|
||||
ctx->throw_exception(ctx->skipping() ? L("Variable does not exist (in an inactive branch)") : L("Variable does not exist"), opt_key);
|
||||
if (ctx->skipping())
|
||||
return;
|
||||
if (opt->is_scalar()) {
|
||||
if (opt->is_nil())
|
||||
ctx->throw_exception("Trying to reference an undefined (nil) optional variable", opt_key);
|
||||
ctx->throw_exception(L("Trying to reference an undefined (nil) optional variable"), opt_key);
|
||||
output = opt->serialize();
|
||||
} else {
|
||||
const ConfigOptionVectorBase *vec = static_cast<const ConfigOptionVectorBase*>(opt);
|
||||
if (vec->empty())
|
||||
ctx->throw_exception("Indexing an empty vector variable", opt_key);
|
||||
ctx->throw_exception(L("Indexing an empty vector variable"), opt_key);
|
||||
if (idx >= vec->size())
|
||||
idx = 0;
|
||||
if (vec->is_nil(idx))
|
||||
ctx->throw_exception("Trying to reference an undefined (nil) element of vector of optional values", opt_key);
|
||||
ctx->throw_exception(L("Trying to reference an undefined (nil) element of vector of optional values"), opt_key);
|
||||
output = vec->vserialize()[idx];
|
||||
}
|
||||
}
|
||||
@@ -1021,7 +1023,7 @@ namespace client
|
||||
if (ctx->skipping() && ! ctx->check_inactive_names())
|
||||
return;
|
||||
|
||||
const char *not_found = ctx->skipping() ? "Variable does not exist (in an inactive branch)" : "Variable does not exist";
|
||||
const char *not_found = ctx->skipping() ? L("Variable does not exist (in an inactive branch)") : L("Variable does not exist");
|
||||
std::string opt_key_str(opt_key.begin(), opt_key.end());
|
||||
const ConfigOption *opt = ctx->resolve_symbol(opt_key_str);
|
||||
if (opt == nullptr) {
|
||||
@@ -1034,24 +1036,24 @@ namespace client
|
||||
ctx->throw_exception(not_found, opt_key);
|
||||
}
|
||||
if (! opt->is_vector())
|
||||
ctx->throw_exception("Trying to index a scalar variable", opt_key);
|
||||
ctx->throw_exception(L("Trying to index a scalar variable"), opt_key);
|
||||
const ConfigOption *opt_index = ctx->resolve_symbol(std::string(opt_vector_index.begin(), opt_vector_index.end()));
|
||||
if (opt_index == nullptr)
|
||||
ctx->throw_exception(not_found, opt_key);
|
||||
if (opt_index->type() != coInt)
|
||||
ctx->throw_exception("Indexing variable has to be integer", opt_key);
|
||||
ctx->throw_exception(L("Indexing variable has to be integer"), opt_key);
|
||||
if (ctx->skipping())
|
||||
return;
|
||||
const ConfigOptionVectorBase *vec = static_cast<const ConfigOptionVectorBase*>(opt);
|
||||
if (vec->empty())
|
||||
ctx->throw_exception("Indexing an empty vector variable", opt_key);
|
||||
ctx->throw_exception(L("Indexing an empty vector variable"), opt_key);
|
||||
int idx = opt_index->getInt();
|
||||
if (idx < 0)
|
||||
ctx->throw_exception("Negative vector index", opt_key);
|
||||
ctx->throw_exception(L("Negative vector index"), opt_key);
|
||||
if (idx >= (int)vec->size())
|
||||
idx = 0;
|
||||
if (vec->is_nil(idx))
|
||||
ctx->throw_exception("Trying to reference an undefined (nil) element of vector of optional values", opt_key);
|
||||
ctx->throw_exception(L("Trying to reference an undefined (nil) element of vector of optional values"), opt_key);
|
||||
output = vec->vserialize()[idx];
|
||||
}
|
||||
|
||||
@@ -1066,7 +1068,7 @@ namespace client
|
||||
if (opt == nullptr) {
|
||||
opt = ctx->resolve_output_symbol(key);
|
||||
if (opt == nullptr)
|
||||
ctx->throw_exception("Not a variable name", opt_key);
|
||||
ctx->throw_exception(L("Not a variable name"), opt_key);
|
||||
output.writable = true;
|
||||
}
|
||||
output.opt = opt;
|
||||
@@ -1076,7 +1078,7 @@ namespace client
|
||||
if (ctx->resolve_symbol(key) == nullptr && ctx->resolve_output_symbol(key) == nullptr &&
|
||||
ctx->inactive_local_variables.count(key) == 0 &&
|
||||
(ctx->context_data == nullptr || ctx->context_data->inactive_global_variables.count(key) == 0))
|
||||
ctx->throw_exception("Not a variable name (in an inactive branch)", opt_key);
|
||||
ctx->throw_exception(L("Not a variable name (in an inactive branch)"), opt_key);
|
||||
}
|
||||
output.it_range = opt_key;
|
||||
}
|
||||
@@ -1110,7 +1112,7 @@ namespace client
|
||||
assert(opt.opt->is_scalar());
|
||||
|
||||
if (opt.opt->is_nil())
|
||||
ctx->throw_exception("Trying to reference an undefined (nil) optional variable", opt.it_range);
|
||||
ctx->throw_exception(L("Trying to reference an undefined (nil) optional variable"), opt.it_range);
|
||||
|
||||
switch (opt.opt->type()) {
|
||||
case coFloat: output.set_d(opt.opt->getFloat()); break;
|
||||
@@ -1137,7 +1139,7 @@ namespace client
|
||||
for (;;) {
|
||||
const ConfigOption *opt_parent = opt_def->ratio_over.empty() ? nullptr : ctx->resolve_symbol(opt_def->ratio_over);
|
||||
if (opt_parent == nullptr)
|
||||
ctx->throw_exception("FloatOrPercent variable failed to resolve the \"ratio_over\" dependencies", opt.it_range);
|
||||
ctx->throw_exception(L("FloatOrPercent variable failed to resolve the \"ratio_over\" dependencies"), opt.it_range);
|
||||
if (boost::ends_with(opt_def->ratio_over, "line_width")) {
|
||||
// Line width supports defaults and a complex graph of dependencies.
|
||||
assert(opt_parent->type() == coFloatOrPercent);
|
||||
@@ -1159,7 +1161,7 @@ namespace client
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ctx->throw_exception("Unsupported scalar variable type", opt.it_range);
|
||||
ctx->throw_exception(L("Unsupported scalar variable type"), opt.it_range);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1173,7 +1175,7 @@ namespace client
|
||||
assert(opt.opt->is_vector());
|
||||
const ConfigOptionVectorBase* vec = static_cast<const ConfigOptionVectorBase*>(opt.opt);
|
||||
if (vec->empty())
|
||||
ctx->throw_exception("Indexing an empty vector variable", opt.it_range);
|
||||
ctx->throw_exception(L("Indexing an empty vector variable"), opt.it_range);
|
||||
|
||||
// Helper to resolve a FloatOrPercent value (handles ratio_over chain for percent values).
|
||||
// elem_index: the element index used to access this vector element, so that
|
||||
@@ -1194,7 +1196,7 @@ namespace client
|
||||
for (;;) {
|
||||
const ConfigOption *opt_parent = opt_def->ratio_over.empty() ? nullptr : ctx->resolve_symbol(opt_def->ratio_over);
|
||||
if (opt_parent == nullptr)
|
||||
ctx->throw_exception("FloatOrPercent variable failed to resolve the \"ratio_over\" dependencies", opt.it_range);
|
||||
ctx->throw_exception(L("FloatOrPercent variable failed to resolve the \"ratio_over\" dependencies"), opt.it_range);
|
||||
if (boost::ends_with(opt_def->ratio_over, "line_width")) {
|
||||
// Line width supports defaults and a complex graph of dependencies.
|
||||
assert(opt_parent->type() == coFloatOrPercent);
|
||||
@@ -1277,12 +1279,12 @@ namespace client
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: ctx->throw_exception("Referencing a vector variable when scalar is expected", opt.it_range);
|
||||
default: ctx->throw_exception(L("Referencing a vector variable when scalar is expected"), opt.it_range);
|
||||
}
|
||||
} else {
|
||||
size_t idx = (opt.index < 0) ? 0 : (opt.index >= int(vec->size())) ? 0 : size_t(opt.index);
|
||||
if (vec->is_nil(idx))
|
||||
ctx->throw_exception("Trying to reference an undefined (nil) element of vector of optional values", opt.it_range);
|
||||
ctx->throw_exception(L("Trying to reference an undefined (nil) element of vector of optional values"), opt.it_range);
|
||||
switch (opt.opt->type()) {
|
||||
case coFloats: output.set_d(static_cast<const ConfigOptionFloats*>(opt.opt)->values[idx]); break;
|
||||
case coInts: output.set_i(static_cast<const ConfigOptionInts*>(opt.opt)->values[idx]); break;
|
||||
@@ -1301,27 +1303,27 @@ namespace client
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ctx->throw_exception("Unsupported vector variable type", opt.it_range);
|
||||
ctx->throw_exception(L("Unsupported vector variable type"), opt.it_range);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void check_writable(const MyContext *ctx, OptWithPos &opt) {
|
||||
if (! opt.writable)
|
||||
ctx->throw_exception("Cannot modify a read-only variable", opt.it_range);
|
||||
ctx->throw_exception(L("Cannot modify a read-only variable"), opt.it_range);
|
||||
}
|
||||
|
||||
static void check_numeric(const expr ¶m) {
|
||||
if (! param.numeric_type())
|
||||
param.throw_exception("Right side is not a numeric expression");
|
||||
param.throw_exception(L("Right side is not a numeric expression"));
|
||||
};
|
||||
|
||||
static size_t evaluate_count(const expr &expr_count) {
|
||||
if (expr_count.type() != expr::TYPE_INT)
|
||||
expr_count.throw_exception("Expected number of elements to fill a vector with.");
|
||||
expr_count.throw_exception(L("Expected number of elements to fill a vector with."));
|
||||
int count = expr_count.i();
|
||||
if (count < 0)
|
||||
expr_count.throw_exception("Negative number of elements specified.");
|
||||
expr_count.throw_exception(L("Negative number of elements specified."));
|
||||
return size_t(count);
|
||||
};
|
||||
|
||||
@@ -1349,11 +1351,11 @@ namespace client
|
||||
break;
|
||||
case coBool:
|
||||
if (rhs.type() != expr::TYPE_BOOL)
|
||||
ctx->throw_exception("Right side is not a boolean expression", rhs.it_range);
|
||||
ctx->throw_exception(L("Right side is not a boolean expression"), rhs.it_range);
|
||||
static_cast<ConfigOptionBool*>(wropt)->value = rhs.b();
|
||||
break;
|
||||
default:
|
||||
ctx->throw_exception("Unsupported output scalar variable type", lhs.it_range);
|
||||
ctx->throw_exception(L("Unsupported output scalar variable type"), lhs.it_range);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1363,12 +1365,12 @@ namespace client
|
||||
assert(lhs.opt->is_vector());
|
||||
check_writable(ctx, lhs);
|
||||
if (! lhs.has_index())
|
||||
ctx->throw_exception("Referencing an output vector variable when scalar is expected", lhs.it_range);
|
||||
ctx->throw_exception(L("Referencing an output vector variable when scalar is expected"), lhs.it_range);
|
||||
ConfigOptionVectorBase *vec = const_cast<ConfigOptionVectorBase*>(static_cast<const ConfigOptionVectorBase*>(lhs.opt));
|
||||
if (vec->empty())
|
||||
ctx->throw_exception("Indexing an empty vector variable", lhs.it_range);
|
||||
ctx->throw_exception(L("Indexing an empty vector variable"), lhs.it_range);
|
||||
if (lhs.index >= int(vec->size()))
|
||||
ctx->throw_exception("Index out of range", lhs.it_range);
|
||||
ctx->throw_exception(L("Index out of range"), lhs.it_range);
|
||||
switch (lhs.opt->type()) {
|
||||
case coFloats:
|
||||
check_numeric(rhs);
|
||||
@@ -1387,11 +1389,11 @@ namespace client
|
||||
break;
|
||||
case coBools:
|
||||
if (rhs.type() != expr::TYPE_BOOL)
|
||||
ctx->throw_exception("Right side is not a boolean expression", rhs.it_range);
|
||||
ctx->throw_exception(L("Right side is not a boolean expression"), rhs.it_range);
|
||||
static_cast<ConfigOptionBools*>(vec)->values[lhs.index] = rhs.b();
|
||||
break;
|
||||
default:
|
||||
ctx->throw_exception("Unsupported output vector variable type", lhs.it_range);
|
||||
ctx->throw_exception(L("Unsupported output vector variable type"), lhs.it_range);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1414,7 +1416,7 @@ namespace client
|
||||
break;
|
||||
case coBools:
|
||||
if (rhs_value.type() != expr::TYPE_BOOL)
|
||||
rhs_value.throw_exception("Right side is not a boolean expression");
|
||||
rhs_value.throw_exception(L("Right side is not a boolean expression"));
|
||||
static_cast<ConfigOptionBools*>(opt)->values.assign(count, rhs_value.b());
|
||||
break;
|
||||
default: assert(false);
|
||||
@@ -1439,10 +1441,10 @@ namespace client
|
||||
if (ctx->skipping()) {
|
||||
} else if (opt.opt->is_vector()) {
|
||||
if (! opt.has_index())
|
||||
ctx->throw_exception("Referencing a vector variable when scalar is expected", opt.it_range);
|
||||
ctx->throw_exception(L("Referencing a vector variable when scalar is expected"), opt.it_range);
|
||||
const ConfigOptionVectorBase *vec = static_cast<const ConfigOptionVectorBase*>(opt.opt);
|
||||
if (vec->empty())
|
||||
ctx->throw_exception("Indexing an empty vector variable", opt.it_range);
|
||||
ctx->throw_exception(L("Indexing an empty vector variable"), opt.it_range);
|
||||
output.set_b(static_cast<const ConfigOptionVectorBase*>(opt.opt)->is_nil(opt.index >= int(vec->size()) ? 0 : size_t(opt.index)));
|
||||
} else {
|
||||
assert(opt.opt->is_scalar());
|
||||
@@ -1466,19 +1468,19 @@ namespace client
|
||||
if (! ctx->skipping()) {
|
||||
t_config_option_key key(std::string(it_range.begin(), it_range.end()));
|
||||
if (const ConfigOption* opt = ctx->resolve_symbol(key); opt)
|
||||
ctx->throw_exception("Symbol is already defined in read-only system dictionary", it_range);
|
||||
ctx->throw_exception(L("Symbol is already defined in read-only system dictionary"), it_range);
|
||||
if (ctx->config_outputs && ctx->config_outputs->optptr(key))
|
||||
ctx->throw_exception("Symbol is already defined as system output variable", it_range);
|
||||
ctx->throw_exception(L("Symbol is already defined as system output variable"), it_range);
|
||||
bool has_global_dictionary = ctx->context_data != nullptr && ctx->context_data->global_config;
|
||||
if (global_variable) {
|
||||
if (! has_global_dictionary)
|
||||
ctx->throw_exception("Global variables are not available in this context", it_range);
|
||||
ctx->throw_exception(L("Global variables are not available in this context"), it_range);
|
||||
if (ctx->config_local.optptr(key))
|
||||
ctx->throw_exception("Variable name already defined in local scope", it_range);
|
||||
ctx->throw_exception(L("Variable name already defined in local scope"), it_range);
|
||||
out.opt = ctx->context_data->global_config->optptr(key);
|
||||
} else {
|
||||
if (has_global_dictionary && ctx->context_data->global_config->optptr(key))
|
||||
ctx->throw_exception("Variable name already defined in global scope", it_range);
|
||||
ctx->throw_exception(L("Variable name already defined in global scope"), it_range);
|
||||
out.opt = ctx->config_local.optptr(key);
|
||||
}
|
||||
out.name = std::move(key);
|
||||
@@ -1514,7 +1516,7 @@ namespace client
|
||||
if (ctx->skipping()) {
|
||||
} else if (lhs.opt) {
|
||||
if (lhs.opt->is_vector())
|
||||
rhs.throw_exception("Cannot assign a scalar value to a vector variable.");
|
||||
rhs.throw_exception(L("Cannot assign a scalar value to a vector variable."));
|
||||
OptWithPos lhs_opt{ lhs.opt, lhs.it_range, true };
|
||||
scalar_variable_assign_scalar(ctx, lhs_opt, rhs);
|
||||
} else {
|
||||
@@ -1540,7 +1542,7 @@ namespace client
|
||||
if (ctx->skipping()) {
|
||||
} else if (lhs.opt) {
|
||||
if (lhs.opt->is_scalar())
|
||||
rhs_value.throw_exception("Cannot assign a vector value to a scalar variable.");
|
||||
rhs_value.throw_exception(L("Cannot assign a vector value to a scalar variable."));
|
||||
OptWithPos lhs_opt{ lhs.opt, lhs.it_range, true };
|
||||
vector_variable_assign_expr_with_count(ctx, lhs_opt, rhs_count, rhs_value);
|
||||
} else {
|
||||
@@ -1566,7 +1568,7 @@ namespace client
|
||||
if (! ctx->skipping()) {
|
||||
check_writable(ctx, lhs);
|
||||
if (lhs.opt->is_scalar())
|
||||
rhs_value.throw_exception("Cannot assign a vector value to a scalar variable.");
|
||||
rhs_value.throw_exception(L("Cannot assign a vector value to a scalar variable."));
|
||||
vector_variable_assign_expr_with_count(ctx, lhs, rhs_count, rhs_value);
|
||||
}
|
||||
}
|
||||
@@ -1595,13 +1597,13 @@ namespace client
|
||||
// scalar_var = ()
|
||||
// or
|
||||
// scalar_var = ( scalar, scalar, ... )
|
||||
ctx->throw_exception("Cannot assign a vector value to a scalar variable.", lhs.it_range);
|
||||
ctx->throw_exception(L("Cannot assign a vector value to a scalar variable."), lhs.it_range);
|
||||
}
|
||||
|
||||
auto check_numeric_vector = [](const std::vector<expr> &il) {
|
||||
for (auto &i : il)
|
||||
if (! i.numeric_type())
|
||||
i.throw_exception("Right side is not a numeric expression");
|
||||
i.throw_exception(L("Right side is not a numeric expression"));
|
||||
};
|
||||
|
||||
ConfigOption *opt = const_cast<ConfigOption*>(lhs.opt);
|
||||
@@ -1620,7 +1622,7 @@ namespace client
|
||||
case coBools:
|
||||
for (auto &i : il)
|
||||
if (i.type() != expr::TYPE_BOOL)
|
||||
i.throw_exception("Right side is not a boolean expression");
|
||||
i.throw_exception(L("Right side is not a boolean expression"));
|
||||
fill_vector_from_initializer_list<ConfigOptionBools>(opt, il, [](auto &v){ return v.b(); });
|
||||
break;
|
||||
default: assert(false);
|
||||
@@ -1642,7 +1644,7 @@ namespace client
|
||||
vector_variable_assign_initializer_list(ctx, lhs_opt, il);
|
||||
} else {
|
||||
if (il.empty())
|
||||
ctx->throw_exception("Cannot create vector variable from an empty initializer list, because its type cannot be deduced.", lhs.it_range);
|
||||
ctx->throw_exception(L("Cannot create vector variable from an empty initializer list, because its type cannot be deduced."), lhs.it_range);
|
||||
// Allocate a new vector variable.
|
||||
// First guesstimate type of the output vector.
|
||||
size_t num_bool = 0;
|
||||
@@ -1663,7 +1665,7 @@ namespace client
|
||||
opt_new = std::make_unique<ConfigOptionStrings>();
|
||||
else if (num_bool > 0) {
|
||||
if (num_double + num_int > 0)
|
||||
ctx->throw_exception("Right side is not valid: Mixing numeric and boolean types.", IteratorRange{ il.front().it_range.begin(), il.back().it_range.end() });
|
||||
ctx->throw_exception(L("Right side is not valid: Mixing numeric and boolean types."), IteratorRange{ il.front().it_range.begin(), il.back().it_range.end() });
|
||||
opt_new = std::make_unique<ConfigOptionBools>();
|
||||
} else {
|
||||
// Output is numeric.
|
||||
@@ -1695,22 +1697,22 @@ namespace client
|
||||
check_writable(ctx, lhs);
|
||||
assert(lhs.opt->is_vector());
|
||||
if (rhs.has_index() || ! rhs.opt->is_vector())
|
||||
ctx->throw_exception("Cannot assign scalar to a vector", lhs.it_range);
|
||||
ctx->throw_exception(L("Cannot assign scalar to a vector"), lhs.it_range);
|
||||
if (rhs.opt->is_nil())
|
||||
ctx->throw_exception("Some elements of the right hand side vector variable of optional values are undefined (nil)", rhs.it_range);
|
||||
ctx->throw_exception(L("Some elements of the right hand side vector variable of optional values are undefined (nil)"), rhs.it_range);
|
||||
if (lhs.opt->type() != rhs.opt->type()) {
|
||||
// Vector types are not compatible.
|
||||
switch (lhs.opt->type()) {
|
||||
case coFloats:
|
||||
ctx->throw_exception("Left hand side is a float vector, while the right hand side is not.", lhs.it_range);
|
||||
ctx->throw_exception(L("Left hand side is a float vector, while the right hand side is not."), lhs.it_range);
|
||||
case coInts:
|
||||
ctx->throw_exception("Left hand side is an int vector, while the right hand side is not.", lhs.it_range);
|
||||
ctx->throw_exception(L("Left hand side is an int vector, while the right hand side is not."), lhs.it_range);
|
||||
case coStrings:
|
||||
ctx->throw_exception("Left hand side is a string vector, while the right hand side is not.", lhs.it_range);
|
||||
ctx->throw_exception(L("Left hand side is a string vector, while the right hand side is not."), lhs.it_range);
|
||||
case coBools:
|
||||
ctx->throw_exception("Left hand side is a bool vector, while the right hand side is not.", lhs.it_range);
|
||||
ctx->throw_exception(L("Left hand side is a bool vector, while the right hand side is not."), lhs.it_range);
|
||||
default:
|
||||
ctx->throw_exception("Left hand side / right hand side vectors are not compatible.", lhs.it_range);
|
||||
ctx->throw_exception(L("Left hand side / right hand side vectors are not compatible."), lhs.it_range);
|
||||
}
|
||||
}
|
||||
const_cast<ConfigOption*>(lhs.opt)->set(rhs.opt);
|
||||
@@ -1735,7 +1737,7 @@ namespace client
|
||||
// Stop parsing, let the other rules resolve this case.
|
||||
return false;
|
||||
if (rhs.opt->is_nil())
|
||||
ctx->throw_exception("Some elements of the right hand side vector variable of optional values are undefined (nil)", rhs.it_range);
|
||||
ctx->throw_exception(L("Some elements of the right hand side vector variable of optional values are undefined (nil)"), rhs.it_range);
|
||||
// Clone the vector variable.
|
||||
std::unique_ptr<ConfigOption> opt_new;
|
||||
if (one_of(rhs.opt->type(), { coFloats, coInts, coStrings, coBools }))
|
||||
@@ -1743,7 +1745,7 @@ namespace client
|
||||
else if (rhs.opt->type() == coPercents)
|
||||
opt_new = std::make_unique<ConfigOptionFloats>(static_cast<const ConfigOptionPercents*>(rhs.opt)->values);
|
||||
else
|
||||
ctx->throw_exception("Duplicating this type of vector variable is not supported", rhs.it_range);
|
||||
ctx->throw_exception(L("Duplicating this type of vector variable is not supported"), rhs.it_range);
|
||||
const_cast<MyContext*>(ctx)->store_new_variable(lhs.name, std::move(opt_new), global_variable);
|
||||
}
|
||||
// Continue parsing.
|
||||
@@ -1761,7 +1763,7 @@ namespace client
|
||||
{
|
||||
if (! ctx->skipping()) {
|
||||
if (opt.has_index() || ! opt.opt->is_vector())
|
||||
ctx->throw_exception("parameter of empty() is not a vector variable", opt.it_range);
|
||||
ctx->throw_exception(L("parameter of empty() is not a vector variable"), opt.it_range);
|
||||
out.set_b(static_cast<const ConfigOptionVectorBase*>(opt.opt)->size() == 0);
|
||||
}
|
||||
out.it_range = opt.it_range;
|
||||
@@ -1771,7 +1773,7 @@ namespace client
|
||||
{
|
||||
if (! ctx->skipping()) {
|
||||
if (opt.has_index() || ! opt.opt->is_vector())
|
||||
ctx->throw_exception("parameter of size() is not a vector variable", opt.it_range);
|
||||
ctx->throw_exception(L("parameter of size() is not a vector variable"), opt.it_range);
|
||||
out.set_i(int(static_cast<const ConfigOptionVectorBase*>(opt.opt)->size()));
|
||||
}
|
||||
out.it_range = opt.it_range;
|
||||
@@ -1783,7 +1785,7 @@ namespace client
|
||||
{
|
||||
if (expr_index.type() != expr::TYPE_EMPTY) {
|
||||
if (expr_index.type() != expr::TYPE_INT)
|
||||
expr_index.throw_exception("Non-integer index is not allowed to address a vector variable.");
|
||||
expr_index.throw_exception(L("Non-integer index is not allowed to address a vector variable."));
|
||||
output = expr_index.i();
|
||||
}
|
||||
}
|
||||
@@ -1794,7 +1796,7 @@ namespace client
|
||||
return;
|
||||
|
||||
if (ctx->context_data == nullptr)
|
||||
ctx->throw_exception("Random number generator not available in this context.",
|
||||
ctx->throw_exception(L("Random number generator not available in this context."),
|
||||
IteratorRange(param1.it_range.begin(), param2.it_range.end()));
|
||||
expr::random(param1, param2, ctx->context_data->rng);
|
||||
}
|
||||
@@ -1832,21 +1834,20 @@ namespace client
|
||||
auto error_line = std::string(first, first_pos) + std::string(last, 0, last_pos);
|
||||
// Position of the it_error from the start of its line.
|
||||
auto error_pos = (it_error - it_begin) - first_pos;
|
||||
msg += "Parsing error at line " + std::to_string(line_nr);
|
||||
if (! info.tag.empty() && info.tag.front() == '*') {
|
||||
// The gat contains an explanatory string.
|
||||
msg += ": ";
|
||||
msg += info.tag.substr(1);
|
||||
// TRN Custom G-code error. %1% is the line number, %2% the reason.
|
||||
msg += Slic3r::format(_u8L("Parsing error at line %1%: %2%"), line_nr, Slic3r::I18N::translate(info.tag.substr(1)));
|
||||
} else {
|
||||
auto it = tag_to_error_message.find(info.tag);
|
||||
if (it == tag_to_error_message.end()) {
|
||||
// A generic error report based on the nonterminal or terminal symbol name.
|
||||
msg += ". Expecting tag ";
|
||||
msg += info.tag;
|
||||
// TRN Custom G-code error. %1% is the line number, %2% the name of a grammar rule.
|
||||
msg += Slic3r::format(_u8L("Parsing error at line %1%. Expecting tag %2%"), line_nr, info.tag);
|
||||
} else {
|
||||
// Use the human readable error message.
|
||||
msg += ". ";
|
||||
msg += it->second;
|
||||
// TRN Custom G-code error. %1% is the line number, %2% the reason.
|
||||
msg += Slic3r::format(_u8L("Parsing error at line %1%. %2%"), line_nr, Slic3r::I18N::translate(it->second));
|
||||
}
|
||||
}
|
||||
msg += '\n';
|
||||
@@ -1877,15 +1878,15 @@ namespace client
|
||||
static void init(const expr &x) {
|
||||
if (x.type() != expr::TYPE_EMPTY) {
|
||||
if (!x.numeric_type())
|
||||
x.throw_exception("Interpolation value must be a number.");
|
||||
x.throw_exception(L("Interpolation value must be a number."));
|
||||
}
|
||||
}
|
||||
static void add_pair(const expr &x, const expr &y, InterpolateTableContext &table) {
|
||||
if (x.type() != expr::TYPE_EMPTY) {
|
||||
if (! x.numeric_type())
|
||||
x.throw_exception("X value of a table point must be a number.");
|
||||
x.throw_exception(L("X value of a table point must be a number."));
|
||||
if (! y.numeric_type())
|
||||
y.throw_exception("Y value of a table point must be a number.");
|
||||
y.throw_exception(L("Y value of a table point must be a number."));
|
||||
table.table.push_back({ x.as_d(), x.it_range, y.as_d() });
|
||||
}
|
||||
}
|
||||
@@ -1902,7 +1903,7 @@ namespace client
|
||||
double x1 = table.table[i].x;
|
||||
if (x0 > x1)
|
||||
boost::throw_exception(qi::expectation_failure(
|
||||
table.table[i - 1].it_range_x.begin(), table.table[i].it_range_x.end(), spirit::info("X coordinates of the table must be increasing")));
|
||||
table.table[i - 1].it_range_x.begin(), table.table[i].it_range_x.end(), spirit::info(std::string("*") + L("X coordinates of the table must be increasing"))));
|
||||
if (! evaluated && x >= x0 && x <= x1) {
|
||||
double y0 = table.table[i - 1].y;
|
||||
double y1 = table.table[i].y;
|
||||
@@ -1925,7 +1926,7 @@ namespace client
|
||||
out.set_d(table.table.back().y);
|
||||
else
|
||||
// The value is really outside the table range.
|
||||
expr_x.throw_exception("Interpolation value is outside the table range");
|
||||
expr_x.throw_exception(L("Interpolation value is outside the table range"));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1939,30 +1940,30 @@ namespace client
|
||||
|
||||
// Table to translate symbol tag to a human readable error message.
|
||||
std::map<std::string, std::string> MyContext::tag_to_error_message = {
|
||||
{ "eoi", "Unknown syntax error" },
|
||||
{ "start", "Unknown syntax error" },
|
||||
{ "text", "Invalid text." },
|
||||
{ "text_block", "Invalid text block." },
|
||||
{ "macro", "Invalid macro." },
|
||||
{ "repeat", "Unknown syntax error" },
|
||||
{ "if_else_output", "Not an {if}{else}{endif} macro." },
|
||||
{ "switch_output", "Not a {switch} macro." },
|
||||
{ "legacy_variable_expansion", "Expecting a legacy variable expansion format" },
|
||||
{ "identifier", "Expecting an identifier." },
|
||||
{ "conditional_expression", "Expecting a conditional expression." },
|
||||
{ "logical_or_expression", "Expecting a boolean expression." },
|
||||
{ "logical_and_expression", "Expecting a boolean expression." },
|
||||
{ "equality_expression", "Expecting an expression." },
|
||||
{ "bool_expr_eval", "Expecting a boolean expression."},
|
||||
{ "relational_expression", "Expecting an expression." },
|
||||
{ "additive_expression", "Expecting an expression." },
|
||||
{ "multiplicative_expression", "Expecting an expression." },
|
||||
{ "unary_expression", "Expecting an expression." },
|
||||
{ "optional_parameter", "Expecting a closing brace or an optional parameter." },
|
||||
{ "one_of_list", "Expecting a list of string patterns (simple text or rexep)" },
|
||||
{ "variable_reference", "Expecting a variable reference."},
|
||||
{ "variable", "Expecting a variable name."},
|
||||
{ "regular_expression", "Expecting a regular expression."}
|
||||
{ "eoi", L("Unknown syntax error") },
|
||||
{ "start", L("Unknown syntax error") },
|
||||
{ "text", L("Invalid text.") },
|
||||
{ "text_block", L("Invalid text block.") },
|
||||
{ "macro", L("Invalid macro.") },
|
||||
{ "repeat", L("Unknown syntax error") },
|
||||
{ "if_else_output", L("Not an {if}{else}{endif} macro.") },
|
||||
{ "switch_output", L("Not a {switch} macro.") },
|
||||
{ "legacy_variable_expansion", L("Expecting a legacy variable expansion format") },
|
||||
{ "identifier", L("Expecting an identifier.") },
|
||||
{ "conditional_expression", L("Expecting a conditional expression.") },
|
||||
{ "logical_or_expression", L("Expecting a boolean expression.") },
|
||||
{ "logical_and_expression", L("Expecting a boolean expression.") },
|
||||
{ "equality_expression", L("Expecting an expression.") },
|
||||
{ "bool_expr_eval", L("Expecting a boolean expression.")},
|
||||
{ "relational_expression", L("Expecting an expression.") },
|
||||
{ "additive_expression", L("Expecting an expression.") },
|
||||
{ "multiplicative_expression", L("Expecting an expression.") },
|
||||
{ "unary_expression", L("Expecting an expression.") },
|
||||
{ "optional_parameter", L("Expecting a closing brace or an optional parameter.") },
|
||||
{ "one_of_list", L("Expecting a list of string patterns (simple text or regexp)") },
|
||||
{ "variable_reference", L("Expecting a variable reference.")},
|
||||
{ "variable", L("Expecting a variable name.")},
|
||||
{ "regular_expression", L("Expecting a regular expression.")}
|
||||
};
|
||||
|
||||
// For debugging the boost::spirit parsers. Print out the string enclosed in it_range.
|
||||
@@ -2031,7 +2032,7 @@ namespace client
|
||||
first = it;
|
||||
return true;
|
||||
err:
|
||||
MyContext::throw_exception("Invalid utf8 sequence", IteratorRange(first, last));
|
||||
MyContext::throw_exception(L("Invalid utf8 sequence"), IteratorRange(first, last));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2057,7 +2058,7 @@ namespace client
|
||||
return false;
|
||||
char c = *first;
|
||||
if (it - first > 1 || c < 0)
|
||||
MyContext::throw_exception("Non-ASCII7 characters are only allowed inside text blocks and string literals, not inside code blocks.", IteratorRange(first, it));
|
||||
MyContext::throw_exception(L("Non-ASCII7 characters are only allowed inside text blocks and string literals, not inside code blocks."), IteratorRange(first, it));
|
||||
if (c == '\r' || c == '\n' || c == '\t' || c == ' ') {
|
||||
// Skip the whitespaces
|
||||
++ first;
|
||||
@@ -2116,7 +2117,7 @@ namespace client
|
||||
if (*it == '\\') {
|
||||
if (++ it == end ||
|
||||
(*it != 'r' && *it != 'n' && *it != '"' && *it != '\\'))
|
||||
ctx->throw_exception("Invalid escape sequence", {std::prev(it), std::next(it) });
|
||||
ctx->throw_exception(L("Invalid escape sequence"), {std::prev(it), std::next(it) });
|
||||
++ len;
|
||||
++ it;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user