diff -uNrp menu-2.1.14.old/examples/menu.h menu-2.1.14/examples/menu.h --- menu-2.1.14.old/examples/menu.h 2004-06-18 19:02:31 +0400 +++ menu-2.1.14/examples/menu.h 2004-06-18 19:03:33 +0400 @@ -6,6 +6,11 @@ #This file is part of the menu package (version 1.4 and higher). #For more information, see /usr/share/doc/menu/html +# I18n and l10n support. the lang.h file is generated at install +# time to be in sync with /etc/sysconfig/i18n + +!include lang.h + #If you prefer long titles, change the definition below accordingly. #(this will currently not give you many long titles, as most menu entries #still don't provide long titles. In those cases, the defintion below @@ -62,7 +67,7 @@ sort=tolower(title()) #sort=ifelse($command, "1", "0" ) ":" title() #Activate menu section translations: -outputlanguage="LOCALE" +#outputlanguage="LOCALE" #menu-methods need to set 'outputencoding' before translations are really #enabled. diff -uNrp menu-2.1.14.old/install-menu/functions.cc menu-2.1.14/install-menu/functions.cc --- menu-2.1.14.old/install-menu/functions.cc 2004-05-17 20:07:27 +0400 +++ menu-2.1.14/install-menu/functions.cc 2004-06-18 19:03:33 +0400 @@ -36,6 +36,7 @@ using std::vector; using std::string; using std::map; using std::cerr; +using std::endl; bool empty_string(const string &s) { @@ -45,6 +46,64 @@ bool empty_string(const string &s) return false; } +/** + * this method translate text + */ +static string +do_translate( string text, string locale, bool need_recode ) +{ + const char *from = text.c_str(); + char *lang = (char *) locale.c_str(); + const char *utf8 = "UTF-8"; + const char *charset; + char *p = strrchr( lang, '.' ); + + if ( !p ) + charset = utf8; + else + { + *p = '\0'; + charset = p + 1; + } + string tmp_locale = lang; + tmp_locale += "."; + tmp_locale += utf8; + + setlocale( LC_ALL, tmp_locale.c_str() ); + + const char *to = dgettext( "menu-messages", from ); + + if ( need_recode && strcmp( charset, utf8 ) ) + { + iconv_t id = iconv_open( charset, utf8 ); + if ( (iconv_t) -1 == id ) + { + cerr << "iconv_open from " << utf8 << " to " << charset << " failed: " << strerror(errno) << endl; + return ""; + } + + const char *in = to; + size_t in_len = strlen(in); + size_t out_len = in_len; + char buf[ out_len + 1 ]; + char *out = buf; + + memset(buf, 0, sizeof buf); + if ( iconv( id, (char **)(&in), &in_len, &out, &out_len ) == (size_t)-1 ) + { + iconv_close( id ); + cerr << "iconv from " << utf8 << " to " << charset << " failed for: " << to << + " (" << strerror(errno) << ')' << endl; + return ""; + } + + iconv_close( id ); + return buf; + } else + return to; +} + + namespace functions { ostream &prefix::output(ostream &o, vector &, @@ -465,7 +524,49 @@ ostream &translate::output(ostream &o, v string lang=args[0]->soutput(menuentry); string text=args[1]->soutput(menuentry); - return o << ldgettext(lang.c_str(), "menu-sections", text.c_str()); + return o << do_translate(text,lang,true); +} + +/* + * this method return translation in UTF-8 (needed for KDE 2.0 and above) + */ +ostream &encode_translate::output(ostream &o, vector &args, + map &menuentry){ + string lang=args[0]->soutput(menuentry); + string text=args[1]->soutput(menuentry); + return o< &args, + map &menuentry){ + string text=args[0]->soutput(menuentry); + string from=args[1]->soutput(menuentry); + string to=args[2]->soutput(menuentry); + + /* convert to dest charset*/ + iconv_t iconvcontext; + if ((iconvcontext = iconv_open (to.c_str(), + from.c_str())) == (iconv_t)-1) + return o<{ + std::ostream &output(std::ostream &o, std::vector &, + std::map &); + const char * getName() const {return "encode_translate";} + }; + + struct encode:public funcN<3>{ + std::ostream &output(std::ostream &o, std::vector &, + std::map &); + const char * getName() const {return "encode";} + }; + } #endif diff -uNrp menu-2.1.14.old/install-menu/install-menu.cc menu-2.1.14/install-menu/install-menu.cc --- menu-2.1.14.old/install-menu/install-menu.cc 2004-06-18 19:02:31 +0400 +++ menu-2.1.14/install-menu/install-menu.cc 2004-06-18 19:03:33 +0400 @@ -183,6 +183,8 @@ void add_functions() store_func(new functions::preoutput); store_func(new functions::cwd); store_func(new functions::translate); + store_func(new functions::encode_translate); + store_func(new functions::encode); } cat_str *get_eq_cat_str(parsestream &i) @@ -895,9 +897,10 @@ int main(int argc, char **argv) std::string script_name; parsestream *ps = 0, *psscript = 0; + unsetenv ("LANGUAGE"); + unsetenv ("LC_MESSAGES"); setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); - bind_textdomain_codeset("menu-sections", menuencoding); textdomain(PACKAGE); if (!getuid()) { diff -uNrp menu-2.1.14.old/update-menus/update-menus.cc menu-2.1.14/update-menus/update-menus.cc --- menu-2.1.14.old/update-menus/update-menus.cc 2004-06-18 19:02:31 +0400 +++ menu-2.1.14/update-menus/update-menus.cc 2004-06-18 19:03:44 +0400 @@ -990,6 +991,8 @@ int main (int argc, char **argv) exit(0); } + unsetenv ("LANGUAGE"); + unsetenv ("LC_MESSAGES"); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE);