Commit 3b9fa093 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo Committed by Linus Torvalds

[PATCH] Kconfig i18n support

This patch adds i18n support for make *config, allowing users to have the
config process in their own language.

No printk was harmed in the process, don't worry, so all the bug reports,
kernel messages, etc, remain in english, just the user tools to configure
the kernel are internationalized.

Users not interested in translations can just unset the related LANG,
LC_ALL, etc env variables and have the config process in plain english,
something like:

LANG= make menuconfig

is enough for having the whole config process in english. Or just don't
install any translation file.

Translations for brazilian portuguese are being done by a team of
volunteers at:

http://www.visionflex.inf.br/kernel_ptbr/pmwiki.php/Principal/Traducoes

To start the translation process:

  make update-po-config

  This will generate the pot template named scripts/kconfig/linux.pot,
  copy it to, say, ~/es.po, to start the translation for spanish.

To test your translation, as root issue this command:

  msgfmt -o /usr/share/locale/es/LC_MESSAGES/linux.mo ~/es.po

  Replace "es" with your language code.

  Then execute, for instance:

  make menuconfig

The current patch doesn't use any optimization to reduce the size of the
generated .mo file, it is possible to use the config option as a key, but
this doesn't prevent the current patch from being used or the translations
done under the current scheme to be in any way lost if we chose to do any
kind of keying.

Thanks to Fabricio Vaccari for starting the pt_BR (brazilian portuguese)
translation effort, Thiago Maciera for helping me with the gconf.cc (QT
frontent) i18n coding and to all the volunteers that are already working on
the first translation, to pt_BR.

I left the question on whether to ship the translations with the stock kernel
sources to be discussed here, please share your suggestions.
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@conectiva.com.br>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
parent f403b7f4
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Kernel configuration targets # Kernel configuration targets
# These targets are used from top-level makefile # These targets are used from top-level makefile
.PHONY: oldconfig xconfig gconfig menuconfig config silentoldconfig .PHONY: oldconfig xconfig gconfig menuconfig config silentoldconfig update-po-config
xconfig: $(obj)/qconf xconfig: $(obj)/qconf
$< arch/$(ARCH)/Kconfig $< arch/$(ARCH)/Kconfig
...@@ -23,6 +23,13 @@ oldconfig: $(obj)/conf ...@@ -23,6 +23,13 @@ oldconfig: $(obj)/conf
silentoldconfig: $(obj)/conf silentoldconfig: $(obj)/conf
$< -s arch/$(ARCH)/Kconfig $< -s arch/$(ARCH)/Kconfig
update-po-config: $(obj)/kxgettext
xgettext --default-domain=linux \
--add-comments --keyword=_ --keyword=N_ \
--files-from=scripts/kconfig/POTFILES.in \
-o scripts/kconfig/linux.pot
scripts/kconfig/kxgettext arch/$(ARCH)/Kconfig >> scripts/kconfig/linux.pot
.PHONY: randconfig allyesconfig allnoconfig allmodconfig defconfig .PHONY: randconfig allyesconfig allnoconfig allmodconfig defconfig
randconfig: $(obj)/conf randconfig: $(obj)/conf
...@@ -72,9 +79,10 @@ help: ...@@ -72,9 +79,10 @@ help:
# Based on GTK which needs to be installed to compile it # Based on GTK which needs to be installed to compile it
# object files used by all kconfig flavours # object files used by all kconfig flavours
hostprogs-y := conf mconf qconf gconf hostprogs-y := conf mconf qconf gconf kxgettext
conf-objs := conf.o zconf.tab.o conf-objs := conf.o zconf.tab.o
mconf-objs := mconf.o zconf.tab.o mconf-objs := mconf.o zconf.tab.o
kxgettext-objs := kxgettext.o zconf.tab.o
ifeq ($(MAKECMDGOALS),xconfig) ifeq ($(MAKECMDGOALS),xconfig)
qconf-target := 1 qconf-target := 1
...@@ -107,7 +115,7 @@ HOSTLOADLIBES_gconf = `pkg-config gtk+-2.0 gmodule-2.0 libglade-2.0 --libs` ...@@ -107,7 +115,7 @@ HOSTLOADLIBES_gconf = `pkg-config gtk+-2.0 gmodule-2.0 libglade-2.0 --libs`
HOSTCFLAGS_gconf.o = `pkg-config gtk+-2.0 gmodule-2.0 libglade-2.0 --cflags` \ HOSTCFLAGS_gconf.o = `pkg-config gtk+-2.0 gmodule-2.0 libglade-2.0 --cflags` \
-D LKC_DIRECT_LINK -D LKC_DIRECT_LINK
$(obj)/conf.o $(obj)/mconf.o $(obj)/qconf.o $(obj)/gconf.o: $(obj)/zconf.tab.h $(obj)/conf.o $(obj)/mconf.o $(obj)/qconf.o $(obj)/gconf.o $(obj)/kxgettext: $(obj)/zconf.tab.h
$(obj)/zconf.tab.h: $(src)/zconf.tab.h_shipped $(obj)/zconf.tab.h: $(src)/zconf.tab.h_shipped
$(obj)/zconf.tab.c: $(src)/zconf.tab.c_shipped $(obj)/zconf.tab.c: $(src)/zconf.tab.c_shipped
......
scripts/kconfig/mconf.c
scripts/kconfig/conf.c
scripts/kconfig/confdata.c
scripts/kconfig/gconf.c
scripts/kconfig/qconf.cc
...@@ -34,7 +34,7 @@ static int conf_cnt; ...@@ -34,7 +34,7 @@ static int conf_cnt;
static signed char line[128]; static signed char line[128];
static struct menu *rootEntry; static struct menu *rootEntry;
static char nohelp_text[] = "Sorry, no help available for this option yet.\n"; static char nohelp_text[] = N_("Sorry, no help available for this option yet.\n");
static void strip(signed char *str) static void strip(signed char *str)
{ {
...@@ -56,9 +56,9 @@ static void strip(signed char *str) ...@@ -56,9 +56,9 @@ static void strip(signed char *str)
static void check_stdin(void) static void check_stdin(void)
{ {
if (!valid_stdin && input_mode == ask_silent) { if (!valid_stdin && input_mode == ask_silent) {
printf("aborted!\n\n"); printf(_("aborted!\n\n"));
printf("Console input/output is redirected. "); printf(_("Console input/output is redirected. "));
printf("Run 'make oldconfig' to update configuration.\n\n"); printf(_("Run 'make oldconfig' to update configuration.\n\n"));
exit(1); exit(1);
} }
} }
...@@ -470,7 +470,7 @@ static void check_conf(struct menu *menu) ...@@ -470,7 +470,7 @@ static void check_conf(struct menu *menu)
if (sym) { if (sym) {
if (sym_is_changable(sym) && !sym_has_value(sym)) { if (sym_is_changable(sym) && !sym_has_value(sym)) {
if (!conf_cnt++) if (!conf_cnt++)
printf("*\n* Restart config...\n*\n"); printf(_("*\n* Restart config...\n*\n"));
rootEntry = menu_get_parent_menu(menu); rootEntry = menu_get_parent_menu(menu);
conf(rootEntry); conf(rootEntry);
} }
...@@ -504,7 +504,7 @@ int main(int ac, char **av) ...@@ -504,7 +504,7 @@ int main(int ac, char **av)
input_mode = set_default; input_mode = set_default;
defconfig_file = av[i++]; defconfig_file = av[i++];
if (!defconfig_file) { if (!defconfig_file) {
printf("%s: No default config file specified\n", printf(_("%s: No default config file specified\n"),
av[0]); av[0]);
exit(1); exit(1);
} }
...@@ -530,7 +530,7 @@ int main(int ac, char **av) ...@@ -530,7 +530,7 @@ int main(int ac, char **av)
} }
name = av[i]; name = av[i];
if (!name) { if (!name) {
printf("%s: Kconfig file missing\n", av[0]); printf(_("%s: Kconfig file missing\n"), av[0]);
} }
conf_parse(name); conf_parse(name);
//zconfdump(stdout); //zconfdump(stdout);
...@@ -547,12 +547,12 @@ int main(int ac, char **av) ...@@ -547,12 +547,12 @@ int main(int ac, char **av)
break; break;
case ask_silent: case ask_silent:
if (stat(".config", &tmpstat)) { if (stat(".config", &tmpstat)) {
printf("***\n" printf(_("***\n"
"*** You have not yet configured your kernel!\n" "*** You have not yet configured your kernel!\n"
"***\n" "***\n"
"*** Please run some configurator (e.g. \"make oldconfig\" or\n" "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
"*** \"make menuconfig\" or \"make xconfig\").\n" "*** \"make menuconfig\" or \"make xconfig\").\n"
"***\n"); "***\n"));
exit(1); exit(1);
} }
case ask_all: case ask_all:
...@@ -576,7 +576,7 @@ int main(int ac, char **av) ...@@ -576,7 +576,7 @@ int main(int ac, char **av)
check_conf(&rootmenu); check_conf(&rootmenu);
} while (conf_cnt); } while (conf_cnt);
if (conf_write(NULL)) { if (conf_write(NULL)) {
fprintf(stderr, "\n*** Error during writing of the kernel configuration.\n\n"); fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
return 1; return 1;
} }
return 0; return 0;
......
...@@ -88,9 +88,9 @@ int conf_read(const char *name) ...@@ -88,9 +88,9 @@ int conf_read(const char *name)
name = conf_expand_value(name); name = conf_expand_value(name);
in = zconf_fopen(name); in = zconf_fopen(name);
if (in) { if (in) {
printf("#\n" printf(_("#\n"
"# using defaults found in %s\n" "# using defaults found in %s\n"
"#\n", name); "#\n"), name);
break; break;
} }
} }
...@@ -312,11 +312,11 @@ int conf_write(const char *name) ...@@ -312,11 +312,11 @@ int conf_write(const char *name)
if (env && *env) if (env && *env)
use_timestamp = 0; use_timestamp = 0;
fprintf(out, "#\n" fprintf(out, _("#\n"
"# Automatically generated make config: don't edit\n" "# Automatically generated make config: don't edit\n"
"# Linux kernel version: %s\n" "# Linux kernel version: %s\n"
"%s%s" "%s%s"
"#\n", "#\n"),
sym_get_string_value(sym), sym_get_string_value(sym),
use_timestamp ? "# " : "", use_timestamp ? "# " : "",
use_timestamp ? ctime(&now) : ""); use_timestamp ? ctime(&now) : "");
......
...@@ -41,7 +41,7 @@ static gboolean resizeable = FALSE; ...@@ -41,7 +41,7 @@ static gboolean resizeable = FALSE;
static gboolean config_changed = FALSE; static gboolean config_changed = FALSE;
static char nohelp_text[] = static char nohelp_text[] =
"Sorry, no help available for this option yet.\n"; N_("Sorry, no help available for this option yet.\n");
GtkWidget *main_wnd = NULL; GtkWidget *main_wnd = NULL;
GtkWidget *tree1_w = NULL; // left frame GtkWidget *tree1_w = NULL; // left frame
...@@ -193,7 +193,7 @@ void init_main_window(const gchar * glade_file) ...@@ -193,7 +193,7 @@ void init_main_window(const gchar * glade_file)
xml = glade_xml_new(glade_file, "window1", NULL); xml = glade_xml_new(glade_file, "window1", NULL);
if (!xml) if (!xml)
g_error("GUI loading failed !\n"); g_error(_("GUI loading failed !\n"));
glade_xml_signal_autoconnect(xml); glade_xml_signal_autoconnect(xml);
main_wnd = glade_xml_get_widget(xml, "window1"); main_wnd = glade_xml_get_widget(xml, "window1");
...@@ -275,7 +275,7 @@ void init_main_window(const gchar * glade_file) ...@@ -275,7 +275,7 @@ void init_main_window(const gchar * glade_file)
/*"style", PANGO_STYLE_OBLIQUE, */ /*"style", PANGO_STYLE_OBLIQUE, */
NULL); NULL);
sprintf(title, "Linux Kernel v%s Configuration", sprintf(title, _("Linux Kernel v%s Configuration"),
getenv("KERNELRELEASE")); getenv("KERNELRELEASE"));
gtk_window_set_title(GTK_WINDOW(main_wnd), title); gtk_window_set_title(GTK_WINDOW(main_wnd), title);
...@@ -325,7 +325,7 @@ void init_left_tree(void) ...@@ -325,7 +325,7 @@ void init_left_tree(void)
column = gtk_tree_view_column_new(); column = gtk_tree_view_column_new();
gtk_tree_view_append_column(view, column); gtk_tree_view_append_column(view, column);
gtk_tree_view_column_set_title(column, "Options"); gtk_tree_view_column_set_title(column, _("Options"));
renderer = gtk_cell_renderer_toggle_new(); renderer = gtk_cell_renderer_toggle_new();
gtk_tree_view_column_pack_start(GTK_TREE_VIEW_COLUMN(column), gtk_tree_view_column_pack_start(GTK_TREE_VIEW_COLUMN(column),
...@@ -370,7 +370,7 @@ void init_right_tree(void) ...@@ -370,7 +370,7 @@ void init_right_tree(void)
column = gtk_tree_view_column_new(); column = gtk_tree_view_column_new();
gtk_tree_view_append_column(view, column); gtk_tree_view_append_column(view, column);
gtk_tree_view_column_set_title(column, "Options"); gtk_tree_view_column_set_title(column, _("Options"));
renderer = gtk_cell_renderer_pixbuf_new(); renderer = gtk_cell_renderer_pixbuf_new();
gtk_tree_view_column_pack_start(GTK_TREE_VIEW_COLUMN(column), gtk_tree_view_column_pack_start(GTK_TREE_VIEW_COLUMN(column),
...@@ -401,7 +401,7 @@ void init_right_tree(void) ...@@ -401,7 +401,7 @@ void init_right_tree(void)
renderer = gtk_cell_renderer_text_new(); renderer = gtk_cell_renderer_text_new();
gtk_tree_view_insert_column_with_attributes(view, -1, gtk_tree_view_insert_column_with_attributes(view, -1,
"Name", renderer, _("Name"), renderer,
"text", COL_NAME, "text", COL_NAME,
"foreground-gdk", "foreground-gdk",
COL_COLOR, NULL); COL_COLOR, NULL);
...@@ -425,7 +425,7 @@ void init_right_tree(void) ...@@ -425,7 +425,7 @@ void init_right_tree(void)
COL_COLOR, NULL); COL_COLOR, NULL);
renderer = gtk_cell_renderer_text_new(); renderer = gtk_cell_renderer_text_new();
gtk_tree_view_insert_column_with_attributes(view, -1, gtk_tree_view_insert_column_with_attributes(view, -1,
"Value", renderer, _("Value"), renderer,
"text", COL_VALUE, "text", COL_VALUE,
"editable", "editable",
COL_EDIT, COL_EDIT,
...@@ -466,15 +466,15 @@ static void text_insert_help(struct menu *menu) ...@@ -466,15 +466,15 @@ static void text_insert_help(struct menu *menu)
GtkTextIter start, end; GtkTextIter start, end;
const char *prompt = menu_get_prompt(menu); const char *prompt = menu_get_prompt(menu);
gchar *name; gchar *name;
const char *help = nohelp_text; const char *help = _(nohelp_text);
if (!menu->sym) if (!menu->sym)
help = ""; help = "";
else if (menu->sym->help) else if (menu->sym->help)
help = menu->sym->help; help = _(menu->sym->help);
if (menu->sym && menu->sym->name) if (menu->sym && menu->sym->name)
name = g_strdup_printf(menu->sym->name); name = g_strdup_printf(_(menu->sym->name));
else else
name = g_strdup(""); name = g_strdup("");
...@@ -530,7 +530,7 @@ gboolean on_window1_delete_event(GtkWidget * widget, GdkEvent * event, ...@@ -530,7 +530,7 @@ gboolean on_window1_delete_event(GtkWidget * widget, GdkEvent * event,
if (config_changed == FALSE) if (config_changed == FALSE)
return FALSE; return FALSE;
dialog = gtk_dialog_new_with_buttons("Warning !", dialog = gtk_dialog_new_with_buttons(_("Warning !"),
GTK_WINDOW(main_wnd), GTK_WINDOW(main_wnd),
(GtkDialogFlags) (GtkDialogFlags)
(GTK_DIALOG_MODAL | (GTK_DIALOG_MODAL |
...@@ -544,7 +544,7 @@ gboolean on_window1_delete_event(GtkWidget * widget, GdkEvent * event, ...@@ -544,7 +544,7 @@ gboolean on_window1_delete_event(GtkWidget * widget, GdkEvent * event,
gtk_dialog_set_default_response(GTK_DIALOG(dialog), gtk_dialog_set_default_response(GTK_DIALOG(dialog),
GTK_RESPONSE_CANCEL); GTK_RESPONSE_CANCEL);
label = gtk_label_new("\nSave configuration ?\n"); label = gtk_label_new(_("\nSave configuration ?\n"));
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label); gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);
gtk_widget_show(label); gtk_widget_show(label);
...@@ -604,7 +604,7 @@ load_filename(GtkFileSelection * file_selector, gpointer user_data) ...@@ -604,7 +604,7 @@ load_filename(GtkFileSelection * file_selector, gpointer user_data)
(user_data)); (user_data));
if (conf_read(fn)) if (conf_read(fn))
text_insert_msg("Error", "Unable to load configuration !"); text_insert_msg(_("Error"), _("Unable to load configuration !"));
else else
display_tree(&rootmenu); display_tree(&rootmenu);
} }
...@@ -613,7 +613,7 @@ void on_load1_activate(GtkMenuItem * menuitem, gpointer user_data) ...@@ -613,7 +613,7 @@ void on_load1_activate(GtkMenuItem * menuitem, gpointer user_data)
{ {
GtkWidget *fs; GtkWidget *fs;
fs = gtk_file_selection_new("Load file..."); fs = gtk_file_selection_new(_("Load file..."));
g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fs)->ok_button), g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fs)->ok_button),
"clicked", "clicked",
G_CALLBACK(load_filename), (gpointer) fs); G_CALLBACK(load_filename), (gpointer) fs);
...@@ -632,7 +632,7 @@ void on_load1_activate(GtkMenuItem * menuitem, gpointer user_data) ...@@ -632,7 +632,7 @@ void on_load1_activate(GtkMenuItem * menuitem, gpointer user_data)
void on_save1_activate(GtkMenuItem * menuitem, gpointer user_data) void on_save1_activate(GtkMenuItem * menuitem, gpointer user_data)
{ {
if (conf_write(NULL)) if (conf_write(NULL))
text_insert_msg("Error", "Unable to save configuration !"); text_insert_msg(_("Error"), _("Unable to save configuration !"));
config_changed = FALSE; config_changed = FALSE;
} }
...@@ -647,7 +647,7 @@ store_filename(GtkFileSelection * file_selector, gpointer user_data) ...@@ -647,7 +647,7 @@ store_filename(GtkFileSelection * file_selector, gpointer user_data)
(user_data)); (user_data));
if (conf_write(fn)) if (conf_write(fn))
text_insert_msg("Error", "Unable to save configuration !"); text_insert_msg(_("Error"), _("Unable to save configuration !"));
gtk_widget_destroy(GTK_WIDGET(user_data)); gtk_widget_destroy(GTK_WIDGET(user_data));
} }
...@@ -656,7 +656,7 @@ void on_save_as1_activate(GtkMenuItem * menuitem, gpointer user_data) ...@@ -656,7 +656,7 @@ void on_save_as1_activate(GtkMenuItem * menuitem, gpointer user_data)
{ {
GtkWidget *fs; GtkWidget *fs;
fs = gtk_file_selection_new("Save file as..."); fs = gtk_file_selection_new(_("Save file as..."));
g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fs)->ok_button), g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fs)->ok_button),
"clicked", "clicked",
G_CALLBACK(store_filename), (gpointer) fs); G_CALLBACK(store_filename), (gpointer) fs);
...@@ -740,7 +740,7 @@ on_show_debug_info1_activate(GtkMenuItem * menuitem, gpointer user_data) ...@@ -740,7 +740,7 @@ on_show_debug_info1_activate(GtkMenuItem * menuitem, gpointer user_data)
void on_introduction1_activate(GtkMenuItem * menuitem, gpointer user_data) void on_introduction1_activate(GtkMenuItem * menuitem, gpointer user_data)
{ {
GtkWidget *dialog; GtkWidget *dialog;
const gchar *intro_text = const gchar *intro_text = _(
"Welcome to gkc, the GTK+ graphical kernel configuration tool\n" "Welcome to gkc, the GTK+ graphical kernel configuration tool\n"
"for Linux.\n" "for Linux.\n"
"For each option, a blank box indicates the feature is disabled, a\n" "For each option, a blank box indicates the feature is disabled, a\n"
...@@ -756,7 +756,7 @@ void on_introduction1_activate(GtkMenuItem * menuitem, gpointer user_data) ...@@ -756,7 +756,7 @@ void on_introduction1_activate(GtkMenuItem * menuitem, gpointer user_data)
"option.\n" "option.\n"
"\n" "\n"
"Toggling Show Debug Info under the Options menu will show \n" "Toggling Show Debug Info under the Options menu will show \n"
"the dependencies, which you can then match by examining other options."; "the dependencies, which you can then match by examining other options.");
dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd), dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd),
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_DESTROY_WITH_PARENT,
...@@ -773,8 +773,8 @@ void on_about1_activate(GtkMenuItem * menuitem, gpointer user_data) ...@@ -773,8 +773,8 @@ void on_about1_activate(GtkMenuItem * menuitem, gpointer user_data)
{ {
GtkWidget *dialog; GtkWidget *dialog;
const gchar *about_text = const gchar *about_text =
"gkc is copyright (c) 2002 Romain Lievin <roms@lpg.ticalc.org>.\n" _("gkc is copyright (c) 2002 Romain Lievin <roms@lpg.ticalc.org>.\n"
"Based on the source code from Roman Zippel.\n"; "Based on the source code from Roman Zippel.\n");
dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd), dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd),
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_DESTROY_WITH_PARENT,
...@@ -791,9 +791,9 @@ void on_license1_activate(GtkMenuItem * menuitem, gpointer user_data) ...@@ -791,9 +791,9 @@ void on_license1_activate(GtkMenuItem * menuitem, gpointer user_data)
{ {
GtkWidget *dialog; GtkWidget *dialog;
const gchar *license_text = const gchar *license_text =
"gkc is released under the terms of the GNU GPL v2.\n" _("gkc is released under the terms of the GNU GPL v2.\n"
"For more information, please see the source code or\n" "For more information, please see the source code or\n"
"visit http://www.fsf.org/licenses/licenses.html\n"; "visit http://www.fsf.org/licenses/licenses.html\n");
dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd), dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd),
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_DESTROY_WITH_PARENT,
...@@ -1579,6 +1579,10 @@ int main(int ac, char *av[]) ...@@ -1579,6 +1579,10 @@ int main(int ac, char *av[])
kconfig_load(); kconfig_load();
#endif #endif
bindtextdomain(PACKAGE, LOCALEDIR);
bind_textdomain_codeset(PACKAGE, "UTF-8");
textdomain(PACKAGE);
/* GTK stuffs */ /* GTK stuffs */
gtk_set_locale(); gtk_set_locale();
gtk_init(&ac, &av); gtk_init(&ac, &av);
......
/*
* Arnaldo Carvalho de Melo <acme@conectiva.com.br>, 2005
*
* Released under the terms of the GNU GPL v2.0
*/
#include <stdlib.h>
#include <string.h>
#define LKC_DIRECT_LINK
#include "lkc.h"
static char *escape(const char* text, char *bf, int len)
{
char *bfp = bf;
int multiline = strchr(text, '\n') != NULL;
*bfp++ = '"';
--len;
if (multiline) {
*bfp++ = '"';
*bfp++ = '\n';
*bfp++ = '"';
len -= 3;
}
while (*text != '\0' && len > 1) {
if (*text == '"')
*bfp++ = '\\';
else if (*text == '\n') {
*bfp++ = '\\';
*bfp++ = 'n';
*bfp++ = '"';
*bfp++ = '\n';
*bfp++ = '"';
len -= 5;
++text;
goto next;
}
*bfp++ = *text++;
next:
--len;
}
if (multiline)
bfp -= 3;
*bfp++ = '"';
*bfp = '\0';
return bf;
}
struct file_line {
struct file_line *next;
char* file;
int lineno;
};
static struct file_line *file_line__new(char *file, int lineno)
{
struct file_line *self = malloc(sizeof(*self));
if (self == NULL)
goto out;
self->file = file;
self->lineno = lineno;
self->next = NULL;
out:
return self;
}
struct message {
const char *msg;
const char *option;
struct message *next;
struct file_line *files;
};
static struct message *message__list;
static struct message *message__new(const char *msg, char *option, char *file, int lineno)
{
struct message *self = malloc(sizeof(*self));
if (self == NULL)
goto out;
self->files = file_line__new(file, lineno);
if (self->files == NULL)
goto out_fail;
self->msg = strdup(msg);
if (self->msg == NULL)
goto out_fail_msg;
self->option = option;
self->next = NULL;
out:
return self;
out_fail_msg:
free(self->files);
out_fail:
free(self);
self = NULL;
goto out;
}
static struct message *mesage__find(const char *msg)
{
struct message *m = message__list;
while (m != NULL) {
if (strcmp(m->msg, msg) == 0)
break;
m = m->next;
}
return m;
}
static int message__add_file_line(struct message *self, char *file, int lineno)
{
int rc = -1;
struct file_line *fl = file_line__new(file, lineno);
if (fl == NULL)
goto out;
fl->next = self->files;
self->files = fl;
rc = 0;
out:
return rc;
}
static int message__add(const char *msg, char *option, char *file, int lineno)
{
int rc = 0;
char bf[16384];
char *escaped = escape(msg, bf, sizeof(bf));
struct message *m = mesage__find(escaped);
if (m != NULL)
rc = message__add_file_line(m, file, lineno);
else {
m = message__new(escaped, option, file, lineno);
if (m != NULL) {
m->next = message__list;
message__list = m;
} else
rc = -1;
}
return rc;
}
void menu_build_message_list(struct menu *menu)
{
struct menu *child;
message__add(menu_get_prompt(menu), NULL,
menu->file == NULL ? "Root Menu" : menu->file->name,
menu->lineno);
if (menu->sym != NULL && menu->sym->help != NULL)
message__add(menu->sym->help, menu->sym->name,
menu->file == NULL ? "Root Menu" : menu->file->name,
menu->lineno);
for (child = menu->list; child != NULL; child = child->next)
if (child->prompt != NULL)
menu_build_message_list(child);
}
static void message__print_file_lineno(struct message *self)
{
struct file_line *fl = self->files;
printf("\n#: %s:%d", fl->file, fl->lineno);
fl = fl->next;
while (fl != NULL) {
printf(", %s:%d", fl->file, fl->lineno);
fl = fl->next;
}
if (self->option != NULL)
printf(", %s:00000", self->option);
putchar('\n');
}
static void message__print_gettext_msgid_msgstr(struct message *self)
{
message__print_file_lineno(self);
printf("msgid %s\n"
"msgstr \"\"\n", self->msg);
}
void menu__xgettext(void)
{
struct message *m = message__list;
while (m != NULL) {
message__print_gettext_msgid_msgstr(m);
m = m->next;
}
}
int main(int ac, char **av)
{
conf_parse(av[1]);
menu_build_message_list(menu_get_root_menu(NULL));
menu__xgettext();
return 0;
}
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "expr.h" #include "expr.h"
#include <libintl.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
...@@ -23,6 +25,12 @@ extern "C" { ...@@ -23,6 +25,12 @@ extern "C" {
#define SRCTREE "srctree" #define SRCTREE "srctree"
#define PACKAGE "linux"
#define LOCALEDIR "/usr/share/locale"
#define _(text) gettext(text)
#define N_(text) (text)
int zconfparse(void); int zconfparse(void);
void zconfdump(FILE *out); void zconfdump(FILE *out);
......
This diff is collapsed.
...@@ -365,9 +365,9 @@ bool menu_is_visible(struct menu *menu) ...@@ -365,9 +365,9 @@ bool menu_is_visible(struct menu *menu)
const char *menu_get_prompt(struct menu *menu) const char *menu_get_prompt(struct menu *menu)
{ {
if (menu->prompt) if (menu->prompt)
return menu->prompt->text; return _(menu->prompt->text);
else if (menu->sym) else if (menu->sym)
return menu->sym->name; return _(menu->sym->name);
return NULL; return NULL;
} }
......
...@@ -26,8 +26,23 @@ ...@@ -26,8 +26,23 @@
#include "qconf.moc" #include "qconf.moc"
#include "images.c" #include "images.c"
#ifdef _
# undef _
# define _ qgettext
#endif
static QApplication *configApp; static QApplication *configApp;
static inline QString qgettext(const char* str)
{
return QString::fromLocal8Bit(gettext(str));
}
static inline QString qgettext(const QString& str)
{
return QString::fromLocal8Bit(gettext(str.latin1()));
}
ConfigSettings::ConfigSettings() ConfigSettings::ConfigSettings()
: showAll(false), showName(false), showRange(false), showData(false) : showAll(false), showName(false), showRange(false), showData(false)
{ {
...@@ -177,7 +192,7 @@ void ConfigItem::updateMenu(void) ...@@ -177,7 +192,7 @@ void ConfigItem::updateMenu(void)
sym = menu->sym; sym = menu->sym;
prop = menu->prompt; prop = menu->prompt;
prompt = menu_get_prompt(menu); prompt = QString::fromLocal8Bit(menu_get_prompt(menu));
if (prop) switch (prop->type) { if (prop) switch (prop->type) {
case P_MENU: case P_MENU:
...@@ -203,7 +218,7 @@ void ConfigItem::updateMenu(void) ...@@ -203,7 +218,7 @@ void ConfigItem::updateMenu(void)
if (!sym) if (!sym)
goto set_prompt; goto set_prompt;
setText(nameColIdx, sym->name); setText(nameColIdx, QString::fromLocal8Bit(sym->name));
type = sym_get_type(sym); type = sym_get_type(sym);
switch (type) { switch (type) {
...@@ -213,9 +228,9 @@ void ConfigItem::updateMenu(void) ...@@ -213,9 +228,9 @@ void ConfigItem::updateMenu(void)
if (!sym_is_changable(sym) && !list->showAll) { if (!sym_is_changable(sym) && !list->showAll) {
setPixmap(promptColIdx, 0); setPixmap(promptColIdx, 0);
setText(noColIdx, 0); setText(noColIdx, QString::null);
setText(modColIdx, 0); setText(modColIdx, QString::null);
setText(yesColIdx, 0); setText(yesColIdx, QString::null);
break; break;
} }
expr = sym_get_tristate_value(sym); expr = sym_get_tristate_value(sym);
...@@ -257,6 +272,7 @@ void ConfigItem::updateMenu(void) ...@@ -257,6 +272,7 @@ void ConfigItem::updateMenu(void)
const char* data; const char* data;
data = sym_get_string_value(sym); data = sym_get_string_value(sym);
#if QT_VERSION >= 300 #if QT_VERSION >= 300
int i = list->mapIdx(dataColIdx); int i = list->mapIdx(dataColIdx);
if (i >= 0) if (i >= 0)
...@@ -264,9 +280,9 @@ void ConfigItem::updateMenu(void) ...@@ -264,9 +280,9 @@ void ConfigItem::updateMenu(void)
#endif #endif
setText(dataColIdx, data); setText(dataColIdx, data);
if (type == S_STRING) if (type == S_STRING)
prompt.sprintf("%s: %s", prompt.latin1(), data); prompt = QString("%1: %2").arg(prompt).arg(data);
else else
prompt.sprintf("(%s) %s", data, prompt.latin1()); prompt = QString("(%2) %1").arg(prompt).arg(data);
break; break;
} }
if (!sym_has_value(sym) && visible) if (!sym_has_value(sym) && visible)
...@@ -343,9 +359,9 @@ void ConfigLineEdit::show(ConfigItem* i) ...@@ -343,9 +359,9 @@ void ConfigLineEdit::show(ConfigItem* i)
{ {
item = i; item = i;
if (sym_get_string_value(item->menu->sym)) if (sym_get_string_value(item->menu->sym))
setText(sym_get_string_value(item->menu->sym)); setText(QString::fromLocal8Bit(sym_get_string_value(item->menu->sym)));
else else
setText(0); setText(QString::null);
Parent::show(); Parent::show();
setFocus(); setFocus();
} }
...@@ -961,7 +977,7 @@ ConfigMainWindow::ConfigMainWindow(void) ...@@ -961,7 +977,7 @@ ConfigMainWindow::ConfigMainWindow(void)
delete configSettings; delete configSettings;
} }
static QString print_filter(const char *str) static QString print_filter(const QString &str)
{ {
QRegExp re("[<>&\"\\n]"); QRegExp re("[<>&\"\\n]");
QString res = str; QString res = str;
...@@ -994,7 +1010,7 @@ static QString print_filter(const char *str) ...@@ -994,7 +1010,7 @@ static QString print_filter(const char *str)
static void expr_print_help(void *data, const char *str) static void expr_print_help(void *data, const char *str)
{ {
((QString*)data)->append(print_filter(str)); reinterpret_cast<QString*>(data)->append(print_filter(str));
} }
/* /*
...@@ -1009,7 +1025,7 @@ void ConfigMainWindow::setHelp(QListViewItem* item) ...@@ -1009,7 +1025,7 @@ void ConfigMainWindow::setHelp(QListViewItem* item)
if (item) if (item)
menu = ((ConfigItem*)item)->menu; menu = ((ConfigItem*)item)->menu;
if (!menu) { if (!menu) {
helpText->setText(NULL); helpText->setText(QString::null);
return; return;
} }
...@@ -1019,16 +1035,16 @@ void ConfigMainWindow::setHelp(QListViewItem* item) ...@@ -1019,16 +1035,16 @@ void ConfigMainWindow::setHelp(QListViewItem* item)
if (sym) { if (sym) {
if (menu->prompt) { if (menu->prompt) {
head += "<big><b>"; head += "<big><b>";
head += print_filter(menu->prompt->text); head += print_filter(_(menu->prompt->text));
head += "</b></big>"; head += "</b></big>";
if (sym->name) { if (sym->name) {
head += " ("; head += " (";
head += print_filter(sym->name); head += print_filter(_(sym->name));
head += ")"; head += ")";
} }
} else if (sym->name) { } else if (sym->name) {
head += "<big><b>"; head += "<big><b>";
head += print_filter(sym->name); head += print_filter(_(sym->name));
head += "</b></big>"; head += "</b></big>";
} }
head += "<br><br>"; head += "<br><br>";
...@@ -1049,7 +1065,7 @@ void ConfigMainWindow::setHelp(QListViewItem* item) ...@@ -1049,7 +1065,7 @@ void ConfigMainWindow::setHelp(QListViewItem* item)
case P_PROMPT: case P_PROMPT:
case P_MENU: case P_MENU:
debug += "prompt: "; debug += "prompt: ";
debug += print_filter(prop->text); debug += print_filter(_(prop->text));
debug += "<br>"; debug += "<br>";
break; break;
case P_DEFAULT: case P_DEFAULT:
...@@ -1088,10 +1104,10 @@ void ConfigMainWindow::setHelp(QListViewItem* item) ...@@ -1088,10 +1104,10 @@ void ConfigMainWindow::setHelp(QListViewItem* item)
debug += "<br>"; debug += "<br>";
} }
help = print_filter(sym->help); help = print_filter(_(sym->help));
} else if (menu->prompt) { } else if (menu->prompt) {
head += "<big><b>"; head += "<big><b>";
head += print_filter(menu->prompt->text); head += print_filter(_(menu->prompt->text));
head += "</b></big><br><br>"; head += "</b></big><br><br>";
if (showDebug) { if (showDebug) {
if (menu->prompt->visible.expr) { if (menu->prompt->visible.expr) {
...@@ -1111,7 +1127,7 @@ void ConfigMainWindow::loadConfig(void) ...@@ -1111,7 +1127,7 @@ void ConfigMainWindow::loadConfig(void)
QString s = QFileDialog::getOpenFileName(".config", NULL, this); QString s = QFileDialog::getOpenFileName(".config", NULL, this);
if (s.isNull()) if (s.isNull())
return; return;
if (conf_read(s.latin1())) if (conf_read(QFile::encodeName(s)))
QMessageBox::information(this, "qconf", "Unable to load configuration!"); QMessageBox::information(this, "qconf", "Unable to load configuration!");
ConfigView::updateListAll(); ConfigView::updateListAll();
} }
...@@ -1127,7 +1143,7 @@ void ConfigMainWindow::saveConfigAs(void) ...@@ -1127,7 +1143,7 @@ void ConfigMainWindow::saveConfigAs(void)
QString s = QFileDialog::getSaveFileName(".config", NULL, this); QString s = QFileDialog::getSaveFileName(".config", NULL, this);
if (s.isNull()) if (s.isNull())
return; return;
if (conf_write(s.latin1())) if (conf_write(QFile::encodeName(s)))
QMessageBox::information(this, "qconf", "Unable to save configuration!"); QMessageBox::information(this, "qconf", "Unable to save configuration!");
} }
...@@ -1372,6 +1388,9 @@ int main(int ac, char** av) ...@@ -1372,6 +1388,9 @@ int main(int ac, char** av)
ConfigMainWindow* v; ConfigMainWindow* v;
const char *name; const char *name;
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
#ifndef LKC_DIRECT_LINK #ifndef LKC_DIRECT_LINK
kconfig_load(); kconfig_load();
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment