Skip to content

I18n: clear out translatable Lua error messsages#941

Merged
SlySven merged 3 commits intoMudlet:developmentfrom
SlySven:I18b_clearOutTranslateableLuaErrorMesssages
Apr 23, 2017
Merged

I18n: clear out translatable Lua error messsages#941
SlySven merged 3 commits intoMudlet:developmentfrom
SlySven:I18b_clearOutTranslateableLuaErrorMesssages

Conversation

@SlySven
Copy link
Copy Markdown
Member

@SlySven SlySven commented Apr 21, 2017

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

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>
Copy link
Copy Markdown
Member

@vadi2 vadi2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 awesome. Trying your hand at the source code smashing too, hey?

@SlySven
Copy link
Copy Markdown
Member Author

SlySven commented Apr 21, 2017

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.

@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Apr 21, 2017

Happy to revisit it if circumstances change for sure.

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());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that makes sense, because we don't want a QString for Lua, and we're not dealing with UTF-8 here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😊 Humm, yes, that does seem to be the case for a fair proportion of the strings, gonna have to review what I dun!

.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!)")
Copy link
Copy Markdown
Contributor

@ahmedcharles ahmedcharles Apr 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))

Copy link
Copy Markdown
Contributor

@ahmedcharles ahmedcharles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@SlySven
Copy link
Copy Markdown
Member Author

SlySven commented Apr 22, 2017

📖 Drat! Didn't read the Lua manual enough, used %i as the lua integer placement parameter in the lua_printfstring(\<format string>, replacement values...) when I should have used %d - got to go and replace them all...! 😊

@SlySven
Copy link
Copy Markdown
Member Author

SlySven commented Apr 22, 2017

@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"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☹️ Agreed it is not ideal and I would like to revisit that at some point...

@SlySven SlySven merged commit 014b668 into Mudlet:development Apr 23, 2017
@SlySven SlySven deleted the I18b_clearOutTranslateableLuaErrorMesssages branch April 23, 2017 00:59
@SlySven SlySven restored the I18b_clearOutTranslateableLuaErrorMesssages branch June 22, 2020 17:59
@SlySven SlySven deleted the I18b_clearOutTranslateableLuaErrorMesssages branch June 22, 2020 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants