+ Reply to Thread
Results 1 to 13 of 13
  1. #1
    Grand Member Online status: Almagnus1 is offline Reputation: Almagnus1 the Indomitable Almagnus1 the Indomitable Almagnus1 the Indomitable Almagnus1 the Indomitable Almagnus1 the Indomitable Almagnus1 the Indomitable Almagnus1 the Indomitable Almagnus1 the Indomitable Almagnus1 the Indomitable Almagnus1 the Indomitable Almagnus1 the Indomitable
    Join Date
    Dec 2007
    Posts
    5,542

    Automatic Client Language Detection

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

  2. #2
    Poster of Note Online status: Garan is offline Reputation: Garan has disabled reputation
    Join Date
    Mar 2007
    Posts
    832

    Re: Automatic Client Language Detection

    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

  3. #3
    Junior Member Online status: ptweety is offline Reputation: ptweety the Neutral
    Join Date
    Jun 2011
    Posts
    5

    AW: Automatic Client Language Detection

    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.."." );
    Last edited by ptweety; Jul 08 2011 at 03:18 AM.
    [Plugin] BuffMonitor, Screenshots: [1], [2], [3], [4], Download: [Klick]

    Grün ist die Hoffnung. Esst mehr Bohnen!

  4. #4
    Poster of Note Online status: Garan is offline Reputation: Garan has disabled reputation
    Join Date
    Mar 2007
    Posts
    832

    Re: AW: Automatic Client Language Detection

    Quote Originally Posted by ptweety View Post
    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

  5. #5
    Member Online status: Feoktist is offline Reputation: Feoktist the Wary Feoktist the Wary
    Join Date
    Apr 2009
    Posts
    99

    Re: AW: Automatic Client Language Detection

    Quote Originally Posted by Garan View Post
    Code:
        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)

  6. #6
    Poster of Note Online status: Garan is offline Reputation: Garan has disabled reputation
    Join Date
    Mar 2007
    Posts
    832

    Re: AW: Automatic Client Language Detection

    Quote Originally Posted by Feoktist View Post
    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

  7. #7
    Poster of Note Online status: moebius92 is offline Reputation: moebius92 the Neophyte moebius92 the Neophyte moebius92 the Neophyte moebius92 the Neophyte moebius92 the Neophyte moebius92 the Neophyte moebius92 the Neophyte moebius92 the Neophyte
    Join Date
    Jan 2008
    Posts
    842

    Re: Automatic Client Language Detection

    "\208\191\208\187\208\176\208\ 179\208\184\208\189\209\139" doesn't work?

  8. #8
    Grand Member Online status: Almagnus1 is offline Reputation: Almagnus1 the Indomitable Almagnus1 the Indomitable Almagnus1 the Indomitable Almagnus1 the Indomitable Almagnus1 the Indomitable Almagnus1 the Indomitable Almagnus1 the Indomitable Almagnus1 the Indomitable Almagnus1 the Indomitable Almagnus1 the Indomitable Almagnus1 the Indomitable
    Join Date
    Dec 2007
    Posts
    5,542

    Re: AW: Automatic Client Language Detection

    Quote Originally Posted by Garan View Post
    How did you obtain a Russian client? The only options I've seen available through Turbine were the EN/DE/FR clients.
    Can't resist this one, but in Soviet Russia, the client downloads you.

    Also, check: http://www.lotro-russia.com/

  9. #9
    Poster of Note Online status: Garan is offline Reputation: Garan has disabled reputation
    Join Date
    Mar 2007
    Posts
    832

    Re: Automatic Client Language Detection

    Quote Originally Posted by moebius92 View Post
    "\208\191\208\187\208\176\208\ 179\208\184\208\189\209\139" doesn't work?
    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

  10. #10
    Member Online status: Feoktist is offline Reputation: Feoktist the Wary Feoktist the Wary
    Join Date
    Apr 2009
    Posts
    99

    Re: AW: Automatic Client Language Detection

    In Soviet Яussia, you eat, drink, and breathe Unicode.
    Quote Originally Posted by Garan View Post
    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)

  11. #11
    Poster of Note Online status: moebius92 is offline Reputation: moebius92 the Neophyte moebius92 the Neophyte moebius92 the Neophyte moebius92 the Neophyte moebius92 the Neophyte moebius92 the Neophyte moebius92 the Neophyte moebius92 the Neophyte
    Join Date
    Jan 2008
    Posts
    842

    Re: Automatic Client Language Detection

    I'm not sure there's a program to do it off hand, but you could pretty much do it any language you cared to name. For perl, the following would work:

    Code:
    #!/usr/bin/perl
    
    open(file, $ARGV[0]);
    while (<file>) {
            foreach (unpack('C*', $_)) {
                    if ($_ >= 128) {
                            print "\\", $_;
                    } else {
                            print chr($_);
                    }
            }
    }
    close(file);
    ...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.)

  12. #12
    Poster of Note Online status: Garan is offline Reputation: Garan has disabled reputation
    Join Date
    Mar 2007
    Posts
    832

    Re: Automatic Client Language Detection

    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

  13. #13
    Member Online status: Feoktist is offline Reputation: Feoktist the Wary Feoktist the Wary
    Join Date
    Apr 2009
    Posts
    99

    Re: Automatic Client Language Detection

    Quote Originally Posted by moebius92 View Post
    Code:
    #!/usr/bin/perl
    ...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)

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts