translations: add infrastructure for translated OSD messages

Add function set_osd_tmsg() which is a version of set_osd_msg that
translates its format argument. Pass OSD message strings in the
command.c property_osd_display table through mp_gtext before they're
used.
This commit is contained in:
Uoti Urpala 2010-01-12 12:16:00 +02:00
parent 23e693d6d2
commit ee98209ab8
3 changed files with 26 additions and 10 deletions

View File

@ -2297,12 +2297,12 @@ static int show_property_osd(MPContext *mpctx, const char *pname)
else if (p->osd_progbar) {
if (prop->type == CONF_TYPE_INT) {
if (mp_property_do(pname, M_PROPERTY_GET, &r, mpctx) > 0)
set_osd_bar(mpctx, p->osd_progbar, p->osd_msg,
set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
prop->min, prop->max, r);
} else if (prop->type == CONF_TYPE_FLOAT) {
float f;
if (mp_property_do(pname, M_PROPERTY_GET, &f, mpctx) > 0)
set_osd_bar(mpctx, p->osd_progbar, p->osd_msg,
set_osd_bar(mpctx, p->osd_progbar, mp_gtext(p->osd_msg),
prop->min, prop->max, f);
} else {
mp_msg(MSGT_CPLAYER, MSGL_ERR,
@ -2316,8 +2316,8 @@ static int show_property_osd(MPContext *mpctx, const char *pname)
char *val = mp_property_print(pname, mpctx);
if (val) {
int index = p - property_osd_display;
set_osd_msg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
1, opts->osd_duration, p->osd_msg, val);
set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
1, opts->osd_duration, p->osd_msg, val);
free(val);
}
}

View File

@ -23,6 +23,7 @@ struct MPContext;
void set_osd_bar(struct MPContext *mpctx, int type,const char* name,double min,double max,double val);
void set_osd_msg(int id, int level, int time, const char* fmt, ...);
void set_osd_tmsg(int id, int level, int time, const char* fmt, ...);
void rm_osd_msg(int id);
#endif /* MPLAYER_MP_OSD_H */

View File

@ -1356,10 +1356,10 @@ static mp_osd_msg_t* osd_msg_stack = NULL;
* it is pulled on top of the stack, otherwise a new message is created.
*
*/
void set_osd_msg(int id, int level, int time, const char* fmt, ...) {
static void set_osd_msg_va(int id, int level, int time, const char *fmt,
va_list ap)
{
mp_osd_msg_t *msg,*last=NULL;
va_list va;
int r;
// look if the id is already in the stack
@ -1376,9 +1376,7 @@ void set_osd_msg(int id, int level, int time, const char* fmt, ...) {
osd_msg_stack = msg;
}
// write the msg
va_start(va,fmt);
r = vsnprintf(msg->msg, 128, fmt, va);
va_end(va);
r = vsnprintf(msg->msg, 128, fmt, ap);
if(r >= 128) msg->msg[127] = 0;
// set id and time
msg->id = id;
@ -1387,6 +1385,23 @@ void set_osd_msg(int id, int level, int time, const char* fmt, ...) {
}
void set_osd_msg(int id, int level, int time, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
set_osd_msg_va(id, level, time, fmt, ap);
va_end(ap);
}
void set_osd_tmsg(int id, int level, int time, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
set_osd_msg_va(id, level, time, mp_gtext(fmt), ap);
va_end(ap);
}
/**
* \brief Remove a message from the OSD stack
*