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 /xfontsel.c | |
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>
Diffstat (limited to 'xfontsel.c')
-rw-r--r-- | xfontsel.c | 85 |
1 files changed, 71 insertions, 14 deletions
@@ -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" ); |