Added missing release notes to Changes file.
[rox-filer.git] / ROX-Filer / src / i18n.c
blob461afdfdeffd6f54475a059f06671940753138fd
1 /*
2 * ROX-Filer, filer for the ROX desktop project
3 * Copyright (C) 2006, Thomas Leonard and others (see changelog for details).
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "config.h"
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <errno.h>
25 #include <string.h>
26 #ifdef HAVE_LIBINTL_H
27 #include <libintl.h>
28 #endif
30 #include "global.h"
32 #include "support.h"
33 #include "choices.h"
34 #include "options.h"
35 #include "i18n.h"
36 #include "gui_support.h"
37 #include "main.h"
39 #define MESSAGE _("Note that you must save your choices " \
40 "and restart the filer for the new language " \
41 "setting to take full effect.")
43 /* Two/five-char country_territory code, or NULL */
44 char *current_lang = NULL;
46 /****************************************************************
47 * EXTERNAL INTERFACE *
48 ****************************************************************/
51 /* Set things up for internationalisation */
52 void i18n_init(void)
54 const char *lang;
56 gtk_set_locale();
58 #ifdef HAVE_LIBINTL_H
59 gchar *path = g_strdup_printf("%s/Messages", app_dir);
60 bindtextdomain("ROX-Filer", path);
61 bind_textdomain_codeset("ROX-Filer", "UTF-8");
62 g_free(path);
63 #endif
65 /* This is a hang-over from when we did translations ourselves.
66 * Maybe we can get this info from the gettext library?
68 lang = getenv("LANG");
69 if (lang)
71 const char *end;
73 /* Extract the language code from the locale name.
74 * language[_territory][.codeset][@modifier]
77 end = strchr(lang, '.');
78 if (!end)
79 end = strchr(lang, '@');
80 if (end)
81 current_lang = g_strndup(lang, end - lang);
82 else
83 current_lang = g_strdup(lang);
87 /* These two stolen from dia :-).
88 * Slight modification though: '>' means 'same as above' so that
89 * if a translation is missing it doesn't muck up the whole menu structure!
91 GtkItemFactoryEntry *translate_entries(GtkItemFactoryEntry *entries, gint n)
93 guchar *first = NULL, *second = NULL; /* Previous menu, submenu */
94 gint i;
95 GtkItemFactoryEntry *ret;
97 ret = g_malloc(sizeof(GtkItemFactoryEntry) * n);
98 for (i = 0; i < n; i++)
100 const gchar *from = entries[i].path;
101 gchar *trans, *slash;
102 int indent;
104 if (from[0] == '>')
106 if (from[1] == '>')
107 indent = 2;
108 else
109 indent = 1;
111 else
112 indent = 0;
114 if (from[indent])
115 from = _(from + indent);
116 else
117 from = "";
119 if (indent == 0)
120 trans = g_strdup_printf("/%s", from);
121 else if (indent == 1)
122 trans = g_strdup_printf("/%s/%s", first, from);
123 else
124 trans = g_strdup_printf("/%s/%s/%s",
125 first, second, from);
127 ret[i].path = trans;
129 g_free(first);
130 null_g_free(&second);
132 trans++;
133 slash = strchr(trans, '/');
134 if (slash)
136 first = g_strndup(trans, slash - trans);
137 trans = slash + 1;
139 slash = strchr(trans, '/');
140 if (slash)
141 second = g_strndup(trans, slash - trans);
142 else
143 second = g_strdup(trans);
145 else
146 first = g_strdup(trans);
148 /* accelerator and item_type are not duped, only referenced */
149 ret[i].accelerator = entries[i].accelerator;
150 ret[i].callback = entries[i].callback;
151 ret[i].callback_action = entries[i].callback_action;
152 ret[i].item_type = entries[i].item_type;
153 ret[i].extra_data = entries[i].extra_data;
156 g_free(first);
157 g_free(second);
159 return ret;
162 void free_translated_entries(GtkItemFactoryEntry *entries, gint n)
164 gint i;
166 for (i=0; i<n; i++)
167 g_free(entries[i].path);
168 g_free(entries);