Add. Text class to manage translate texts.
This commit is contained in:
parent
6fa7dcfa30
commit
fedd5ba9fc
|
|
@ -1,4 +1,4 @@
|
||||||
text = {};
|
text = text or {};
|
||||||
|
|
||||||
text['label-download'] = {};
|
text['label-download'] = {};
|
||||||
text['label-download']['en-us'] = "Download";
|
text['label-download']['en-us'] = "Download";
|
||||||
|
|
@ -24,3 +24,4 @@ text['label-attached']['fr-fr'] = "Attaché";
|
||||||
text['label-attached']['de-de'] = "im Anhang";
|
text['label-attached']['de-de'] = "im Anhang";
|
||||||
text['label-attached']['de-at'] = "im Anhang";
|
text['label-attached']['de-at'] = "im Anhang";
|
||||||
|
|
||||||
|
return text
|
||||||
|
|
@ -25,10 +25,6 @@
|
||||||
|
|
||||||
local send_mail = require 'resources.functions.send_mail'
|
local send_mail = require 'resources.functions.send_mail'
|
||||||
|
|
||||||
local function T(str)
|
|
||||||
return text[str][default_language..'-'..default_dialect] or text[str]['en-us']
|
|
||||||
end
|
|
||||||
|
|
||||||
--define a function to send email
|
--define a function to send email
|
||||||
function send_email(id, uuid)
|
function send_email(id, uuid)
|
||||||
--get voicemail message details
|
--get voicemail message details
|
||||||
|
|
@ -58,7 +54,8 @@
|
||||||
--require the email address to send the email
|
--require the email address to send the email
|
||||||
if (string.len(voicemail_mail_to) > 2) then
|
if (string.len(voicemail_mail_to) > 2) then
|
||||||
--include languages file
|
--include languages file
|
||||||
require "app.voicemail.app_languages";
|
local Text = require "resources.functions.text"
|
||||||
|
local text = Text.new("app.voicemail.app_languages")
|
||||||
|
|
||||||
--get voicemail message details
|
--get voicemail message details
|
||||||
sql = [[SELECT * FROM v_voicemail_messages
|
sql = [[SELECT * FROM v_voicemail_messages
|
||||||
|
|
@ -142,11 +139,11 @@
|
||||||
body = body:gsub("${sip_to_user}", id);
|
body = body:gsub("${sip_to_user}", id);
|
||||||
body = body:gsub("${dialed_user}", id);
|
body = body:gsub("${dialed_user}", id);
|
||||||
if (voicemail_file == "attach") then
|
if (voicemail_file == "attach") then
|
||||||
body = body:gsub("${message}", T'label-attached');
|
body = body:gsub("${message}", text['label-attached']);
|
||||||
elseif (voicemail_file == "link") then
|
elseif (voicemail_file == "link") then
|
||||||
body = body:gsub("${message}", "<a href='https://"..domain_name.."/app/voicemails/voicemail_messages.php?action=download&type=vm&t=bin&id="..id.."&voicemail_uuid="..db_voicemail_uuid.."&uuid="..uuid.."&src=email'>"..T'label-download'.."</a>");
|
body = body:gsub("${message}", "<a href='https://"..domain_name.."/app/voicemails/voicemail_messages.php?action=download&type=vm&t=bin&id="..id.."&voicemail_uuid="..db_voicemail_uuid.."&uuid="..uuid.."&src=email'>"..text['label-download'].."</a>");
|
||||||
else
|
else
|
||||||
body = body:gsub("${message}", "<a href='https://"..domain_name.."/app/voicemails/voicemail_messages.php?action=autoplay&id="..db_voicemail_uuid.."&uuid="..uuid.."'>"..T'label-listen'.."</a>");
|
body = body:gsub("${message}", "<a href='https://"..domain_name.."/app/voicemails/voicemail_messages.php?action=autoplay&id="..db_voicemail_uuid.."&uuid="..uuid.."'>"..text['label-listen'].."</a>");
|
||||||
end
|
end
|
||||||
body = body:gsub(" ", " ");
|
body = body:gsub(" ", " ");
|
||||||
body = body:gsub("%s+", "");
|
body = body:gsub("%s+", "");
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
---
|
||||||
|
-- @tparam table dict Dictionary
|
||||||
|
-- @tparam[opt='en'] string language default language
|
||||||
|
-- @tparam[opt='us'] string dialect default language
|
||||||
|
-- @return[1] nil if key is unknown
|
||||||
|
-- @return[2] empty string if language/dialect unknown or there no appropriate value for default language/dialect
|
||||||
|
-- @return[3] translated value accordint dictionary/language/dialect
|
||||||
|
--
|
||||||
|
-- @usage
|
||||||
|
-- local dict = {
|
||||||
|
-- ['label-text'] = {
|
||||||
|
-- ['en-us'] = 'text';
|
||||||
|
-- ['ru-ru'] = 'текст';
|
||||||
|
-- }
|
||||||
|
-- }
|
||||||
|
-- local text = Text.new(dict)
|
||||||
|
-- -- use global `default_language` and `default_dialect` to resolve language
|
||||||
|
-- var = text['label-attached']
|
||||||
|
-- -- use prefix form
|
||||||
|
-- var = text'label-attached'
|
||||||
|
-- -- Implicit specify language
|
||||||
|
-- var = text('label-attached', 'ru', 'ru')
|
||||||
|
-- -- set global variables(you can set them even after ctor call)
|
||||||
|
-- default_language, default_dialect = 'ru', 'ru'
|
||||||
|
-- var = text['label-attached']
|
||||||
|
local function make_text(dict, language, dialect)
|
||||||
|
if not (language and dialect) then
|
||||||
|
language, dialect = 'en', 'us'
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(dict) == 'string' then
|
||||||
|
dict = require(dict)
|
||||||
|
end
|
||||||
|
|
||||||
|
local default = (language .. '-' .. dialect):lower()
|
||||||
|
|
||||||
|
local function index(_, k)
|
||||||
|
local t = dict[k]
|
||||||
|
if not t then return end
|
||||||
|
|
||||||
|
local lang
|
||||||
|
if default_language and default_dialect then
|
||||||
|
lang = (default_language .. '-' .. default_dialect):lower()
|
||||||
|
end
|
||||||
|
if not lang then lang = default end
|
||||||
|
return t[lang] or t[default] or ''
|
||||||
|
end
|
||||||
|
|
||||||
|
local function call(self, k, language, dialect)
|
||||||
|
if language and dialect then
|
||||||
|
local t = dict[k]
|
||||||
|
if not t then return end
|
||||||
|
local lang = (language .. '-' .. dialect):lower()
|
||||||
|
local v = t[lang]
|
||||||
|
if v then return v end
|
||||||
|
end
|
||||||
|
return self[k]
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable({},{
|
||||||
|
__newindex = function()
|
||||||
|
error('Can not add field to proxy')
|
||||||
|
end;
|
||||||
|
__index = index;
|
||||||
|
__call = call;
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
new = make_text;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue