I18n: clear out translatable Lua error messsages#941
I18n: clear out translatable Lua error messsages#941SlySven merged 3 commits intoMudlet:developmentfrom
Conversation
Since it has been decided that the Mudlet Lua API should not have the
capability to report errors in using the API in a translated form the use
of the Qt tr(...) function to mark such QStrings is not wanted. This
commit switches those usages to use the QStringLiteral(...) wrapper
instead. As the strings concerned are each unique the known downsides of
using this "non"-translatable QString wrapper should not be significant and
the code "template" for the two things are very similar {if there are no
second or second & third arguments in the tr(...) case} - the editing to
switch to QLatin1Strings in the same location would be much more intensive.
Where the (formerly) translated QString is then passed to the Lua system
there are some instances where QString::toUtf8() must be used instead of
QString::toLatin1() - these are generally the cases where a variable
included in the resulting QString can contain non-ASCII characters which
is any user defined/named item or {mainly on Windows platform} involving
file-system objects as that can also have non-ASCII characters.
There may be a few long text lines that I have manually inserted new-lines
into to try and prevent the resulting text from exceeding around 80
characters when shown on the main profile console.
There was a typo in one error message for TLuaInterpreter::downloadFile
as it described an issue for argument 1 when it should have said 2. Also
in three functions a QString "windowName" is set to the null `QString` when
the `QString::clear()`is a little more descriptive of what is happening.
Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
vadi2
left a comment
There was a problem hiding this comment.
👌 awesome. Trying your hand at the source code smashing too, hey?
|
It's a mixed feeling I have for this 😐 - I still think there is a middle way where a user having a problem with a Mudlet API feature could get help in their native language whilst using current English API functions/constants/variables even though the Lua core + libraries which are used by (some large multiplier) more people will also be producing English error messages but which will also have a wider support base amongst non-English users. Maybe it will get revisited for 5.0 when we get many more non-English users from Mudlet 4.0? 😉 Anyhow this is a big, repetitive PR and I'll see if @ahmedcharles has any input (spotted any clangers?) before hitting the green button. |
|
Happy to revisit it if circumstances change for sure. |
src/TLuaInterpreter.cpp
Outdated
| lua_pushstring( L, tr( "raiseEvent: NULL Host pointer - something is wrong!" ) | ||
| .toUtf8().constData() ); | ||
| lua_pushstring(L, QStringLiteral("raiseEvent: NULL Host pointer - something is wrong!") | ||
| .toLatin1().constData()); |
There was a problem hiding this comment.
Why are we using Qt types here at all? lua_pushstring(L, "raiseEvent: NULL Host pointer - something is wrong!"); will work exactly the same way in this case, so using Qt types just makes things more complex for no benefit.
There was a problem hiding this comment.
I think that makes sense, because we don't want a QString for Lua, and we're not dealing with UTF-8 here.
There was a problem hiding this comment.
😊 Humm, yes, that does seem to be the case for a fair proportion of the strings, gonna have to review what I dun!
src/TLuaInterpreter.cpp
Outdated
| .arg( luaL_typename( L, i ) ) | ||
| .toUtf8().constData() ); | ||
| lua_pushstring(L, QStringLiteral("raiseGlobalEvent: bad argument type #%1 (boolean, number, string or nil\n" | ||
| "expected, got a %2!)") |
There was a problem hiding this comment.
Similarly, here, I'd rather use: https://www.lua.org/manual/5.3/manual.html#lua_pushfstring
lua_pushstring(L, "raiseGlobalEvent: bad argument type #%d (boolean, number, string or nil expected, got a %s!)", i, luaL_typename(L, i))
ahmedcharles
left a comment
There was a problem hiding this comment.
I apparently still suck at doing reviews instead of individual comments. :P
Since we are not intending to translate the Mudlet Lua API error messages we can avoid instantiating QStrings in many places where Latin1 text is injected straight into the Lua sub-system. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
|
📖 Drat! Didn't read the Lua manual enough, used |
|
@ahmedcharles Do you like this better (can approve it) now? |
| .arg( i ) | ||
| .arg( luaL_typename( L, i ) ) | ||
| .toUtf8().constData() ); | ||
| lua_pushfstring(L, "raiseEvent: bad argument #%d type (string, number, boolean, or nil\n" |
There was a problem hiding this comment.
I guess I'm not sure why we are hardwrapping an error message like this, but I suppose it's not changed, so no need to fix it.
There was a problem hiding this comment.
Since it has been decided that the Mudlet Lua API should not have the capability to report errors in using the API in a translated form the use of the Qt
tr(...)function to mark suchQStringsis not wanted. This commit switches those usages to use theQStringLiteral(...)wrapper instead. As the strings concerned are each unique the known downsides of using this "non"-translatableQStringwrapper should not be significant and the code "template" for the two things are very similar {if there are no second or second & third arguments in thetr(...)case} - the editing to switch toQLatin1Stringsin the same location would be much more intensive.Where the (formerly) translated
QStringis then passed to the Lua system there are some instances whereQString::toUtf8()must be used instead ofQString::toLatin1()- these are generally the cases where a variable included in the resultingQStringcan contain non-ASCII characters which is any user defined/named item or {mainly on Windows platform} involving file-system objects as that can also have non-ASCII characters.There may be a few long text lines that I have manually inserted new-lines into to try and prevent the resulting text from exceeding around 80 characters when shown on the main profile console.
There was a typo in one error message for
TLuaInterpreter::downloadFileas it described an issue for argument 1 when it should have said 2. Also in three functions aQString "windowName"is set to the nullQStringwhen theQString::clear()is a little more descriptive of what is happening.Signed-off-by: Stephen Lyons slysven@virginmedia.com