-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLang 2.pluto
28 lines (23 loc) · 927 Bytes
/
Lang 2.pluto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
-- In this model, we register labels as we need them.
-- This has the downside that we cannot have multiple labels with the same English text.
local MyLangLib
pluto_class MyLangLib
static function trans(text)
local key = lang.find_registered(text)
if key == 0 then
key = lang.register(text)
end
return key
end
static function str_trans(text)
return lang.get_localised(MyLangLib.trans(text))
end
end
MyLangLib.trans("Hello, world!") -- We want to use this inside of the callback, but we need to register it now.
menu.my_root():action(MyLangLib.trans("Say Hello"), {}, "", function()
util.toast(MyLangLib.str_trans("Hello, world!"))
end)
-- Then after they're all registered, we can do translations via find_registered.
lang.set_translate("de")
lang.translate(lang.find_registered("Say Hello"), "Sag Hallo")
lang.translate(lang.find_registered("Hello, world!"), "Hallo, Welt!")