[MPlayer-dev-eng] New translation system
Michael Niedermayer
michaelni at gmx.at
Thu Nov 30 17:50:10 CET 2006
Hi
On Thu, Nov 30, 2006 at 02:33:25PM +0200, Uoti Urpala wrote:
[...]
>
> > > 5 Outdated, broken or intentionally harmful translation files should not
> > > cause crashes or security holes.
> >
> > Unreasonable requirement.
>
> It is doable without too much trouble and a useful property to have, so
> in no way an unreasonable requirement.
checking all strings for validity is not terribly difficult, just search for
all % and check that number order and type match between all corresponding
pairs from 2 translation files
the only thing required is the ability to enumerate all strings ...
[...]
> > Using strings as keys for looking up strings is idiotic and plain
> > wrong, both semantically and in terms of implementation sanity.
> > Indices are numbers not strings. We code in C not PHP.
>
> Completely baseless drivel.
i am too very strongly against string based "indices"
one simple implementation would be something like:
mplayer.c
mp_msg(MSGT_CPLAYER, MSGL_INFO, GET_TR(MSID_ExitingHow), how);
help_mp.h
#define GET_TR(id) tr_table[language][id]
enum{
MSID_ExitingHow,
...
MSID_COUNT,
}
char **tr_table[LANGUAGE_COUNT];
help_mp-en.h
static char *table[MSID_COUNT]={
[MSID_ExitingHow] = "Exiting %s",
...
}
tr_table[LANG_ID_EN]= table;
with this you could
* compile with any subset of languages
* switch between them at runtime
* enumerate all strings
* the table itself could be even put in seperate shared lib if you are crazy
in which case you could add new languages without recompling
* if you are not crazy then recompiling and linking just the table is enough,
no need to recompile the whole mplayer source if you change something
* very space efficient (just a sizeof(void*) per string)
* no new dependancies
* fallback possible if a specific string isnt translated, or more specifically
init(){
if(!tr_table[lang])
tr_table[lang]= tr_table[default_lang];
for(i=0; i<MSID_COUNT; i++){
if(!tr_table[lang][i])
tr_table[lang][i]= tr_table[default_lang][i];
}
}
* O(1)
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
In the past you could go to a library and read, borrow or copy any book
Today you'd get arrested for mere telling someone where the library is
More information about the MPlayer-dev-eng
mailing list