1. #1
    High Overlord Crudor's Avatar
    Join Date
    Nov 2011
    Location
    Berlin
    Posts
    151

    Get locale/language of realm

    Is there any way to detect the language of the realm the user is currently on, with the WoW api?

    So for example: I run an English client on a German realm. Can an addon know I'am on a German realm?

  2. #2
    I think that the realm name are unique, so you could build N array (one per language) and check where the GetRealmName() belong to.

    If someone know a sexier way to do that, I will gladly take his solution.
    Quote Originally Posted by DemoBytom View Post
    But well - you don't really eat something that speaks to you, is part of "your people"

  3. #3

  4. #4
    GetLocal()

    enGB ptBR deDE esES frRF ruRU - Europe realms
    enUS - US realms
    znCH - China
    koKR - Korea
    zhTW - Taiwan
    Last edited by Aleaa; 2013-01-03 at 08:30 PM.
    @TimoshN #AffdotsPriest #SPTimer http://www.aleaaddons.ru

  5. #5
    High Overlord Crudor's Avatar
    Join Date
    Nov 2011
    Location
    Berlin
    Posts
    151
    GetLocale() returns enUS for EU english clients, too. so no identification possible with that either...

  6. #6
    Drycoded:
    Code:
    local function timezoneOffset()
        local realmHour,realmMin = GetGameTime()
        local utcHour, utcMin = tonumber(date("!%H")), tonumber(date("!%M"))
        local hourOffset = realmHour - utcHour
        local minOffset = realmMin - utcMin
        if minOffset < -30 then
            hourOffset = hourOffset - 1
        elseif minOffset > 30 then
            hourOffset = hourOffset + 1
        end
        return hourOffset
    end
    As long as the local clock is within 30 minutes of the server's clock, this should give you the time zone of the server.

    From here, you have two options:
    1) Assume everything below, say, UTC-3 is an US realm, and everything above UTC-3 is an EU realm. Other regions would require adjustments.
    2) Keep a database of every realm name, all occurrences of that realm name and the respective server time zones. First index with GetRealmName(), then check for the closest match (or assume a default language [english? the client's locale?] if no exact match is found).

    PS: Someone should make a library that does this.
    UI & AddOns expert | Interface & Macros moderator - My work

  7. #7
    GetCVar("locale")
    @TimoshN #AffdotsPriest #SPTimer http://www.aleaaddons.ru

  8. #8
    High Overlord Crudor's Avatar
    Join Date
    Nov 2011
    Location
    Berlin
    Posts
    151
    thanks, this should do the trick (even though having to maintain a table of all realms is somewhat clunky...)

  9. #9
    This is indeed a good idea for a lib. I will look at this tomorrow (I will create a new thread as soon as I have something correct.)
    Quote Originally Posted by DemoBytom View Post
    But well - you don't really eat something that speaks to you, is part of "your people"

Posting Permissions

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