Add these gettext "macros" to the scripting engine: N_, P_, PE_, NP_, gettext_noop and pgettext, which work just like their C counterparts

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5689 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2008-07-28 02:12:59 +00:00
parent 40a8a0c1ff
commit f7a433bf51
3 changed files with 105 additions and 0 deletions

View File

@ -11747,3 +11747,80 @@ BOOL scrGettext()
return stackPushResult(ST_TEXTSTRING, &scrFunctionResult);
}
BOOL scrGettext_noop()
{
if (!stackPopParams(1, VAL_STRING, &strParam1))
{
return false;
}
scrFunctionResult.v.sval = gettext_noop(strParam1);
return stackPushResult(VAL_STRING, &scrFunctionResult);
}
BOOL scrPgettext()
{
char* msg_ctxt_id;
char* translation;
if (!stackPopParams(2, VAL_STRING, &strParam1, VAL_STRING, &strParam2))
{
return false;
}
asprintf(&msg_ctxt_id, "%s%s%s", strParam1, GETTEXT_CONTEXT_GLUE, strParam2);
if (!msg_ctxt_id)
{
debug(LOG_ERROR, "Out of memory");
abort();
return false;
}
#ifdef DEFAULT_TEXT_DOMAIN
translation = dcgettext(DEFAULT_TEXT_DOMAIN, msg_ctxt_id, LC_MESSAGES);
#else
translation = dcgettext(NULL, msg_ctxt_id, LC_MESSAGES);
#endif
/* Due to the way dcgettext works a pointer comparison is enough, hence
* the reason why we free() now.
*/
free(msg_ctxt_id);
if (translation == msg_ctxt_id)
{
scrFunctionResult.v.sval = strParam2;
}
else
{
scrFunctionResult.v.sval = translation;
}
return stackPushResult(ST_TEXTSTRING, &scrFunctionResult);
}
BOOL scrPgettext_expr()
{
if (!stackPopParams(2, VAL_STRING, &strParam1, VAL_STRING, &strParam2))
{
return false;
}
scrFunctionResult.v.sval = (char*)pgettext_expr(strParam1, strParam2);
return stackPushResult(ST_TEXTSTRING, &scrFunctionResult);
}
BOOL scrPgettext_noop()
{
if (!stackPopParams(2, VAL_STRING, &strParam1, VAL_STRING, &strParam2))
{
return false;
}
scrFunctionResult.v.sval = gettext_noop(strParam1);
return stackPushResult(VAL_STRING, &scrFunctionResult);
}

View File

@ -657,6 +657,10 @@ extern BOOL scrWeaponFirePauseUpgrade(void);
extern BOOL scrIsComponentAvailable(void);
extern BOOL scrGetBodySize(void);
extern BOOL scrGettext(void);
extern BOOL scrGettext_noop(void);
extern BOOL scrPgettext(void);
extern BOOL scrPgettext_expr(void);
extern BOOL scrPgettext_noop(void);
extern BOOL beingResearchedByAlly(SDWORD resIndex, SDWORD player);

View File

@ -1467,6 +1467,30 @@ FUNC_SYMBOL asFuncTable[] =
1, { VAL_STRING },
false, 0, NULL, 0, 0, NULL, NULL },
{ "N_", scrGettext_noop, VAL_STRING,
1, { VAL_STRING },
false, 0, NULL, 0, 0, NULL, NULL },
{ "gettext_noop", scrGettext_noop, VAL_STRING,
1, { VAL_STRING },
false, 0, NULL, 0, 0, NULL, NULL },
{ "P_", scrPgettext, (INTERP_TYPE)ST_TEXTSTRING,
2, { VAL_STRING, VAL_STRING },
false, 0, NULL, 0, 0, NULL, NULL },
{ "pgettext", scrPgettext, (INTERP_TYPE)ST_TEXTSTRING,
2, { VAL_STRING, VAL_STRING },
false, 0, NULL, 0, 0, NULL, NULL },
{ "PE_", scrPgettext_expr, (INTERP_TYPE)ST_TEXTSTRING,
2, { VAL_STRING, VAL_STRING },
false, 0, NULL, 0, 0, NULL, NULL },
{ "NP_", scrPgettext_noop, VAL_STRING,
2, { VAL_STRING, VAL_STRING },
false, 0, NULL, 0, 0, NULL, NULL },
/* END new functions */
/* This final entry marks the end of the function list */