Hi, maybe this:
import macros, strutils, tables
var cfgFile = """title_ENh = Hubanize
title_DKh = Hubanize
title_ENc = Cx Manager
title_DKc = Cx Manager
help_ENh = Help
help_DKh = Hjælp
help_ENc = Help
help_DKc = Hjælp"""
var multiLang = initTable[string, string]()
macro readCfgAndBuildSource(cfgFilename: string): typed =
let
inputString = cfgFile
#...or from file by compile time
#inputString = slurp(cfgFilename.strVal)
var source = ""
for line in inputString.splitLines:
# Ignore empty lines
if line.len < 1: continue
var chunks = split(line, '=')
if chunks.len != 2:
error("Input needs '=' split values, got: " & line)
source &= "multiLang[\"" & chunks[0].strip & "\"] = \"" &
chunks[1].strip & "\"\n"
#echo source
if source.len < 1: error("Input file empty!")
result = parseStmt(source)
proc langGen*(identifier, pageID: string, lang = "EN"): string =
## Retrive language item
## identifier => The item to retrieve
## pageID => c or h based on the host address. Accessed per user with
c.pageID
## lang => Language. Accessed per user with c.lang - test users can
have empty lang, therefor standard "EN"
try:
return multiLang[identifier & "_" & lang & pageID]
except:
return ""
readCfgAndBuildSource("languagefile.cfg")
echo langGen("title", "c", "EN") # = Cx Manager
echo langGen("help", "h", "DK") # = Hjælp