asclock (2.0.12-18) l10n.diff

Summary

 config.c  |   88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 config.h  |    2 +
 configure |    3 +-
 3 files changed, 88 insertions(+), 5 deletions(-)

    
download this patch

Patch contents

# Description: This patch adds l10n runtime support
#  Initial patch (C) 2008 by Arne, later extended by Helge to cover
#  all cases (2009)
# Author: Arne Kreutzmann <mail@arne-kreutzmann.de>
# Author: Helge Kreutzmann <debian@helgefjell.de>
# Last-Update: 2010-02-27

Index: asclock-xlib/config.c
===================================================================
--- asclock-xlib.orig/config.c	2010-02-27 13:27:23.000000000 +0100
+++ asclock-xlib/config.c	2010-02-27 13:29:50.000000000 +0100
@@ -1,4 +1,6 @@
 #include "asclock.h"
+#include "config.h"
+#include "default.h"
 
 extern char *Geometry;
 
@@ -96,10 +98,38 @@
   return FALSE;
 }
 
+char* getLanguageExtension()
+{
+	char* lang;
+
+	if((lang = getenv("LC_ALL")) == NULL)
+	{
+		if((lang = getenv("LC_MESSAGES")) == NULL)
+               {
+			if((lang = getenv("LANG")) == NULL)
+			{
+				lang="C";
+			}
+		}
+	}
+
+	char** local = supported_locales;
+	while(*local)
+	{
+		if(strncasecmp(*local, lang, 2) == 0)
+			return *local;
+		local++;
+	}
+
+	fprintf(stderr, "Locale %s not supported\n", lang);
+	return NULL;
+}
+
 int loadTheme(char *themesdir)
 {
   FILE *f;
   char filename[MAX_PATH_LEN];
+  char* langExt = "";
 
   char token[64];
   int type;
@@ -162,14 +192,26 @@
 
   fclose(f);
 
+  langExt = getLanguageExtension();
+
   strcpy(clock_xpm_fn, themesdir);
   strcat(clock_xpm_fn, "/clock.xpm");
 
-  strcpy(month_xpm_fn, themesdir);
-  strcat(month_xpm_fn, "/month.xpm");
+  if (langExt==NULL)
+  {
+	strcpy(month_xpm_fn, themesdir);
+	strcat(month_xpm_fn, "/month.xpm");
 
-  strcpy(weekday_xpm_fn, themesdir);
-  strcat(weekday_xpm_fn, "/weekday.xpm");
+	strcpy(weekday_xpm_fn, themesdir);
+	strcat(weekday_xpm_fn, "/weekday.xpm");
+  }
+  else
+  {
+	sprintf(month_xpm_fn,   "%s%s%s%s", themesdir, "/month.",   langExt, ".xpm");
+	//printf("Opening:%s\n",month_xpm_fn);
+	sprintf(weekday_xpm_fn, "%s%s%s%s", themesdir, "/weekday.", langExt, ".xpm");
+	//printf("Opening:%s\n",weekday_xpm_fn);
+  }
 
   strcpy(date_xpm_fn, themesdir);
   strcat(date_xpm_fn, "/date.xpm");
@@ -197,9 +239,11 @@
   int i;
   char themesdir[MAX_PATH_LEN];
   char *ProgName = argv[0];
+  int themeloaded;
 
   itblinks=TRUE;
   itdocks=FALSE;
+  themeloaded=FALSE;
   for(i=1;i<argc;i++) {
     char *arg= argv[i];
 
@@ -223,6 +267,7 @@
       case 'n':
 	itblinks = FALSE;
 	continue;
+      case 'i':
       case 'd':
 	itdocks = TRUE;
 	continue;
@@ -232,6 +277,19 @@
       case '2':
         showampm=0;
         continue;
+      case 's':
+        if(! findTheme("shaped", themesdir) )
+          {
+            fprintf(stderr, "Could not find theme shaped\n\n");
+            exit(-1);
+          }
+
+        if(!loadTheme(themesdir))
+          exit(-1);
+
+	itdocks = TRUE;
+	themeloaded = TRUE;
+        continue;
 			case 'p':
 				if(++i >=argc) usage(ProgName);
 				Geometry = argv[i];
@@ -248,6 +306,7 @@
         if(!loadTheme(themesdir))
           exit(-1);
 
+	themeloaded = TRUE;
         continue;
       case 'e':
         if(++i >=argc) usage(ProgName);
@@ -258,4 +317,25 @@
       }
     }
   }
+
+  if (! themeloaded)
+  {
+      // if the default theme in the file system (i.e. asclock-themes is
+      // present) then that theme is loaded (probably in an l10n version)
+
+      //fprintf(stderr, "No theme loaded");
+
+      if(! findTheme(deftheme, themesdir) )
+      {
+	fprintf(stderr, "Could not find theme %s in path\n\n", deftheme);
+	fprintf(stderr, "using built in (and dropping i18n)\n\n");
+      }
+      else
+      {
+       if(!loadTheme(themesdir))
+         exit(-1);
+      }
+
+      // else use built in theme (only availabe in English)
+  }
 }
Index: asclock-xlib/config.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ asclock-xlib/config.h	2010-02-27 13:27:26.000000000 +0100
@@ -0,0 +1,2 @@
+char *supported_locales[]={ "br", "cs", "de", "da", "en", "es", "fr", "he", "hu", "id", "ja", "nb", "it", "nl", "pt", "ru", "sl", "sv", "uk", NULL };
+
Index: asclock-xlib/configure
===================================================================
--- asclock-xlib.orig/configure	2010-02-27 13:27:24.000000000 +0100
+++ asclock-xlib/configure	2010-02-27 13:27:26.000000000 +0100
@@ -27,7 +27,7 @@
     if ! test -f themes/$line/classic
     then ln -s themes/$line default_theme
          xmkmf
-         rm -f *.o *~ asclock core
+         rm -f *.o *~ asclock core default.h
          exit 0
     else
 	 mkdir default_theme
@@ -39,6 +39,7 @@
 	 ln -s ../themes/$line/minute.xpm default_theme/minute.xpm
 	 ln -s ../themes/$line/second.xpm default_theme/second.xpm
          ln -s ../themes/$line/beats.xpm  default_theme/beats.xpm
+	 echo "static char *deftheme = \"$line\" ;" > default.h
 	 exec ./classic.configure
     fi
   fi