From c9434d2ddbb36e1a46c18add11ff1d35576a704a Mon Sep 17 00:00:00 2001 From: Ianos Gnatiuc Date: Tue, 21 Feb 2006 09:30:48 +0000 Subject: [PATCH] New config file token TRANSLATE and @TR{text} template macro --- docs/notework.txt | 7 +++++++ golded3/gccfgg.h | 1 + golded3/gccfgg0.cpp | 1 + golded3/gccfgg8.cpp | 11 +++++++++++ golded3/gcprot.h | 1 + golded3/gecfgg.h | 1 + golded3/gemsgs.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 66 insertions(+) diff --git a/docs/notework.txt b/docs/notework.txt index d9a5bcd..cddc693 100644 --- a/docs/notework.txt +++ b/docs/notework.txt @@ -10,6 +10,13 @@ ______________________________________________________________________ Notes for GoldED+ 1.1.5, /snapshot/ ______________________________________________________________________ ++ New config file token: Translate "text" "translation". Used together + with @tr{text} macro to translate some parts of template. + ++ Added new macro: @tr{text}, that can be used to translate texts in + templates. It is recursive. Look also at Translate keyword. + Example: @tr{ @oname{I}{You} } + + Macro @pad is recursive now. Example: @pad{=C79}{ @oname{I}{You} } diff --git a/golded3/gccfgg.h b/golded3/gccfgg.h index 67fe930..bf42948 100644 --- a/golded3/gccfgg.h +++ b/golded3/gccfgg.h @@ -379,6 +379,7 @@ const word CRC_TIMEOUTSAVEMSG = 0xF644; const word CRC_TIMESLICE = 0x3EFF; const word CRC_TIMESREAD = 0xDD0E; const word CRC_TITLESTATUS = 0x5ABA; +const word CRC_TRANSLATE = 0xE4E5; const word CRC_TWITMODE = 0x9DC8; const word CRC_TWITNAME = 0x2055; const word CRC_TWITSUBJ = 0x08C0; diff --git a/golded3/gccfgg0.cpp b/golded3/gccfgg0.cpp index 5a3c8f3..f1c1b32 100644 --- a/golded3/gccfgg0.cpp +++ b/golded3/gccfgg0.cpp @@ -576,6 +576,7 @@ SwitchT: case CRC_TEMPPATH : CfgTemppath (); break; case CRC_TIMEOUT : CfgTimeout (); break; case CRC_TITLESTATUS : CfgTitlestatus (); break; + case CRC_TRANSLATE : CfgTranslate (); break; case CRC_TWITMODE : CfgTwitmode (); break; case CRC_TWITNAME : CfgTwitname (); break; case CRC_TWITSUBJ : CfgTwitsubj (); break; diff --git a/golded3/gccfgg8.cpp b/golded3/gccfgg8.cpp index f9dc2f3..41053ff 100644 --- a/golded3/gccfgg8.cpp +++ b/golded3/gccfgg8.cpp @@ -242,6 +242,17 @@ void CfgTitlestatus(){ // ------------------------------------------------------------------ +void CfgTranslate() +{ + char* key; + getkeyval(&key, &val); + StripQuotes(key); + StripQuotes(val); + CFG->translate.Add(strupr(key), val); +} + +// ------------------------------------------------------------------ + void CfgTwitmode() { int tmp = TWIT_SHOW; diff --git a/golded3/gcprot.h b/golded3/gcprot.h index 45ac770..b87cb80 100644 --- a/golded3/gcprot.h +++ b/golded3/gcprot.h @@ -360,6 +360,7 @@ void CfgTemppath (); void CfgTimeout (); void CfgTimeoutsavemsg (); void CfgTitlestatus (); +void CfgTranslate (); void CfgTwitmode (); void CfgTwitname (); void CfgTwitsubj (); diff --git a/golded3/gecfgg.h b/golded3/gecfgg.h index 64c6ffa..8b39980 100644 --- a/golded3/gecfgg.h +++ b/golded3/gecfgg.h @@ -352,6 +352,7 @@ public: char tasktitle[60]; Tear tearline; bool titlestatus; + GStrBag2 translate; std::vector tpl; int tplno; bool templatematch; diff --git a/golded3/gemsgs.cpp b/golded3/gemsgs.cpp index ff463b5..76ecfdd 100644 --- a/golded3/gemsgs.cpp +++ b/golded3/gemsgs.cpp @@ -89,6 +89,36 @@ static bool tokenxchg(std::string &input, std::string::iterator &pos, } +// ------------------------------------------------------------------ + +static void translate(std::string &text) +{ + GStrBag2 &strbag = CFG->translate; + + if (strbag.First()) + { + do + { + const char* str1 = strbag.Current1(); + size_t s1len = strlen(str1); + + std::string::iterator pos; + for (pos = text.begin(); (*pos != '}') && (pos != text.end()); pos++) + { + if (strnieql(pos, str1, s1len)) + { + const char* str2 = strbag.Current2(); + size_t idx = pos - text.begin(); + text.replace(pos, pos+s1len, str2, strlen(str2)); + pos = text.begin() + idx; + } + } + } + while (strbag.Next()); + } +} + + // ------------------------------------------------------------------ inline bool domain_requested(std::string::iterator str, size_t pos) @@ -624,6 +654,20 @@ void TokenXlat(int mode, std::string &input, GMsg* msg, GMsg* oldmsg, int __orig continue; } } + + if (strnieql(dst, "@tr{", 4)) + { + std::string buff = input.substr(dst+3-input.begin()); + TokenXlat(mode, buff, msg, oldmsg, __origarea); + translate(buff); + + size_t idx = dst - input.begin(); + input.replace(dst+3, input.end(), buff); + dst = input.begin() + idx; + + if (tokenxchg(input, dst, "@tr", "", 0, 1, (int)true)) + continue; + } } dst++;