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?
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?
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.
unfortunately the names are not unique:
http://eu.battle.net/wow/en/status#name=dethecus and
http://us.battle.net/wow/en/status#name=dethecus
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.
GetLocale() returns enUS for EU english clients, too. so no identification possible with that either...
Drycoded:
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.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
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.
thanks, this should do the trick (even though having to maintain a table of all realms is somewhat clunky...)
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.)