Page 1 of 1
Translating Regular Expression Errors
Posted: Sun Feb 11, 2024 8:05 am
by AZJIO
Is it possible to make an external file for a list of regular expression errors to be able to translate into languages other than English? There are specific programs that will only be used in their own country.
Re: Translating Regular Expression Errors
Posted: Mon Feb 19, 2024 2:22 am
by tj1010
I *assume* it's based on PCRE like PB.
http://www.pcre.org/pcre.txt
Regular Expression you won't master in a single sitting; too much variation and syntax. They just allow you to one-line pattern matching instead of scanning for matching in a simple binary or unicode character loop...
Only solution I see for your problem is using a translation service, likely over HTTP, in your code... I don't see any language mappings for it in the files...
Re: Translating Regular Expression Errors
Posted: Mon Feb 19, 2024 7:11 am
by AZJIO
PCRE uses an error code
Error return values from pcre_exec()
If pcre_exec() fails, it returns a negative number. The following are
defined in the header file:
PCRE_ERROR_NOMATCH (-1)
The subject string did not match the pattern.
PCRE_ERROR_NULL (-2)
Either code or subject was passed as NULL, or ovector was NULL and
ovecsize was not zero.
PCRE_ERROR_BADOPTION (-3)
An unrecognized bit was set in the options argument.
PCRE_ERROR_BADMAGIC (-4)
It can be assumed that the error text can be assigned
Code: Select all
var e = new Error("Malformed input") // e.name = "Error"
e.name = "ParseError" // e.toString() will return "ParseError: Malformed input"
throw e;
Code: Select all
var e = new Error("A problem has occurred");
// e.message = A problem has occurred
throw e;
I don't see any language mappings for it in the files...
So the internal javascript text is used.
I wonder how many phrases there are. I can simulate standard errors (no opening or closing brackets, etc.) and make an array to replace strings.
I spied a function in one of the scripts
Code: Select all
WScript.Echo(_localize("Save file first!"));
function _localize(s) {
var strings = {
"Save file first!": {
ru: "Сначала сохраните файл!"
},
"Name of backup file:": {
ru: "Имя файла резервной копии:"
}
};
var lng = "en";
// switch(AkelPad.GetLangId(1 /*LANGID_PRIMARY*/)) {
// case 0x19: lng = "ru";
// }
lng = "ru";
_localize = function(s) {
return strings[s] && strings[s][lng] || s;
};
return _localize(s);
}
Considering that it is possible to
get the browser language
Code: Select all
!var v_lang0$ = navigator.language;
On Windows I get the error text in Russian.