diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-11-09 13:19:21 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2022-11-09 13:19:21 -0800 |
commit | f286ef347dc9e87c6d5b5b8bce22afdeb82af4ed (patch) | |
tree | c04f47f0e67b8456283e87e3c7b9fb0dce6449de | |
parent | 57f670195bb1854edbea97b672ae966343965bb7 (diff) |
Use gettext() to localize messages if available
Originally fixed for Solaris in August 2000 by Jay Hobson under
Sun bug 4256527 "Internationalize xfontsel"
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | COPYING | 21 | ||||
-rw-r--r-- | Makefile.am | 11 | ||||
-rw-r--r-- | configure.ac | 20 | ||||
-rw-r--r-- | xfontsel.c | 85 |
4 files changed, 123 insertions, 14 deletions
@@ -42,3 +42,24 @@ WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +Copyright (c) 2000, 2022, Oracle and/or its affiliates. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/Makefile.am b/Makefile.am index e62fd49..62e51c3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -53,3 +53,14 @@ ChangeLog: dist-hook: ChangeLog INSTALL EXTRA_DIST = README.md + +if USE_GETTEXT +AM_CPPFLAGS = -DLOCALEDIR='"$(LOCALEDIR)"' + +noinst_DATA = xfontsel.po + +xfontsel.po: $(xfontsel_SOURCES:%=$(srcdir)/%) + $(AM_V_GEN)xgettext -d xfontsel -c -n $(xfontsel_SOURCES:%=$(srcdir)/%) + +CLEANFILES = xfontsel.po +endif diff --git a/configure.ac b/configure.ac index 2b5b9b5..51f410f 100644 --- a/configure.ac +++ b/configure.ac @@ -47,6 +47,26 @@ AC_ARG_WITH(appdefaultdir, [appdefaultdir="$withval"], [appdefaultdir="${xt_appdefaultdir}"]) AC_SUBST(appdefaultdir) +# Internationalization & localization support +AC_SEARCH_LIBS([gettext], [intl], [USE_GETTEXT="yes"], [USE_GETTEXT="no"]) +AC_MSG_CHECKING([where to install localized messages]) +AC_ARG_WITH([localedir], AS_HELP_STRING([--with-localedir=<path>], + [Path to install message files in (default: datadir/locale)]), + [LOCALEDIR=${withval}], [LOCALEDIR=${datadir}/locale]) +if test "x$LOCALEDIR" = "xno" -o "x$USE_GETTEXT" = "xno" ; then + AC_MSG_RESULT([nowhere]) + USE_GETTEXT="no" +else + AC_SUBST([LOCALEDIR]) + AC_MSG_RESULT([$LOCALEDIR]) +fi + +if test "x$USE_GETTEXT" = "xyes" ; then + AC_DEFINE([USE_GETTEXT], 1, + [Define to 1 if you want to use the gettext() function.]) +fi +AM_CONDITIONAL(USE_GETTEXT, test "x$USE_GETTEXT" = "xyes") + AC_CONFIG_FILES([ Makefile @@ -31,6 +31,32 @@ Author: Ralph R. Swick, DEC/MIT Project Athena Modified: Mark Leisher <mleisher@crl.nmsu.edu> to deal with UCS sample text. */ +/* + * Copyright (c) 2000, 2022, Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Modifications by Jay Hobson (Sun Microsystems) to internationalize messages + */ + + #include <stdio.h> #include <stdlib.h> #include <X11/Intrinsic.h> @@ -53,6 +79,13 @@ Modified: Mark Leisher <mleisher@crl.nmsu.edu> to deal with UCS sample text. #include <X11/Xlib.h> #include "ULabel.h" +#ifdef USE_GETTEXT +# include <locale.h> /* setlocale() */ +# include <libintl.h> /* gettext(), textdomain(), etc. */ +#else +# define gettext(a) (a) +#endif + #define MIN_APP_DEFAULTS_VERSION 1 #define FIELD_COUNT 14 #define DELIM '-' @@ -154,6 +187,7 @@ static XrmOptionDescRec options[] = { static void Syntax(const char *call) { fprintf (stderr, "usage: %s [-options ...] -fn font\n\n%s\n", call, + gettext( "where options include:\n" " -display dpy X server to contact\n" " -geometry geom size and location of window\n" @@ -163,7 +197,7 @@ static void Syntax(const char *call) " -sample16 string sample text to use for 2-byte fonts\n" " -sampleUCS string sample text to use for ISO10646 fonts\n" " -scaled use scaled instances of fonts\n" - "plus any standard toolkit options\n"); + "plus any standard toolkit options\n")); exit (1); } @@ -263,6 +297,25 @@ main(int argc, char **argv) topLevel = XtAppInitialize(&appCtx, "XFontSel", options, XtNumber(options), &argc, argv, NULL, NULL, 0); +#ifdef USE_GETTEXT + /* + * Set up internationalized messages Jhobson 8/23/00 + * + * Do this after the AppInitialize since setlocale is setup by + * XtSetLanguageProc, but does not occur until XtAppInitialize happens. + */ + textdomain("xfontsel"); + + { + const char *domaindir; + + if ((domaindir = getenv("TEXTDOMAINDIR")) == NULL) { + domaindir = LOCALEDIR; + } + bindtextdomain("xfontsel", domaindir); + } +#endif + if (argc != 1) Syntax(argv[0]); XtAppAddActions(appCtx, xfontsel_actions, XtNumber(xfontsel_actions)); @@ -272,12 +325,16 @@ main(int argc, char **argv) XtGetApplicationResources( topLevel, (XtPointer)&AppRes, resources, XtNumber(resources), NZ ); if (AppRes.app_defaults_version < MIN_APP_DEFAULTS_VERSION) { + char full_message[300]; XrmDatabase rdb = XtDatabase(XtDisplay(topLevel)); - XtWarning( "app-defaults file not properly installed." ); - XrmPutLineResource( &rdb, -"*sampleText*UCSLabel:XFontSel app-defaults file not properly installed;\\n\ -see 'xfontsel' manual page." - ); + + XtWarning(gettext("app-defaults file not properly installed.")); + + snprintf(full_message, sizeof(full_message), + "*sampleText*UCSLabel:%s", + gettext("XFontSel app-defaults file not properly installed;\\n" + "see 'xfontsel' manual page.")); + XrmPutLineResource(&rdb, full_message); } ScheduleWork(GetFontNames, (XtPointer)topLevel, 0); @@ -519,7 +576,7 @@ void GetFontNames(XtPointer closure) } else XtAppWarning( appCtx, - "internal error; pattern didn't match first font" ); + gettext("internal error; pattern didn't match first font" )); } else { SetNoFonts(); @@ -1056,11 +1113,11 @@ static void SetCurrentFontCount(void) char label[80]; Arg args[1]; if (matchingFontCount == 1) - strcpy( label, "1 name matches" ); + strcpy( label, gettext("1 name matches") ); else if (matchingFontCount) - snprintf( label, sizeof(label), "%d names match", matchingFontCount ); + snprintf( label, sizeof(label), gettext("%d names match"), matchingFontCount); else - strcpy( label, "no names match" ); + strcpy( label, gettext("no names match") ); XtSetArg( args[0], XtNlabel, label ); XtSetValues( countLabel, args, ONE ); } @@ -1071,9 +1128,9 @@ static void SetParsingFontCount(int count) char label[80]; Arg args[1]; if (count == 1) - strcpy( label, "1 name to parse" ); + strcpy( label, gettext("1 name to parse") ); else - snprintf( label, sizeof(label), "%d names to parse", count ); + snprintf( label, sizeof(label), gettext("%d names to parse"), count ); XtSetArg( args[0], XtNlabel, label ); XtSetValues( countLabel, args, ONE ); FlushXqueue(XtDisplay(countLabel)); @@ -1279,9 +1336,9 @@ void SelectField(Widget w, XtPointer closure, XtPointer callData) int field = (long)closure; FieldValue *values = fieldValues[field]->value; int count = fieldValues[field]->count; - printf( "field %d:\n", field ); + printf(gettext("field %d:\n"), field ); while (count--) { - printf( " %s: %d fonts\n", values->string, values->count ); + printf( gettext(" %s: %d fonts\n"), values->string, values->count ); values++; } printf( "\n" ); |