Since every client is a multilingual client (thanks to a button at the top), and this thread will likely contain information others will find useful........
Is there an easy way to detect what language the client is using (English, French, or German)?
The built-in mechanism, GetLocale() retrieves the OS locale setting, not the client. There is a fairly simple way to detect the EN client. To distinquish between the EN and DE/FR clients (for purposes of handling the number format issue if nothing else) you can use:
euroFormat=(tonumber("1,000")= =1);
where euroFormat will be true for the DE/FR clients and false for the EN client. If you're interested in automatically handling number format issues when users switch clients between saving their data and reloading it, check how euroFormat is used in main.lua in MoorMap.
EDIT: PTweety has a nice, simple solution to locale detection below
Last edited by Garan; Jul 08 2011 at 10:19 AM.
Gnashtooth - Rank 10 Warg - My breath's worse than my bite - but what d'ya want? I eat Hobbitsess fer cryin' out loud
Garan - Captain of little note - got parked at a Fell Scrying Pool so long it dried up and blew away
and many, many others...
"No, no, the hamsters are for the forums. The servers run on chinchillas!"-Patience 7/20/2007
Could one check for certain localized commands using Turbine.Shell.GetCommands() and derive the locale with this workarround?
EDIT: Something like this:
Code:
local function _find( value )
for cmd, name in pairs( Turbine.Shell.GetCommands() ) do
if string.lower( name ) == string.lower( value ) then
return true;
end
end
return false;
end
local _locale = "fr";
if _find( "hilfe" ) then
_locale = "de";
elseif _find( "help" ) then
_locale = "en";
end
Turbine.Shell.WriteLine( "SysLocale: "..Turbine.Engine.GetLocale()..", ClientLocale: ".._locale.."." );
Could one check for certain localized commands using Turbine.Shell.GetCommands() and derive the locale with this workarround?
EDIT: Something like this:
Code:
local function _find( value )
for cmd, name in pairs( Turbine.Shell.GetCommands() ) do
if string.lower( name ) == string.lower( value ) then
return true;
end
end
return false;
end
local _locale = "fr";
if _find( "hilfe" ) then
_locale = "de";
elseif _find( "help" ) then
_locale = "en";
end
Turbine.Shell.WriteLine( "SysLocale: "..Turbine.Engine.GetLocale()..", ClientLocale: ".._locale.."." );
Nice catch. I totally overlooked the Shell Commands. Turbine even provides a simpler test:
Code:
local _locale = "fr";
if Turbine.Shell.IsCommand("hilfe") then
_locale = "de";
elseif Turbine.Shell.IsCommand("help") then
_locale = "en";
end
or for the English-centric:
Code:
local _locale = "en";
if Turbine.Shell.IsCommand("hilfe") then
_locale = "de";
elseif Turbine.Shell.IsCommand("aide") then
_locale = "fr";
end
Last edited by Garan; Jul 08 2011 at 10:24 AM.
Gnashtooth - Rank 10 Warg - My breath's worse than my bite - but what d'ya want? I eat Hobbitsess fer cryin' out loud
Garan - Captain of little note - got parked at a Fell Scrying Pool so long it dried up and blew away
and many, many others...
"No, no, the hamsters are for the forums. The servers run on chinchillas!"-Patience 7/20/2007
local _locale = "en";
if Turbine.Shell.IsCommand("hilfe") then
_locale = "de";
elseif Turbine.Shell.IsCommand("aide") then
_locale = "fr";
end
Just in case someone will be looking to localize plugins for Russian Lotro, like I'm doing now for marvelous "CombatAnalysis". "help" command is SUDDENLY "help" in RU.Lotro, but "plugins" command is "плагины". Full check would look like this:
Code:
_G.locale = "en";
if Turbine.Shell.IsCommand("hilfe") then
_G.locale = "de";
elseif Turbine.Shell.IsCommand("aide") then
_G.locale = "fr";
elseif Turbine.Shell.IsCommand("плагины") then
_G.locale = "ru";
end
UPD: just make sure you file is UTF-8.
Feoktist of Landroval
(currently playing U8 on RU.Lotro)
Just in case someone will be looking to localize plugins for Russian Lotro, like I'm doing now for marvelous "CombatAnalysis". "help" command is SUDDENLY "help" in RU.Lotro, but "plugins" command is "плагины". Full check would look like this:
Code:
_G.locale = "en";
if Turbine.Shell.IsCommand("hilfe") then
_G.locale = "de";
elseif Turbine.Shell.IsCommand("aide") then
_G.locale = "fr";
elseif Turbine.Shell.IsCommand("плагины") then
_G.locale = "ru";
end
UPD: just make sure you file is UTF-8.
Thanks for the Russian translation.
I'm not sure about your client, but the US/EN client does not properly parse utf-8 encoded files. This causes any strings that are embedded in them that contain special characters to be corrupted when parsed and they either generate errors or just replace characters with things like question marks. To avoid this issue we don't save lua files in utf-8 encoding, rather we use ANSI and replace any special characters with the character codes that are used to generate them. For instance your "плагины" becomes
string.char(208)..string.char( 191)..string.char(208)..string .char(187)..string.char(208).. string.char(176)..string.char( 208)..string.char(179)..string .char(208)..string.char(184).. string.char(208)..string.char( 189)..string.char(209)..string .char(139)
It is obviously very cumbersome for Russian where every character is considered a "special" character. Unfortunately, this is the only way to be sure the files will work with any client (I just tested the parsing on a utf-8 file again today and it is still broken).
How did you obtain a Russian client? The only options I've seen available through Turbine were the EN/DE/FR clients.
Last edited by Garan; Apr 12 2012 at 11:50 AM.
Gnashtooth - Rank 10 Warg - My breath's worse than my bite - but what d'ya want? I eat Hobbitsess fer cryin' out loud
Garan - Captain of little note - got parked at a Fell Scrying Pool so long it dried up and blew away
and many, many others...
"No, no, the hamsters are for the forums. The servers run on chinchillas!"-Patience 7/20/2007
Ah yes, it would. I had missed that shortcut for literal characters. Makes those ugly strings a bit more manageable, thanks Moebius.
Gnashtooth - Rank 10 Warg - My breath's worse than my bite - but what d'ya want? I eat Hobbitsess fer cryin' out loud
Garan - Captain of little note - got parked at a Fell Scrying Pool so long it dried up and blew away
and many, many others...
"No, no, the hamsters are for the forums. The servers run on chinchillas!"-Patience 7/20/2007
In Soviet Яussia, you eat, drink, and breathe Unicode.
Originally Posted by Garan
It is obviously very cumbersome for Russian where every character is considered a "special" character. Unfortunately, this is the only way to be sure the files will work with any client (I just tested the parsing on a utf-8 file again today and it is still broken).
How did you obtain a Russian client? The only options I've seen available through Turbine were the EN/DE/FR clients.
You would have to know Russian to install it anyway. You can do with Google translate to browse the website, but otherwise I'm not sure they have an option for non-Russian speaking people (which kind of makes sense, if you think about it =)). If absolutely convinced you need the client, see how far you can get down this rabbit-hole http://www.lotro-russia.com/client/
On the Unicode side, in the Russian client there is absolutely no issue with .lua files saved in Unicode (utf-8 codepage), without this mocking about with \123. I have seen things like L["Conviction"] = "\195\156berzeugung" in the source files so I can feel your pain.
But for the record,
Turbine.Shell.IsCommand("\208\ 191\208\187\208\176\208\179\20 8\184\208\189\209\139")
also works. Since you've been throught this already, maybe you can suggest some tool to convert utf-8 files into this "safe" format?
Feoktist of Landroval
(currently playing U8 on RU.Lotro)
...which isn't even the right language to use, since it's a character by character operation. (This assumes that the only byte values >= 128 are UTF-8 characters inside Lua strings.)
Sorry I can't recommend any utility programs for converting utf-8 to LoTRO .lua compatible files, the only applications I use for this are small utilitity programs I've written myself - as Moebius pointed out, it's fairly easy to put together a conversion utility yourself. Most of the time I just do the replacements manually since I usually only run into this issue when I am translating new strings to French or German and it usually takes longer to settle on a suitable translation than it does to replace the special characters.
Gnashtooth - Rank 10 Warg - My breath's worse than my bite - but what d'ya want? I eat Hobbitsess fer cryin' out loud
Garan - Captain of little note - got parked at a Fell Scrying Pool so long it dried up and blew away
and many, many others...
"No, no, the hamsters are for the forums. The servers run on chinchillas!"-Patience 7/20/2007
...which isn't even the right language to use, since it's a character by character operation. (This assumes that the only byte values >= 128 are UTF-8 characters inside Lua strings.)
Thanks moebius and Garan, I actually mostly use perl for utility tasks. Unpack has some means for Unicode symbols I think, will look into it.
Feoktist of Landroval
(currently playing U8 on RU.Lotro)