From 859212df2523e8b15076d968018dbf98618fd60f Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 15 Jun 2010 10:44:51 +0000 Subject: Implement translation support for ScummVM GUI. Based on patch #2903830: "Updated Translation Prototype" by alexbevi which in turn is based on patch #1739965 by jvprat. Currently it builds all translations right into ScummVM. Once the feature will be accepted more widely, i.e. more translations will pop up, it will be trivial to move translation strings to external file. Finished translation: Russian Unfinished translation: Hungarian Things which are nice to do: - Language code -> language mapping for more user friendness - Specifying fonts to be used with language - Updating of interface language without restart. It will require moving of much code to reflowLayout() methods for each dialog The .po files must be in single byte encodings. I.e. no support for Unicode. svn-id: r49759 --- tools/po2c | 280 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 280 insertions(+) create mode 100755 tools/po2c (limited to 'tools/po2c') diff --git a/tools/po2c b/tools/po2c new file mode 100755 index 0000000000..ac1744aa2c --- /dev/null +++ b/tools/po2c @@ -0,0 +1,280 @@ +#!/usr/bin/perl + +# +# po2c - Converts .po files to C code +# +# Copyright (C) 2004 Angel Ortega +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# http://www.triptico.com +# + +$VERSION = "1.0.2"; + +if(scalar(@ARGV) == 0) +{ + print "Usage: po2c {po file[s]}\n"; + exit 1; +} + +%msgs = (); +%msgids = (); + +# stage 1: loading + +# arguments are .po files +foreach my $f (@ARGV) +{ + my ($lang); + my ($langDesc); + + next unless(($lang) = ($f =~ /([^\/]+)\.po$/)); + + if(open F, $f) + { + my ($msgid, $val, %a); + + while() + { + chomp; + + # ignore blank lines or comments + next if /^$/ or /^#/; + + if(/^msgid\s+\"(.*)\"\s*$/) + { + # store previous msgid + if(defined($msgid)) + { + $a{$msgid} = $val; + $msgids{$msgid} ++; + } + + # start of msgid + $val = $1; + } + elsif(/^msgstr\s+\"(.*)\"\s*$/) + { + # store previous msgid + $msgid = $val; + + # start of msgstr + $val = $1; + } + elsif(/^\"(.*)\"\s*$/) + { + # add to current value + $val .= $1; + } + } + + # store previous msgid + if(defined($msgid)) + { + $a{$msgid} = $val; + $msgids{$msgid} ++; + } + + close F; + + # add to the global message pool + $msgs{$lang} = \%a; + } +} + +# stage 2: convert the data + +# stores all sorted msgids into @msgids +@msgids = sort(keys(%msgids)); + +# travels again, storing indexes into %msgids +for(my $n = 0;$n < scalar(@msgids);$n++) +{ + $msgids{$msgids[$n]} = $n; +} + +# stage 3: dump as C code + +print "/* generated by po2c $VERSION - Do not modify */\n\n"; +print "#include \n"; +print "#include \n\n"; + +# dump first the msgid array +print "static const char * _po2c_msgids[] = {\n"; + +for(my $n = 0;$n < scalar(@msgids);$n++) +{ + print "\t/* $n */ \"" . $msgids[$n] . "\",\n"; +} + +print "\tNULL\n};\n\n"; + +# dump the lang structure +print "struct _po2c_msg {\n"; +print "\tint msgid;\n"; +print "\tconst char * msgstr;\n"; +print "};\n\n"; + +# dump now each language + +foreach my $l (keys(%msgs)) +{ + print "static struct _po2c_msg _po2c_lang_${l}\[\] = {\n"; + + # get the translation table for the language $l + my ($m) = $msgs{$l}; + +# while (my ($msgstr, $msgid) = each (%$m)) + foreach my $msgid (sort(keys(%$m))) + { + my ($msgstr) = ""; + + # make it 7-bit safe + foreach $c (split(//, $m->{$msgid})) { + if (ord($c) > 0x7f) { + $msgstr .= sprintf("\\%o", ord($c)); + } else { + $msgstr .= $c; + } + } + + print "\t{ " . $msgids{$msgid} . ", \"" . $msgstr . "\" },\n" + if $msgstr; + } + + print "\t{ -1, NULL }\n};\n\n"; +} + +# finally, dump the languages + +print "static struct {\n"; +print "\tconst char * lang;\n"; +print "\tconst char * charset;\n"; +print "\tstruct _po2c_msg * msgs;\n"; +print "} _po2c_langs[] = {\n"; + +foreach my $l (keys(%msgs)) +{ + $header = $msgs{$l}->{""}; + $header =~ /charset=([^\\]+)/; + $charset = $1; + print "\t{ \"" . $l . "\", \"" . $charset . "\", _po2c_lang_${l} },\n"; +} + +print "\t{ NULL, NULL, NULL }\n};\n\n"; + +print "/* code */\n"; +print << 'EOF'; + +static struct _po2c_msg * _po2c_lang=NULL; +static int _po2c_lang_size=0; +static const char * _po2c_charset=NULL; + +void po2c_setlang(const char * lang) +{ + int n; + + _po2c_lang=NULL; + _po2c_lang_size=0; + _po2c_charset=NULL; + + /* if lang is NULL or "", deactivate it */ + if(lang == NULL || *lang == '\0') + return; + + /* searches for a valid language array */ + for(n=0;_po2c_lang == NULL && _po2c_langs[n].lang != NULL;n++) + { + if(strcmp(lang, _po2c_langs[n].lang) == 0) { + _po2c_lang=_po2c_langs[n].msgs; + _po2c_charset=_po2c_langs[n].charset; + } + } + + /* try partial searches */ + for(n=0;_po2c_lang == NULL && _po2c_langs[n].lang != NULL;n++) + { + if(strncmp(lang, _po2c_langs[n].lang, 2) == 0) { + _po2c_lang=_po2c_langs[n].msgs; + _po2c_charset=_po2c_langs[n].charset; + } + } + + /* if found, count entries */ + if(_po2c_lang != NULL) + { + struct _po2c_msg * m; + + for(m=_po2c_lang;m->msgid != -1;m++) + _po2c_lang_size++; + } +} + +const char * po2c_gettext(const char * msgid) +{ + struct _po2c_msg * m; + int b, t, n, c; + + /* if no language is set or msgid is empty, return msgid as is */ + if(_po2c_lang == NULL || *msgid == '\0') + return(msgid); + + /* binary-search for the msgid */ + b=0; t=_po2c_lang_size - 1; + + while(t >= b) + { + n=(b + t) / 2; + m=&_po2c_lang[n]; + + c=strcmp(msgid, _po2c_msgids[m->msgid]); + + if(c == 0) + return(m->msgstr); + else + if(c < 0) + t=n - 1; + else + b=n + 1; + } + + return(msgid); +} + +const char * po2c_getcharset(void) +{ + if (_po2c_charset) + return _po2c_charset; + else + return "ASCII"; +} + +int po2c_getnumlangs(void) +{ + int n = 0; + while (_po2c_langs[n].lang) + n++; + + return n; +} + +const char * po2c_getlang(int num) +{ + return _po2c_langs[num].lang; +} +EOF + +exit 0; -- cgit v1.2.3 From c96991d991ed46fe7d79bde67d21808cf03969d1 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 24 Jun 2010 21:59:03 +0000 Subject: Added some consts to the output of tools/po2c. svn-id: r50238 --- tools/po2c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tools/po2c') diff --git a/tools/po2c b/tools/po2c index ac1744aa2c..f6aff97404 100755 --- a/tools/po2c +++ b/tools/po2c @@ -113,7 +113,7 @@ print "#include \n"; print "#include \n\n"; # dump first the msgid array -print "static const char * _po2c_msgids[] = {\n"; +print "static const char * const _po2c_msgids[] = {\n"; for(my $n = 0;$n < scalar(@msgids);$n++) { @@ -132,7 +132,7 @@ print "};\n\n"; foreach my $l (keys(%msgs)) { - print "static struct _po2c_msg _po2c_lang_${l}\[\] = {\n"; + print "static const struct _po2c_msg _po2c_lang_${l}\[\] = {\n"; # get the translation table for the language $l my ($m) = $msgs{$l}; @@ -160,10 +160,10 @@ foreach my $l (keys(%msgs)) # finally, dump the languages -print "static struct {\n"; +print "static const struct {\n"; print "\tconst char * lang;\n"; print "\tconst char * charset;\n"; -print "\tstruct _po2c_msg * msgs;\n"; +print "\tconst struct _po2c_msg * msgs;\n"; print "} _po2c_langs[] = {\n"; foreach my $l (keys(%msgs)) @@ -179,7 +179,7 @@ print "\t{ NULL, NULL, NULL }\n};\n\n"; print "/* code */\n"; print << 'EOF'; -static struct _po2c_msg * _po2c_lang=NULL; +static const struct _po2c_msg * _po2c_lang=NULL; static int _po2c_lang_size=0; static const char * _po2c_charset=NULL; @@ -216,7 +216,7 @@ void po2c_setlang(const char * lang) /* if found, count entries */ if(_po2c_lang != NULL) { - struct _po2c_msg * m; + const struct _po2c_msg * m; for(m=_po2c_lang;m->msgid != -1;m++) _po2c_lang_size++; @@ -225,7 +225,7 @@ void po2c_setlang(const char * lang) const char * po2c_gettext(const char * msgid) { - struct _po2c_msg * m; + const struct _po2c_msg * m; int b, t, n, c; /* if no language is set or msgid is empty, return msgid as is */ -- cgit v1.2.3 From 63cab52b854bedb33d5b2ef478c7f2568440a589 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 24 Jun 2010 21:59:27 +0000 Subject: Adapt po2c's output to better mach our code formatting conventions. Along with it I added a suffix "-scummvm" to the version variable, since we also feature some custom extensions like the charset specification. svn-id: r50239 --- tools/po2c | 128 +++++++++++++++++++++++++++---------------------------------- 1 file changed, 57 insertions(+), 71 deletions(-) (limited to 'tools/po2c') diff --git a/tools/po2c b/tools/po2c index f6aff97404..a2b006cd6b 100755 --- a/tools/po2c +++ b/tools/po2c @@ -22,7 +22,7 @@ # http://www.triptico.com # -$VERSION = "1.0.2"; +$VERSION = "1.0.2-scummvm"; if(scalar(@ARGV) == 0) { @@ -106,9 +106,9 @@ for(my $n = 0;$n < scalar(@msgids);$n++) $msgids{$msgids[$n]} = $n; } -# stage 3: dump as C code +# stage 3: dump as C++ code -print "/* generated by po2c $VERSION - Do not modify */\n\n"; +print "// generated by po2c $VERSION - Do not modify\n\n"; print "#include \n"; print "#include \n\n"; @@ -123,16 +123,16 @@ for(my $n = 0;$n < scalar(@msgids);$n++) print "\tNULL\n};\n\n"; # dump the lang structure -print "struct _po2c_msg {\n"; +print "struct PoMessageEntry {\n"; print "\tint msgid;\n"; -print "\tconst char * msgstr;\n"; +print "\tconst char *msgstr;\n"; print "};\n\n"; # dump now each language foreach my $l (keys(%msgs)) { - print "static const struct _po2c_msg _po2c_lang_${l}\[\] = {\n"; + print "static const PoMessageEntry _po2c_lang_${l}\[\] = {\n"; # get the translation table for the language $l my ($m) = $msgs{$l}; @@ -160,11 +160,12 @@ foreach my $l (keys(%msgs)) # finally, dump the languages -print "static const struct {\n"; -print "\tconst char * lang;\n"; -print "\tconst char * charset;\n"; -print "\tconst struct _po2c_msg * msgs;\n"; -print "} _po2c_langs[] = {\n"; +print "struct PoLangEntry {\n"; +print "\tconst char *lang;\n"; +print "\tconst char *charset;\n"; +print "\tconst PoMessageEntry *msgs;\n"; +print "};\n\n"; +print "const PoLangEntry _po2c_langs[] = {\n"; foreach my $l (keys(%msgs)) { @@ -176,103 +177,88 @@ foreach my $l (keys(%msgs)) print "\t{ NULL, NULL, NULL }\n};\n\n"; -print "/* code */\n"; +print "// code\n"; print << 'EOF'; -static const struct _po2c_msg * _po2c_lang=NULL; -static int _po2c_lang_size=0; -static const char * _po2c_charset=NULL; - -void po2c_setlang(const char * lang) -{ - int n; +static const struct PoMessageEntry *_po2c_lang = NULL; +static int _po2c_lang_size = 0; +static const char * _po2c_charset = NULL; - _po2c_lang=NULL; - _po2c_lang_size=0; - _po2c_charset=NULL; +void po2c_setlang(const char *lang) { + _po2c_lang = NULL; + _po2c_lang_size = 0; + _po2c_charset = NULL; - /* if lang is NULL or "", deactivate it */ - if(lang == NULL || *lang == '\0') + // if lang is NULL or "", deactivate it + if (lang == NULL || *lang == '\0') return; - /* searches for a valid language array */ - for(n=0;_po2c_lang == NULL && _po2c_langs[n].lang != NULL;n++) - { - if(strcmp(lang, _po2c_langs[n].lang) == 0) { - _po2c_lang=_po2c_langs[n].msgs; - _po2c_charset=_po2c_langs[n].charset; + // searches for a valid language array + for (int i = 0; _po2c_lang == NULL && _po2c_langs[i].lang != NULL; ++i) { + if (strcmp(lang, _po2c_langs[i].lang) == 0) { + _po2c_lang = _po2c_langs[i].msgs; + _po2c_charset = _po2c_langs[i].charset; } } - /* try partial searches */ - for(n=0;_po2c_lang == NULL && _po2c_langs[n].lang != NULL;n++) - { - if(strncmp(lang, _po2c_langs[n].lang, 2) == 0) { - _po2c_lang=_po2c_langs[n].msgs; - _po2c_charset=_po2c_langs[n].charset; + // try partial searches + for (int i = 0; _po2c_lang == NULL && _po2c_langs[i].lang != NULL; ++i) { + if (strncmp(lang, _po2c_langs[i].lang, 2) == 0) { + _po2c_lang = _po2c_langs[i].msgs; + _po2c_charset = _po2c_langs[i].charset; } } - /* if found, count entries */ - if(_po2c_lang != NULL) - { - const struct _po2c_msg * m; - - for(m=_po2c_lang;m->msgid != -1;m++) - _po2c_lang_size++; + // if found, count entries + if (_po2c_lang != NULL) { + for (const PoMessageEntry *m = _po2c_lang; m->msgid != -1; ++m) + ++_po2c_lang_size; } } -const char * po2c_gettext(const char * msgid) -{ - const struct _po2c_msg * m; - int b, t, n, c; +const char *po2c_gettext(const char *msgid) { + // if no language is set or msgid is empty, return msgid as is + if (_po2c_lang == NULL || *msgid == '\0') + return msgid; - /* if no language is set or msgid is empty, return msgid as is */ - if(_po2c_lang == NULL || *msgid == '\0') - return(msgid); + // binary-search for the msgid + int leftIndex = 0; + int rightIndex = _po2c_lang_size - 1; - /* binary-search for the msgid */ - b=0; t=_po2c_lang_size - 1; + while (rightIndex >= leftIndex) { + const int midIndex = (leftIndex + rightIndex) / 2; + const struct PoMessageEntry * const m = &_po2c_lang[midIndex]; - while(t >= b) - { - n=(b + t) / 2; - m=&_po2c_lang[n]; - - c=strcmp(msgid, _po2c_msgids[m->msgid]); + const int compareResult = strcmp(msgid, _po2c_msgids[m->msgid]); - if(c == 0) - return(m->msgstr); + if (compareResult == 0) + return m->msgstr; + else if (compareResult < 0) + rightIndex = midIndex - 1; else - if(c < 0) - t=n - 1; - else - b=n + 1; + leftIndex = midIndex + 1; } - return(msgid); + return msgid; } -const char * po2c_getcharset(void) -{ +const char *po2c_getcharset(void) { if (_po2c_charset) return _po2c_charset; else return "ASCII"; } -int po2c_getnumlangs(void) -{ +int po2c_getnumlangs(void) { int n = 0; + while (_po2c_langs[n].lang) n++; return n; } -const char * po2c_getlang(int num) -{ +const char *po2c_getlang(int num) { return _po2c_langs[num].lang; } EOF -- cgit v1.2.3 From a5fb4fec2e71f252d5f7aa2b8d09165ce46fa3fa Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 24 Jun 2010 21:59:50 +0000 Subject: Some more cleanup of po2c's output. svn-id: r50240 --- tools/po2c | 62 +++++++++++++++++++++++++++++--------------------------------- 1 file changed, 29 insertions(+), 33 deletions(-) (limited to 'tools/po2c') diff --git a/tools/po2c b/tools/po2c index a2b006cd6b..ae55b28bfa 100755 --- a/tools/po2c +++ b/tools/po2c @@ -132,7 +132,7 @@ print "};\n\n"; foreach my $l (keys(%msgs)) { - print "static const PoMessageEntry _po2c_lang_${l}\[\] = {\n"; + print "static const PoMessageEntry _translation_${l}\[\] = {\n"; # get the translation table for the language $l my ($m) = $msgs{$l}; @@ -165,14 +165,14 @@ print "\tconst char *lang;\n"; print "\tconst char *charset;\n"; print "\tconst PoMessageEntry *msgs;\n"; print "};\n\n"; -print "const PoLangEntry _po2c_langs[] = {\n"; +print "const PoLangEntry _translations[] = {\n"; foreach my $l (keys(%msgs)) { $header = $msgs{$l}->{""}; $header =~ /charset=([^\\]+)/; $charset = $1; - print "\t{ \"" . $l . "\", \"" . $charset . "\", _po2c_lang_${l} },\n"; + print "\t{ \"" . $l . "\", \"" . $charset . "\", _translation_${l} },\n"; } print "\t{ NULL, NULL, NULL }\n};\n\n"; @@ -180,54 +180,54 @@ print "\t{ NULL, NULL, NULL }\n};\n\n"; print "// code\n"; print << 'EOF'; -static const struct PoMessageEntry *_po2c_lang = NULL; -static int _po2c_lang_size = 0; -static const char * _po2c_charset = NULL; +static const struct PoMessageEntry *_currentTranslation = NULL; +static int _currentTranslationMessageEntries = 0; +static const char *_currentTranslationCharset = NULL; void po2c_setlang(const char *lang) { - _po2c_lang = NULL; - _po2c_lang_size = 0; - _po2c_charset = NULL; + _currentTranslation = NULL; + _currentTranslationMessageEntries = 0; + _currentTranslationCharset = NULL; // if lang is NULL or "", deactivate it if (lang == NULL || *lang == '\0') return; // searches for a valid language array - for (int i = 0; _po2c_lang == NULL && _po2c_langs[i].lang != NULL; ++i) { - if (strcmp(lang, _po2c_langs[i].lang) == 0) { - _po2c_lang = _po2c_langs[i].msgs; - _po2c_charset = _po2c_langs[i].charset; + for (int i = 0; _currentTranslation == NULL && _translations[i].lang != NULL; ++i) { + if (strcmp(lang, _translations[i].lang) == 0) { + _currentTranslation = _translations[i].msgs; + _currentTranslationCharset = _translations[i].charset; } } // try partial searches - for (int i = 0; _po2c_lang == NULL && _po2c_langs[i].lang != NULL; ++i) { - if (strncmp(lang, _po2c_langs[i].lang, 2) == 0) { - _po2c_lang = _po2c_langs[i].msgs; - _po2c_charset = _po2c_langs[i].charset; + for (int i = 0; _currentTranslation == NULL && _translations[i].lang != NULL; ++i) { + if (strncmp(lang, _translations[i].lang, 2) == 0) { + _currentTranslation = _translations[i].msgs; + _currentTranslationCharset = _translations[i].charset; } } // if found, count entries - if (_po2c_lang != NULL) { - for (const PoMessageEntry *m = _po2c_lang; m->msgid != -1; ++m) - ++_po2c_lang_size; + if (_currentTranslation != NULL) { + for (const PoMessageEntry *m = _currentTranslation; m->msgid != -1; ++m) + ++_currentTranslationMessageEntries; } } const char *po2c_gettext(const char *msgid) { // if no language is set or msgid is empty, return msgid as is - if (_po2c_lang == NULL || *msgid == '\0') + if (_currentTranslation == NULL || *msgid == '\0') return msgid; // binary-search for the msgid int leftIndex = 0; - int rightIndex = _po2c_lang_size - 1; + int rightIndex = _currentTranslationMessageEntries - 1; while (rightIndex >= leftIndex) { const int midIndex = (leftIndex + rightIndex) / 2; - const struct PoMessageEntry * const m = &_po2c_lang[midIndex]; + const struct PoMessageEntry * const m = &_currentTranslation[midIndex]; const int compareResult = strcmp(msgid, _po2c_msgids[m->msgid]); @@ -243,23 +243,19 @@ const char *po2c_gettext(const char *msgid) { } const char *po2c_getcharset(void) { - if (_po2c_charset) - return _po2c_charset; + if (_currentTranslationCharset) + return _currentTranslationCharset; else return "ASCII"; } int po2c_getnumlangs(void) { - int n = 0; - - while (_po2c_langs[n].lang) - n++; - - return n; + return ARRAYSIZE(_translations) - 1; } -const char *po2c_getlang(int num) { - return _po2c_langs[num].lang; +const char *po2c_getlang(const int num) { + assert(num < ARRAYSIZE(_translations)); + return _translations[num].lang; } EOF -- cgit v1.2.3 From 968e10795ffdf2e17a7ca678ca5e303b0d265795 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 24 Jun 2010 22:00:20 +0000 Subject: Do not include any headers from common/messages.cpp, since that file might be included into an namespace. svn-id: r50241 --- tools/po2c | 2 -- 1 file changed, 2 deletions(-) (limited to 'tools/po2c') diff --git a/tools/po2c b/tools/po2c index ae55b28bfa..dddd4541c0 100755 --- a/tools/po2c +++ b/tools/po2c @@ -109,8 +109,6 @@ for(my $n = 0;$n < scalar(@msgids);$n++) # stage 3: dump as C++ code print "// generated by po2c $VERSION - Do not modify\n\n"; -print "#include \n"; -print "#include \n\n"; # dump first the msgid array print "static const char * const _po2c_msgids[] = {\n"; -- cgit v1.2.3 From 17a96b3bd2f0c24fdf581aac8cffabb575fd8c82 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 24 Jun 2010 22:00:45 +0000 Subject: Yet another slight variable renaming to match our conventions. svn-id: r50242 --- tools/po2c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'tools/po2c') diff --git a/tools/po2c b/tools/po2c index dddd4541c0..9dbc5e0fb7 100755 --- a/tools/po2c +++ b/tools/po2c @@ -111,7 +111,7 @@ for(my $n = 0;$n < scalar(@msgids);$n++) print "// generated by po2c $VERSION - Do not modify\n\n"; # dump first the msgid array -print "static const char * const _po2c_msgids[] = {\n"; +print "static const char * const _messageIds[] = {\n"; for(my $n = 0;$n < scalar(@msgids);$n++) { @@ -178,13 +178,13 @@ print "\t{ NULL, NULL, NULL }\n};\n\n"; print "// code\n"; print << 'EOF'; -static const struct PoMessageEntry *_currentTranslation = NULL; -static int _currentTranslationMessageEntries = 0; +static const PoMessageEntry *_currentTranslation = NULL; +static int _currentTranslationMessageEntryCount = 0; static const char *_currentTranslationCharset = NULL; void po2c_setlang(const char *lang) { _currentTranslation = NULL; - _currentTranslationMessageEntries = 0; + _currentTranslationMessageEntryCount = 0; _currentTranslationCharset = NULL; // if lang is NULL or "", deactivate it @@ -210,7 +210,7 @@ void po2c_setlang(const char *lang) { // if found, count entries if (_currentTranslation != NULL) { for (const PoMessageEntry *m = _currentTranslation; m->msgid != -1; ++m) - ++_currentTranslationMessageEntries; + ++_currentTranslationMessageEntryCount; } } @@ -221,13 +221,13 @@ const char *po2c_gettext(const char *msgid) { // binary-search for the msgid int leftIndex = 0; - int rightIndex = _currentTranslationMessageEntries - 1; + int rightIndex = _currentTranslationMessageEntryCount - 1; while (rightIndex >= leftIndex) { const int midIndex = (leftIndex + rightIndex) / 2; - const struct PoMessageEntry * const m = &_currentTranslation[midIndex]; + const PoMessageEntry * const m = &_currentTranslation[midIndex]; - const int compareResult = strcmp(msgid, _po2c_msgids[m->msgid]); + const int compareResult = strcmp(msgid, _messageIds[m->msgid]); if (compareResult == 0) return m->msgstr; -- cgit v1.2.3 From 1c6b339bbc2f9ee0624f7777e5950417a66a3286 Mon Sep 17 00:00:00 2001 From: Thierry Crozat Date: Sat, 31 Jul 2010 15:46:43 +0000 Subject: i18n: use user friendly language names in GUI The GUI now uses the content of the Language field from the po file header if it is present and not empty for the language selection PopupWidget. If not present it uses the file name as before (e.g. ru_RU). Also update all the translation template and all the translation files. svn-id: r51542 --- tools/po2c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'tools/po2c') diff --git a/tools/po2c b/tools/po2c index 9dbc5e0fb7..10e15338c7 100755 --- a/tools/po2c +++ b/tools/po2c @@ -161,19 +161,29 @@ foreach my $l (keys(%msgs)) print "struct PoLangEntry {\n"; print "\tconst char *lang;\n"; print "\tconst char *charset;\n"; +print "\tconst char *langname;\n"; print "\tconst PoMessageEntry *msgs;\n"; print "};\n\n"; print "const PoLangEntry _translations[] = {\n"; foreach my $l (keys(%msgs)) { + # charset $header = $msgs{$l}->{""}; $header =~ /charset=([^\\]+)/; $charset = $1; - print "\t{ \"" . $l . "\", \"" . $charset . "\", _translation_${l} },\n"; + # user readable language name + $lang = "NULL"; + $header = $msgs{$l}->{""}; + $header =~ /Language:[\s]*([^\\]*)/; + unless ($1 eq "") + { + $lang = "\"" . $1 . "\""; + } + print "\t{ \"" . $l . "\", \"" . $charset . "\", " . $lang . ", _translation_${l} },\n"; } -print "\t{ NULL, NULL, NULL }\n};\n\n"; +print "\t{ NULL, NULL, NULL, NULL }\n};\n\n"; print "// code\n"; print << 'EOF'; @@ -255,6 +265,13 @@ const char *po2c_getlang(const int num) { assert(num < ARRAYSIZE(_translations)); return _translations[num].lang; } + +const char *po2c_getlangname(const int num) { + assert(num < ARRAYSIZE(_translations)); + if (_translations[num].langname != NULL) + return _translations[num].langname; + return _translations[num].lang; +} EOF exit 0; -- cgit v1.2.3