automatically set language on Android

This commit is contained in:
chrox
2014-06-08 21:32:45 +08:00
parent 88061b323e
commit 20bd14d588
2 changed files with 14 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
local isAndroid, android = pcall(require, "android")
local DEBUG = require("dbg")
local GetText = {
@@ -96,4 +97,16 @@ elseif os.getenv("LANG") then
GetText.changeLang(os.getenv("LANG"))
end
if isAndroid then
local ffi = require("ffi")
local buf = ffi.new("char[?]", 16)
ffi.C.AConfiguration_getLanguage(android.app.config, buf)
local lang = ffi.string(buf)
ffi.C.AConfiguration_getCountry(android.app.config, buf)
local country = ffi.string(buf)
if lang and country then
GetText.changeLang(lang.."_"..country)
end
end
return GetText