~ubuntu-core-dev/update-notifier/ubuntu

« back to all changes in this revision

Viewing changes to src/hooks.c

  • Committer: mvo
  • Date: 2005-02-03 12:45:41 UTC
  • Revision ID: gustavo@niemeyer.net-20050203124541-66b00f59dd8cee24
* src/rfc822.h: added a comment explaining about the memory use
* src/hooks.c: basic i18n support added, needs more love

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#include "assert.h"
5
5
#include <glib.h>
6
6
#include <glib/gstdio.h>
 
7
#include <locale.h>
7
8
 
8
9
/* relative to the home dir */
9
10
#define HOOKS_SEEN ".update-notifier/hooks_seen"
77
78
}
78
79
 
79
80
 
 
81
/* get the language code in a static allocated buffer
 
82
 * short_form: only return the languagecode if true, otherwise
 
83
 *             languagecode_countrycode
 
84
 */
 
85
char* get_lang_code(gboolean short_form)
 
86
{
 
87
   /* make own private copy */
 
88
   static gchar locale[51];
 
89
   strncpy(locale, setlocale(LC_MESSAGES, NULL), 50);
 
90
   
 
91
   // FIXME: we need to be more inteligent here
 
92
   // _and_ we probably want to look into the "LANGUAGE" enviroment too
 
93
   if(short_form) {
 
94
      locale[2] = 0;
 
95
      return locale;
 
96
   } else {
 
97
      locale[5] = 0;
 
98
      return locale;
 
99
   }
 
100
}
 
101
 
 
102
/*
 
103
 * get a i18n field of the rfc822 header
 
104
 * Return Value: a pointer that must not be freed (part of the rfc822 struct)
 
105
 */
 
106
char *hook_file_lookup_i18n(struct rfc822_header *rfc822, char *field)
 
107
{
 
108
   gchar *s, *entry;
 
109
 
 
110
   /* try $field-$languagecode_$countrycode first */
 
111
   s = g_strdup_printf("%s-%s", field, get_lang_code(FALSE));
 
112
   entry = rfc822_header_lookup(rfc822, s);
 
113
   //g_print("Looking for: %s ; found: %s\n",s,entry);
 
114
   g_free(s);
 
115
   if(entry != NULL)
 
116
      return entry;
 
117
 
 
118
   /* try $field-$languagecode next */
 
119
   s = g_strdup_printf("%s-%s", field, get_lang_code(TRUE));
 
120
   //g_print("Looking for: %s ; found: %s\n",s,entry);
 
121
   entry = rfc822_header_lookup(rfc822, s);
 
122
   g_free(s);
 
123
   if(entry != NULL)
 
124
      return entry;
 
125
 
 
126
   /* if everything else fails ... return untranslated */
 
127
   return rfc822_header_lookup(rfc822, field);
 
128
}
 
129
 
 
130
/*
 
131
 * show the given hook file
 
132
 */
80
133
void show_one_hook(TrayApplet *ta, gchar *hook_file)
81
134
{
82
135
   HookDialog *hook_dialog = (HookDialog *)ta->user_data;
112
165
      gtk_widget_hide(button_run);
113
166
   }
114
167
 
115
 
   char *name = rfc822_header_lookup(rfc822, "Name");
116
 
   char *description = rfc822_header_lookup(rfc822, "Description");
 
168
   char *name = hook_file_lookup_i18n(rfc822, "Name");
 
169
   char *description = hook_file_lookup_i18n(rfc822, "Description");
117
170
   char *s = g_strdup_printf("%s\n\n%s\n",name, description);
118
171
   gtk_text_buffer_set_text(buf, s, -1);
119
172