From 3f478b6cd3041b85891ff4a3ef1a141f85f82e49 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 2 Jun 2023 14:02:53 -0700 Subject: [PATCH] propername-lite: new module propername_lite acts like propername_utf8 but needs less infrastructure, e.g., it does not worry about memory allocation. * MODULES.html.sh (func_all_modules): Mention it. * lib/propername.h (proper_name_lite): New decl. * lib/propername-lite.c, modules/propername-lite: New files. * pygnulib/GLEmiter.py (GLEmiter.po_Makevars): Treat proper_name_lite like proper_name_utf8. --- ChangeLog | 11 +++++++++++ MODULES.html.sh | 1 + lib/propername-lite.c | 36 ++++++++++++++++++++++++++++++++++++ lib/propername.h | 32 +++++++++++++++++++++++++++++--- modules/propername-lite | 27 +++++++++++++++++++++++++++ pygnulib/GLEmiter.py | 1 + 6 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 lib/propername-lite.c create mode 100644 modules/propername-lite diff --git a/ChangeLog b/ChangeLog index bcf84672b5..f93c5e3ad2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2023-06-02 Paul Eggert + + propername-lite: new module + propername_lite acts like propername_utf8 but needs less + infrastructure, e.g., it does not worry about memory allocation. + * MODULES.html.sh (func_all_modules): Mention it. + * lib/propername.h (proper_name_lite): New decl. + * lib/propername-lite.c, modules/propername-lite: New files. + * pygnulib/GLEmiter.py (GLEmiter.po_Makevars): + Treat proper_name_lite like proper_name_utf8. + 2023-06-02 Bruno Haible openmp-init: Silence "no previous prototype for 'openmp_init'" warning. diff --git a/MODULES.html.sh b/MODULES.html.sh index 01d8762fe5..b5c741cf86 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -3041,6 +3041,7 @@ func_all_modules () func_module gettext func_module gettext-h func_module propername + func_module propername-lite func_module iconv func_module striconv func_module xstriconv diff --git a/lib/propername-lite.c b/lib/propername-lite.c new file mode 100644 index 0000000000..49436001ca --- /dev/null +++ b/lib/propername-lite.c @@ -0,0 +1,36 @@ +/* Localization of proper names. + Copyright 2023 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include "propername.h" + +#include "c-strcase.h" +#include "gettext.h" +#include "localcharset.h" + +/* Return the localization of the name spelled NAME_ASCII in ASCII, + and NAME_UTF8 in UTF-8. */ + +char const * +proper_name_lite (char const *name_ascii, char const *name_utf8) +{ + char const *translation = gettext (name_ascii); + return (translation != name_ascii ? translation + : c_strcasecmp (locale_charset (), "UTF-8") == 0 ? name_utf8 + : name_ascii); +} diff --git a/lib/propername.h b/lib/propername.h index 359c8b57ff..eced2e86da 100644 --- a/lib/propername.h +++ b/lib/propername.h @@ -45,11 +45,14 @@ ... Written by Danilo Segan and Bruno Haible. - The 'propername' module does exactly this. Plus, for languages that use - a different writing system than the Latin alphabet, it allows a translator + The 'propername' and 'propername-lite’ modules do this. Plus, for + languages that do not use the Latin alphabet, they allow a translator to write the name using that different writing system. In that case the - output will look like this: + propername and propername_utf8 output will look like this: () + whereas the propername_lite output will just be the translated name + if available, otherwise the original name (in UTF-8 if possible and + in ASCII if not). To use the 'propername' module requires two simple steps: @@ -62,12 +65,29 @@ from "Torbjorn Granlund" to proper_name_utf8 ("Torbjorn Granlund", "Torbj\303\266rn Granlund") + or proper_name_lite ("Torbjorn Granlund", "Torbj\303\266rn Granlund") from "F. Pinard" to proper_name_utf8 ("Franc,ois Pinard", "Fran\303\247ois Pinard") + or proper_name_lite ("Franc,ois Pinard", "Fran\303\247ois Pinard") + + In source code, the second argument of proper_name_lite and + proper_name_utf8 should use octal escapes, not UTF-8 - e.g., + "Fran\303\247ois Pinard", not "François Pinard". Doing it + this way can avoid mishandling non-ASCII characters if the + source is recoded to non-UTF8, or if the compiler does not + treat UTF-8 as-is in character string contents. (Optionally, here you can also add / * TRANSLATORS: ... * / comments explaining how the name is written or pronounced.) + + Here is an example in context. + + printf (_("Written by %s and %s.\n"), + / * TRANSLATORS: This is the proper name "Danilo Šegan". + In the original Cyrillic it is "Данило Шеган". * / + proper_name_utf8 ("Danilo Segan", "Danilo \305\240egan"), + proper_name ("Bruno Haible")); */ #ifndef _PROPERNAME_H @@ -88,6 +108,12 @@ extern const char * proper_name (const char *name) /* NOT attribute const */; extern const char * proper_name_utf8 (const char *name_ascii, const char *name_utf8); +/* Return the localization of the name spelled NAME_ASCII in ASCII, + and NAME_UTF8 in UTF-8. This function needs less infrastructure + than proper_name and proper_name_utf8. */ +extern const char *proper_name_lite (const char *name_ascii, + const char *name_utf8); + #ifdef __cplusplus } #endif diff --git a/modules/propername-lite b/modules/propername-lite new file mode 100644 index 0000000000..53f0187238 --- /dev/null +++ b/modules/propername-lite @@ -0,0 +1,27 @@ +Description: +Lighter-weight localization of proper names. + +Files: +lib/propername-lite.c +lib/propername.h + +Depends-on: +localcharset +c-strcase +gettext-h + +configure.ac: +m4_ifdef([AM_XGETTEXT_OPTION], + [AM_][XGETTEXT_OPTION([--keyword='proper_name_lite:1,\"This is a proper name. See the gettext manual, section Names.\"'])]) + +Makefile.am: +lib_SOURCES += propername-lite.c propername.h + +Include: +"propername.h" + +License: +LGPL + +Maintainer: +all diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py index dc46ba89e9..7dec6fd0c3 100644 --- a/pygnulib/GLEmiter.py +++ b/pygnulib/GLEmiter.py @@ -405,6 +405,7 @@ XGETTEXT_OPTIONS = \\ --keyword=_ --flag=_:1:pass-c-format \\ --keyword=N_ --flag=N_:1:pass-c-format \\ --keyword='proper_name:1,"This is a proper name. See the gettext manual, section Names."' \\ + --keyword='proper_name_lite:1,"This is a proper name. See the gettext manual, section Names."' \\ --keyword='proper_name_utf8:1,"This is a proper name. See the gettext manual, section Names."' \\ --flag=error:3:c-format --flag=error_at_line:5:c-format -- 2.39.5