From 90a9e55b775eb019c299e51a2a891442b5134ec1 Mon Sep 17 00:00:00 2001 From: markjcrane Date: Fri, 4 Mar 2016 15:51:10 -0700 Subject: [PATCH] Handle the phrases_dir nil in a more flexible way. --- .../resources/scripts/languages/languages.lua | 69 +++++++++---------- 1 file changed, 32 insertions(+), 37 deletions(-) diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/languages/languages.lua b/resources/install/scripts/app/xml_handler/resources/scripts/languages/languages.lua index eb618a0eca..7777e5c60d 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/languages/languages.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/languages/languages.lua @@ -34,14 +34,6 @@ --action = params:getHeader("action"); language = params:getHeader("lang"); ---make sure phrase_dir variable is not nil - if (phrases_dir == nil) then - --define the variable - phrases_dir = ''; - --include the config.lua and local.lua - require "resources.functions.config"; - end - --additional information --event_calling_function = params:getHeader("Event-Calling-Function"); @@ -150,38 +142,41 @@ table.insert(xml, [[ ]]); end - --read root xml language file, parse included xml files - local xml_file_paths = {} - local file_handle = io.open(phrases_dir.."/"..language.."/"..language..".xml", "r"); - if (file_handle ~= nil) then - for file_line in file_handle:lines() do - if (string.find(file_line, 'cmd="include" data="', 0, true) ~= nil) then - pos_beg = string.find(file_line, 'cmd="include" data="', 0, true) + 20; - pos_end = string.find(file_line, '"/>', 0, true) - 1; - xml_file_path = string.sub(file_line, pos_beg, pos_end); - table.insert(xml_file_paths, phrases_dir.."/"..language.."/"..xml_file_path); - --freeswitch.consoleLog("notice", "file path = "..xml_file_path.."\n"); + --if nil do nt include language xml from the file system the phrases directory is not set in default settings - category: switch name: phrases_dir or its false + --it also can be nil if config.lua is not writable so that it can be defined in it + if (phrases_dir == nil) then + --read root xml language file, parse included xml files + local xml_file_paths = {} + local file_handle = io.open(phrases_dir.."/"..language.."/"..language..".xml", "r"); + if (file_handle ~= nil) then + for file_line in file_handle:lines() do + if (string.find(file_line, 'cmd="include" data="', 0, true) ~= nil) then + pos_beg = string.find(file_line, 'cmd="include" data="', 0, true) + 20; + pos_end = string.find(file_line, '"/>', 0, true) - 1; + xml_file_path = string.sub(file_line, pos_beg, pos_end); + table.insert(xml_file_paths, phrases_dir.."/"..language.."/"..xml_file_path); + --freeswitch.consoleLog("notice", "file path = "..xml_file_path.."\n"); + end + end + file_handle:close(); + end + --iterate array of file paths, get contents of other xml macro files + for key, xml_file_path in pairs(xml_file_paths) do + if (file_exists(xml_file_path)) then + xml_file = io.open(xml_file_path, "r"); + if (xml_file ~= nil) then + xml_file_content = xml_file:read("*a"); + xml_file_content = string.gsub(xml_file_content, "", ''); + xml_file_content = string.gsub(xml_file_content, "", ''); + table.insert(xml, xml_file_content); + --freeswitch.consoleLog("notice", "file contents...\n\n"..xml_file_content.."\n"); + end + xml_file:close(); end end - file_handle:close(); - end + end - --iterate array of file paths, get contents of other xml macro files - for key, xml_file_path in pairs(xml_file_paths) do - if (file_exists(xml_file_path)) then - xml_file = io.open(xml_file_path, "r"); - if (xml_file ~= nil) then - xml_file_content = xml_file:read("*a"); - xml_file_content = string.gsub(xml_file_content, "", ''); - xml_file_content = string.gsub(xml_file_content, "", ''); - table.insert(xml, xml_file_content); - --freeswitch.consoleLog("notice", "file contents...\n\n"..xml_file_content.."\n"); - end - xml_file:close(); - end - end - - --output xml & close previous file + --output xml & close previous file table.insert(xml, [[ ]]); table.insert(xml, [[ ]]); table.insert(xml, [[ ]]);