Репозиторий Sisyphus
Последнее обновление: 1 октября 2023 | Пакетов: 18631 | Посещений: 37046160
en ru br
Репозитории ALT
S:2.1.41-alt23
5.1: 2.1.41-alt9
4.1: 2.1.41-alt3.M41.1
4.0: 2.1.35-alt5
3.0: 2.1.25-alt3
+backports:2.1.29-alt4.0.M30
www.altlinux.org/Changes

Группа :: Система/Основа
Пакет: menu

 Главная   Изменения   Спек   Патчи   Sources   Загрузить   Gear   Bugs and FR  Repocop 

Патч: menu-2.1.14-alt-translate.patch
Скачать


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.41.old/install-menu/functions.cc	2004-05-17 20:07:27 +0400
+++ menu-2.1.41/install-menu/functions.cc	2004-06-18 19:03:33 +0400
@@ -30,12 +30,14 @@
 #include <iostream>
 #include <cstdio>
 #include <unistd.h>
+#include <iconv.h>
 
 using std::ostream;
 using std::vector;
 using std::string;
 using std::map;
 using std::cerr;
+using std::endl;
 
 bool empty_string(const string &s)
 {
@@ -45,6 +47,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<cat_str *> &,
@@ -465,7 +525,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<cat_str *> &args,
+				 map<string, string> &menuentry){
+  string lang=args[0]->soutput(menuentry);
+  string text=args[1]->soutput(menuentry);
+  return o<<do_translate(text,lang,false);
+}
+
+/*
+ * this method encode input in locale encoding
+ */
+ostream &encode::output(ostream &o, vector<cat_str *> &args,
+			     map<string, string> &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<<text;
+  
+  const char *start = text.c_str();
+
+  size_t srclen = strlen(start);
+  char buf[srclen * 4 + 1];
+  size_t destlen = sizeof(buf) - 1;
+  char *tmp = buf;
+
+  if ( iconv(iconvcontext, (char**)&start, &srclen, &tmp, &destlen) == (size_t)-1 )
+    cerr << "iconv from " << from << " to " << to << " failed for: " << text << endl;
+
+  iconv_close(iconvcontext);
+  *tmp='\0';
+  
+  /* free memory */
+  return o << buf;
 }
 
 }
diff -uNrp menu-2.1.14.old/install-menu/functions.h menu-2.1.14/install-menu/functions.h
--- menu-2.1.14.old/install-menu/functions.h	2004-05-17 20:07:27 +0400
+++ menu-2.1.14/install-menu/functions.h	2004-06-18 19:03:33 +0400
@@ -295,6 +295,18 @@ namespace functions {
     const char * getName() const { return "translate"; }
   };
 
+  struct encode_translate:public funcN<3>{
+    std::ostream &output(std::ostream &o, std::vector<cat_str *> &,
+		  std::map<std::string, std::string> &);
+    const char * getName() const {return "encode_translate";}
+  };
+
+  struct encode:public funcN<3>{
+    std::ostream &output(std::ostream &o, std::vector<cat_str *> &,
+		  std::map<std::string, std::string> &);
+    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);
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin