Does anyone know of any open-sourced modules for getting a user’s full country/region? Localization:GetCountryRegionForPlayerAsync()
returns GB
for me but I want it to be automatically converted to Great Britain
, for example.
3 Likes
local Players = game:GetService("Players")
local HttpService = game:GetService("HttpService")
local LocalizationService = game:GetService("LocalizationService")
local Countries = {}
local success, result = pcall(function()
return HttpService:GetAsync("http://country.io/names.json")
end)
if success and result then
Countries = HttpService:JSONDecode(result)
end
Players.PlayerAdded:Connect(function(player)
local success, code = pcall(LocalizationService.GetCountryRegionForPlayerAsync, LocalizationService, player)
if success and code then
print(Countries[code])
end
end)
14 Likes
Thanks a lot.
chars
1 Like
How can I get the country code from the actual name? [Ex: Canada → CA]
1 Like
LocalizationService already does this for you automatically. The reason the HTTP request in the original solution is sent is so it can translate the country/region code to an actual country name (the reverse of what you want to do). Removing the HTTP to the website should have the effect you want.
Made a post about it awhile ago with working code for country codes, check it out if you’d like.
3 Likes
uh, it returns nil for me, does someone know what might be an issue?
also yes, http requests are enabled :v