- dimensions_of should now work in all contexts
- import_image now works in style files, although should be avoided, since it reloads the file every time the code in run, it should be used in one shot scripts, like import scripts and bulk modification scripts
- process_english_hints now correctly processes <singular> and <plural> tags
This commit is contained in:
GenevensiS
2026-04-24 13:18:40 +02:00
parent d782e4851c
commit 0baa73ae7d
4 changed files with 59 additions and 41 deletions
+28 -12
View File
@@ -269,7 +269,9 @@ String process_english_hints(const String& str) {
String ret; ret.reserve(str.size());
// have we seen a <hint-1/2>?
// 1 for singular, 2 for plural
int singplur = 0;
int singplur = 0;
int sing_found = 0;
int plur_found = 0;
for (size_t i = 0 ; i < str.size() ; ) {
Char c = str.GetChar(i);
if (is_substr(str, i, _("<hint-"))) {
@@ -288,7 +290,7 @@ String process_english_hints(const String& str) {
// a -> an, where the a originates from english_number_a(1)
size_t after_end = skip_tag(str,after+1);
if (after_end == String::npos) {
throw Error(_("Incomplete </param> tag"));
throw ScriptError(_("Incomplete </param> tag"));
}
if (after_end != String::npos && after_end + 1 < str.size()
&& isSpace(str.GetChar(after_end)) && is_vowel(str.GetChar(after_end+1))) {
@@ -313,23 +315,31 @@ String process_english_hints(const String& str) {
}
ret.append(str,i,min(after,str.size())-i);
i = after;
} else if (is_substr(str, i, _("<singular>"))) {
} else if (is_substr(str, i, _("<singular>"))) {
sing_found++;
// singular -> keep, plural -> drop
size_t start = skip_tag(str, i);
size_t end = match_close_tag(str, start);
if (singplur == 1 && end != String::npos) {
ret += str.substr(start, end - start);
size_t end = match_close_tag(str, i);
if (end == String::npos) {
throw ScriptError(_("<singular> tag found without matching closing tag."));
}
else if (singplur == 1) {
ret += str.substr(start, end - start);
singplur = 0;
}
singplur = 0;
i = skip_tag(str, end);
} else if (is_substr(str, i, _("<plural>"))) {
} else if (is_substr(str, i, _("<plural>"))) {
plur_found++;
// singular -> drop, plural -> keep
size_t start = skip_tag(str, i);
size_t end = match_close_tag(str, start);
if (singplur == 2 && end != String::npos) {
ret += str.substr(start, end - start);
size_t end = match_close_tag(str, i);
if (end == String::npos) {
throw ScriptError(_("<plural> tag found without matching closing tag."));
}
else if (singplur == 2) {
ret += str.substr(start, end - start);
singplur = 0;
}
singplur = 0;
i = skip_tag(str, end);
} else if (c == _('(') && singplur) {
// singular -> drop (...), plural -> keep it
@@ -352,6 +362,12 @@ String process_english_hints(const String& str) {
ret += c;
++i;
}
}
if (sing_found > plur_found) {
throw ScriptError(_("<singular> tag found without matching <plural> tag."));
}
else if (sing_found < plur_found) {
throw ScriptError(_("<plural> tag found without matching <singular> tag."));
}
return ret;
}