New config file token TRANSLATE and @TR{text} template macro

This commit is contained in:
Ianos Gnatiuc 2006-02-21 09:30:48 +00:00
parent 823a7c8699
commit c9434d2ddb
7 changed files with 66 additions and 0 deletions

View File

@ -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} }

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -360,6 +360,7 @@ void CfgTemppath ();
void CfgTimeout ();
void CfgTimeoutsavemsg ();
void CfgTitlestatus ();
void CfgTranslate ();
void CfgTwitmode ();
void CfgTwitname ();
void CfgTwitsubj ();

View File

@ -352,6 +352,7 @@ public:
char tasktitle[60];
Tear tearline;
bool titlestatus;
GStrBag2 translate;
std::vector<Tpl> tpl;
int tplno;
bool templatematch;

View File

@ -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++;