mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
Add gettext_spec stub (#3343)
This commit is contained in:
@@ -36,14 +36,13 @@ end
|
||||
-- we only implement a sane subset for now
|
||||
|
||||
function GetText_mt.__index.changeLang(new_lang)
|
||||
-- can be various things such as `en_US` or `en_US:en`
|
||||
if new_lang:match("^en_US") == "en_US" then return end
|
||||
|
||||
GetText.translation = {}
|
||||
GetText.current_lang = "C"
|
||||
|
||||
-- the "C" locale disables localization alltogether
|
||||
if new_lang == "C" or new_lang == nil then return end
|
||||
-- the "C" locale disables localization altogether
|
||||
-- can be various things such as `en_US` or `en_US:en`
|
||||
if new_lang == "C" or new_lang == nil or new_lang == ""
|
||||
or new_lang:match("^en_US") == "en_US" then return end
|
||||
|
||||
-- strip encoding suffix in locale like "zh_CN.utf8"
|
||||
new_lang = new_lang:sub(1, new_lang:find(".%."))
|
||||
@@ -53,7 +52,7 @@ function GetText_mt.__index.changeLang(new_lang)
|
||||
|
||||
if not po then
|
||||
logger.err("cannot open translation file:", file)
|
||||
return
|
||||
return false
|
||||
end
|
||||
|
||||
local data = {}
|
||||
|
||||
2
kodev
2
kodev
@@ -561,7 +561,7 @@ OPTIONS:
|
||||
busted --lua="./luajit" "${opts}" \
|
||||
--no-auto-insulate \
|
||||
--lazy \
|
||||
-o "./spec/$1/unit/verbose_print" \
|
||||
--output=gtest \
|
||||
--exclude-tags=notest "${test_path}"
|
||||
} && popd || exit
|
||||
}
|
||||
|
||||
25
spec/unit/gettext_spec.lua
Normal file
25
spec/unit/gettext_spec.lua
Normal file
@@ -0,0 +1,25 @@
|
||||
describe("GetText module", function()
|
||||
local GetText
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
GetText = require("gettext")
|
||||
end)
|
||||
describe("changeLang", function()
|
||||
it("should return nil when passing newlang = C", function()
|
||||
assert.is_nil(GetText.changeLang("C"))
|
||||
end)
|
||||
it("should return nil when passing empty string or nil value", function()
|
||||
assert.is_nil(GetText.changeLang(nil))
|
||||
assert.is_nil(GetText.changeLang(""))
|
||||
end)
|
||||
it("should return nil when passing values that start with en_US", function()
|
||||
assert.is_nil(GetText.changeLang("en_US"))
|
||||
assert.is_nil(GetText.changeLang("en_US:en"))
|
||||
assert.is_nil(GetText.changeLang("en_US.utf8"))
|
||||
end)
|
||||
it("should return false when it can't find a po file", function()
|
||||
assert.is_false(GetText.changeLang("nonsense"))
|
||||
assert.is_false(GetText.changeLang("more_NONSENSE"))
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
Reference in New Issue
Block a user