Module:Sandbox/CXuesong/Translations/TranslationBuilder

- -- This module is used to build and store translation dictionary. -- The terms are orderd and case-sensitive. -

local p = {}

local Dictionary = {}

local OrderedTerms = {}

local CurrentGroup = nil

local Warnings = {}

function warn(message) ne = debug.traceback(message, 2) table.insert(Warnings, ne) return ne end

function p.beginGroup(groupName) if groupName == nil or groupName == "" then warn("groupName cannot be nil or empty.") end if CurrentGroup ~= nil then warn(string.format("Currently in the Group: %s .", CurrentGroup)) end CurrentGroup = groupName end

function p.endGroup if CurrentGroup == nil then error("Currently not in any Group.") end CurrentGroup = groupName end

-- Add a translation entry to the dictionary. function p.addTranslation(term, translations) if Dictionary[term] ~= nil then warn(string.format("Term \"%s\" already exists. Translation ignored.", term)) return end table.insert(OrderedTerms, term) Dictionary[term] = translations end

function p.orderedTerms return OrderedTerms end

function p.getTranslation(term) return Dictionary[term] end

return p