1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 12:28:22 +01:00

Menu translation support

When generating menus, lookup translations for menu entries in
specified textdomain.  Often used by linux distributions.

Original-patch-by: Alexey Voinov <voins@altlinux.ru>
Signed-off-by: Alexey I. Froloff <raorn@altlinux.org>
This commit is contained in:
Alexey I. Froloff
2010-09-10 20:51:02 +04:00
committed by Carlos R. Mafra
parent e9d42e5121
commit ca1c29cd98
4 changed files with 35 additions and 14 deletions

View File

@@ -368,6 +368,11 @@ if test "x$NLSDIR" = "x"; then
fi
fi
AC_ARG_WITH(menu-textdomain, AS_HELP_STRING([--with-menu-textdomain=DOMAIN], [specify gettext domain used for menu translations]),
[if test "x$withval" != "xno"; then
AC_DEFINE_UNQUOTED([MENU_TEXTDOMAIN], ["$withval"], [gettext domain used for menu translations])
fi])
AC_SUBST(INTLIBS)
AC_SUBST(NLSDIR)
AC_SUBST(MOFILES)

View File

@@ -711,11 +711,21 @@ static int real_main(int argc, char **argv)
if (!Locale || strcmp(Locale, "C") == 0 || strcmp(Locale, "POSIX") == 0)
Locale = NULL;
#ifdef I18N
if (getenv("NLSPATH"))
if (getenv("NLSPATH")) {
bindtextdomain("WindowMaker", getenv("NLSPATH"));
else
#if defined(MENU_TEXTDOMAIN)
bindtextdomain(MENU_TEXTDOMAIN, getenv("NLSPATH"));
#endif
} else {
bindtextdomain("WindowMaker", LOCALEDIR);
#if defined(MENU_TEXTDOMAIN)
bindtextdomain(MENU_TEXTDOMAIN, LOCALEDIR);
#endif
}
bind_textdomain_codeset("WindowMaker", "UTF-8");
#if defined(MENU_TEXTDOMAIN)
bind_textdomain_codeset(MENU_TEXTDOMAIN, "UTF-8");
#endif
textdomain("WindowMaker");
if (!XSupportsLocale()) {

View File

@@ -1032,12 +1032,12 @@ static WMenu *parseCascade(WScreen * scr, WMenu * menu, FILE * file, char *file_
/* start submenu */
cascade = wMenuCreate(scr, title, False);
cascade = wMenuCreate(scr, M_(title), False);
cascade->on_destroy = removeShortcutsForMenu;
if (parseCascade(scr, cascade, file, file_name) == NULL) {
wMenuDestroy(cascade, True);
} else {
wMenuEntrySetCascade(menu, wMenuAddCallback(menu, title, NULL, NULL), cascade);
wMenuEntrySetCascade(menu, wMenuAddCallback(menu, M_(title), NULL, NULL), cascade);
}
} else if (strcasecmp(command, "END") == 0) {
/* end of menu */
@@ -1045,7 +1045,7 @@ static WMenu *parseCascade(WScreen * scr, WMenu * menu, FILE * file, char *file_
} else {
/* normal items */
addMenuEntry(menu, title, shortcut[0] ? shortcut : NULL, command,
addMenuEntry(menu, M_(title), shortcut[0] ? shortcut : NULL, command,
params[0] ? params : NULL, file_name);
}
}
@@ -1112,7 +1112,7 @@ static WMenu *readMenuFile(WScreen * scr, char *file_name)
break;
}
if (strcasecmp(command, "MENU") == 0) {
menu = wMenuCreate(scr, title, True);
menu = wMenuCreate(scr, M_(title), True);
menu->on_destroy = removeShortcutsForMenu;
if (!parseCascade(scr, menu, file, file_name)) {
wMenuDestroy(menu, True);
@@ -1209,7 +1209,7 @@ static WMenu *readMenuPipe(WScreen * scr, char **file_name)
break;
}
if (strcasecmp(command, "MENU") == 0) {
menu = wMenuCreate(scr, title, True);
menu = wMenuCreate(scr, M_(title), True);
menu->on_destroy = removeShortcutsForMenu;
if (!parseCascade(scr, menu, file, filename)) {
wMenuDestroy(menu, True);
@@ -1356,7 +1356,7 @@ static WMenu *readMenuDirectory(WScreen * scr, char *title, char **path, char *c
WMSortArray(dirs, myCompare);
WMSortArray(files, myCompare);
menu = wMenuCreate(scr, title, False);
menu = wMenuCreate(scr, M_(title), False);
menu->on_destroy = removeShortcutsForMenu;
WM_ITERATE_ARRAY(dirs, data, iter) {
@@ -1392,7 +1392,7 @@ static WMenu *readMenuDirectory(WScreen * scr, char *title, char **path, char *c
strcat(buffer, command);
}
addMenuEntry(menu, data->name, NULL, "OPEN_MENU", buffer, path[data->index]);
addMenuEntry(menu, M_(data->name), NULL, "OPEN_MENU", buffer, path[data->index]);
wfree(buffer);
if (data->name)
@@ -1438,7 +1438,7 @@ static WMenu *readMenuDirectory(WScreen * scr, char *title, char **path, char *c
if (ptr && ptr != data->name)
*ptr = 0;
}
addMenuEntry(menu, data->name, NULL, "SHEXEC", buffer, path[data->index]);
addMenuEntry(menu, M_(data->name), NULL, "SHEXEC", buffer, path[data->index]);
wfree(buffer);
if (data->name)
@@ -1459,8 +1459,8 @@ static WMenu *makeDefaultMenu(WScreen * scr)
WMenu *menu = NULL;
menu = wMenuCreate(scr, _("Commands"), True);
wMenuAddCallback(menu, "XTerm", execCommand, "xterm");
wMenuAddCallback(menu, "rxvt", execCommand, "rxvt");
wMenuAddCallback(menu, M_("XTerm"), execCommand, "xterm");
wMenuAddCallback(menu, M_("rxvt"), execCommand, "rxvt");
wMenuAddCallback(menu, _("Restart"), restartCommand, NULL);
wMenuAddCallback(menu, _("Exit..."), exitCommand, NULL);
return menu;
@@ -1548,7 +1548,7 @@ static WMenu *configureMenu(WScreen * scr, WMPropList * definition)
}
mtitle = WMGetFromPLString(elem);
menu = wMenuCreate(scr, mtitle, False);
menu = wMenuCreate(scr, M_(mtitle), False);
menu->on_destroy = removeShortcutsForMenu;
#ifdef GLOBAL_SUBMENU_FILE
@@ -1607,7 +1607,7 @@ static WMenu *configureMenu(WScreen * scr, WMPropList * definition)
if (!title || !command)
goto error;
addMenuEntry(menu, WMGetFromPLString(title),
addMenuEntry(menu, M_(WMGetFromPLString(title)),
shortcut ? WMGetFromPLString(shortcut) : NULL,
WMGetFromPLString(command),
params ? WMGetFromPLString(params) : NULL, "WMRootMenu");

View File

@@ -413,9 +413,15 @@
* the string up for translation
*/
#define N_(text) (text)
#if defined(MENU_TEXTDOMAIN)
#define M_(text) dgettext(MENU_TEXTDOMAIN, text)
#else
#define M_(text) (text)
#endif
#else
#define _(text) (text)
#define N_(text) (text)
#define M_(text) (text)
#endif
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)