1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[gettext] try system gettext. Refs #62

Now, only meson was changed.
-Dnls=true -Dgettext=true
This commit is contained in:
Witold Filipczyk 2021-08-08 21:25:08 +02:00
parent 86edf56482
commit 66305fcb50
141 changed files with 548 additions and 140 deletions

View File

@ -82,14 +82,18 @@
/* Define if you want: FTP protocol support */
#mesondefine CONFIG_FTP
/* Define if you want: Gemini protocol support */
#mesondefine CONFIG_GEMINI
/* Define to 1 if you want libc gettext. */
#mesondefine CONFIG_GETTEXT
/* Define if you want: Global history support */
#mesondefine CONFIG_GLOBHIST
/* Define if you want: GNUTLS support */
#mesondefine CONFIG_GNUTLS
/* Define if you want: Gemini protocol support */
#mesondefine CONFIG_GEMINI
/* Define if you want: Gopher protocol support */
#mesondefine CONFIG_GOPHER

View File

@ -17,6 +17,7 @@ conf_data.set('CONFIG_BOOKMARKS', get_option('bookmarks'))
conf_data.set('CONFIG_XBEL_BOOKMARKS', get_option('xbel'))
conf_data.set('CONFIG_SCRIPTING_SPIDERMONKEY', get_option('sm-scripting'))
conf_data.set('CONFIG_NLS', get_option('nls'))
conf_data.set('CONFIG_GETTEXT', get_option('gettext'))
conf_data.set('CONFIG_COOKIES', get_option('cookies'))
conf_data.set('CONFIG_FORMHIST', get_option('formhist'))

View File

@ -62,3 +62,4 @@ option('libevent', type: 'boolean', value: false, description: 'compile with lib
option('x', type: 'boolean', value: false, description: 'use the X Window System')
option('xml', type: 'boolean', value: false, description: 'libxml++')
option('gemini', type: 'boolean', value: false, description: 'gemini protocol support')
option('gettext', type: 'boolean', value: false, description: 'use external gettext library')

View File

@ -10,7 +10,7 @@
#include "bfu/button.h"
#include "bfu/dialog.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "terminal/draw.h"
#include "terminal/mouse.h"
#include "terminal/terminal.h"

View File

@ -10,7 +10,7 @@
#include "bfu/checkbox.h"
#include "bfu/dialog.h"
#include "bfu/text.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "terminal/draw.h"
#include "terminal/mouse.h"
#include "terminal/terminal.h"

View File

@ -13,7 +13,7 @@
#include "config/kbdbind.h"
#include "config/options.h"
#include "intl/charsets.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "terminal/draw.h"
#include "main/timer.h"
#include "terminal/kbd.h"

View File

@ -11,7 +11,7 @@
#include "bfu/dialog.h"
#include "bfu/button.h"
#include "bfu/group.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "terminal/draw.h"
#include "terminal/terminal.h"
#include "util/color.h"

View File

@ -16,7 +16,7 @@
#include "bfu/msgbox.h"
#include "bfu/text.h"
#include "config/kbdbind.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "protocol/uri.h"
#include "session/task.h"
#include "terminal/screen.h"

View File

@ -11,7 +11,7 @@
#include "bfu/hotkey.h"
#include "bfu/menu.h"
#include "config/kbdbind.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "terminal/draw.h"
#include "terminal/terminal.h"
#include "terminal/window.h"

View File

@ -18,7 +18,7 @@
#include "bfu/text.h"
#include "config/kbdbind.h"
#include "intl/charsets.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "osdep/osdep.h"
#include "session/session.h"
#include "terminal/draw.h"

View File

@ -18,7 +18,7 @@
#include "config/options.h"
#include "document/document.h"
#include "document/view.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "main/timer.h"
#include "session/session.h"

View File

@ -12,7 +12,7 @@
#include "bfu/hierbox.h"
#include "bfu/listbox.h"
#include "config/kbdbind.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "terminal/draw.h"
#include "terminal/mouse.h"
#include "terminal/terminal.h"

View File

@ -17,7 +17,7 @@
#include "bfu/inpfield.h"
#include "bfu/menu.h"
#include "config/kbdbind.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "session/session.h"
#include "terminal/draw.h"
#include "terminal/event.h"

View File

@ -12,7 +12,7 @@
#include "bfu/button.h"
#include "bfu/msgbox.h"
#include "bfu/text.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "terminal/terminal.h"
#include "util/color.h"
#include "util/memlist.h"

View File

@ -13,7 +13,7 @@
#include "bfu/dialog.h"
#include "bfu/text.h"
#include "config/kbdbind.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "terminal/draw.h"
#include "terminal/mouse.h"
#include "terminal/terminal.h"

View File

@ -11,7 +11,7 @@
#include "bfu/dialog.h"
#include "bfu/inphist.h"
#include "bfu/widget.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "terminal/terminal.h"
#include "util/error.h"

View File

@ -26,7 +26,7 @@
#include "bookmarks/backend/common.h"
#include "bookmarks/backend/xbel.h"
#include "intl/charsets.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "util/conv.h"
#include "util/lists.h"
#include "util/string.h"

View File

@ -18,7 +18,7 @@
#include "bookmarks/dialogs.h"
#include "config/home.h"
#include "config/options.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "main/object.h"
#include "protocol/uri.h"

View File

@ -18,7 +18,7 @@
#include "bookmarks/bookmarks.h"
#include "bookmarks/dialogs.h"
#include "dialogs/edit.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/object.h"
#include "protocol/uri.h"
#include "session/session.h"

2
src/cache/dialogs.c vendored
View File

@ -16,7 +16,7 @@
#include "cache/cache.h"
#include "cache/dialogs.h"
#include "dialogs/edit.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/object.h"
#include "protocol/uri.h"
#include "session/session.h"

View File

@ -34,7 +34,7 @@
#include "config/conf.h"
#include "config/options.h"
#include "config/opttypes.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "network/dns.h"
#include "protocol/uri.h"
#include "session/session.h"

View File

@ -25,7 +25,7 @@
#include "config/kbdbind.h"
#include "config/options.h"
#include "config/opttypes.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "osdep/osdep.h"
#include "terminal/terminal.h"
#include "util/error.h"

View File

@ -18,7 +18,7 @@
#include "config/kbdbind.h"
#include "config/options.h"
#include "config/opttypes.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/event.h"
#include "main/object.h"
#include "session/session.h"

View File

@ -17,7 +17,7 @@
#include "config/home.h"
#include "config/options.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/main.h"
#include "osdep/osdep.h"
#include "util/memory.h"

View File

@ -14,7 +14,7 @@
#include "config/dialogs.h"
#include "config/kbdbind.h"
#include "config/options.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/event.h"
#include "main/module.h"
#include "terminal/kbd.h"

View File

@ -20,7 +20,7 @@
#include "document/document.h"
#include "globhist/globhist.h"
#include "intl/charsets.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/main.h" /* shrink_memory() */
#include "main/select.h"
#include "network/connection.h"

View File

@ -13,7 +13,7 @@
#include "config/options.h"
#include "config/opttypes.h"
#include "intl/charsets.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "util/color.h"
#include "util/conv.h"
#include "util/error.h"

View File

@ -8,7 +8,7 @@
#include "config/options.h"
#include "config/timer.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/event.h"
#include "main/module.h"
#include "main/timer.h"

View File

@ -8,7 +8,7 @@
#include "bfu/dialog.h"
#include "config/urlhist.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/event.h"
#include "main/module.h"
#include "util/lists.h"

View File

@ -25,7 +25,7 @@
#include "config/home.h"
#include "config/kbdbind.h"
#include "config/options.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "main/object.h"
#include "main/select.h"

View File

@ -21,7 +21,7 @@
#include "cookies/cookies.h"
#include "cookies/dialogs.h"
#include "dialogs/edit.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/object.h"
#include "session/session.h"
#include "terminal/draw.h"

View File

@ -17,7 +17,7 @@
#include "document/document.h"
#include "document/view.h"
#include "globhist/globhist.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "protocol/header.h"
#include "protocol/uri.h"
#include "session/location.h"

View File

@ -16,7 +16,7 @@
#include "dialogs/menu.h"
#include "dialogs/progress.h"
#include "dialogs/status.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/object.h"
#include "main/select.h"
#include "network/connection.h"

View File

@ -10,7 +10,7 @@
#include "bfu/dialog.h"
#include "dialogs/edit.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "session/session.h"
#include "terminal/terminal.h"
#include "util/color.h"

View File

@ -14,7 +14,7 @@
#include "config/kbdbind.h"
#include "config/options.h"
#include "dialogs/exmode.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "session/session.h"
#include "session/task.h"

View File

@ -20,7 +20,7 @@
#include "dialogs/info.h"
#include "document/renderer.h"
#include "ecmascript/ecmascript.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/select.h"
#include "main/timer.h"
#include "main/version.h"

View File

@ -20,7 +20,7 @@
#include "dialogs/info.h"
#include "dialogs/menu.h"
#include "dialogs/options.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/event.h"
#include "main/main.h"
#include "main/select.h"

View File

@ -16,7 +16,7 @@
#include "config/options.h"
#include "dialogs/options.h"
#include "intl/charsets.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "osdep/osdep.h"
#include "session/session.h"
#include "terminal/color.h"

View File

@ -8,7 +8,7 @@
#include "bfu/dialog.h"
#include "dialogs/progress.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "network/progress.h"
#include "terminal/draw.h"
#include "util/conv.h"

View File

@ -16,7 +16,7 @@
#include "document/document.h"
#include "document/renderer.h"
#include "document/view.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "network/connection.h"
#include "network/progress.h"
#include "network/state.h"

View File

@ -16,7 +16,7 @@
#include "document/css/parser.h"
#include "document/css/stylesheet.h"
#include "encoding/encoding.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "network/connection.h"
#include "protocol/uri.h"

View File

@ -18,7 +18,7 @@
#include "document/xml/renderer2.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/spidermonkey.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "main/select.h"
#include "main/timer.h"

View File

@ -38,7 +38,7 @@
#include "ecmascript/spidermonkey/screen.h"
#include "ecmascript/spidermonkey/unibar.h"
#include "ecmascript/spidermonkey/window.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/select.h"
#include "osdep/newwin.h"
#include "osdep/sysname.h"

View File

@ -19,7 +19,7 @@
#include "dialogs/status.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/spidermonkey/console.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "osdep/newwin.h"
#include "osdep/sysname.h"
#include "util/conv.h"

View File

@ -29,7 +29,7 @@
#include "ecmascript/spidermonkey/document.h"
#include "ecmascript/spidermonkey/element.h"
#include "ecmascript/spidermonkey/window.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/select.h"
#include "osdep/newwin.h"
#include "osdep/sysname.h"

View File

@ -25,7 +25,7 @@
#include "ecmascript/ecmascript.h"
#include "ecmascript/spidermonkey/element.h"
#include "ecmascript/spidermonkey/window.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/select.h"
#include "osdep/newwin.h"
#include "osdep/sysname.h"

View File

@ -27,7 +27,7 @@
#include "ecmascript/spidermonkey/document.h"
#include "ecmascript/spidermonkey/form.h"
#include "ecmascript/spidermonkey/window.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/select.h"
#include "osdep/newwin.h"
#include "osdep/sysname.h"

View File

@ -29,7 +29,7 @@
#include "ecmascript/spidermonkey/localstorage-db.h"
#include "ecmascript/spidermonkey/document.h"
#include "ecmascript/spidermonkey/window.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/select.h"
#include "osdep/newwin.h"
#include "osdep/sysname.h"

View File

@ -25,7 +25,7 @@
#include "ecmascript/ecmascript.h"
#include "ecmascript/spidermonkey/location.h"
#include "ecmascript/spidermonkey/window.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/select.h"
#include "osdep/newwin.h"
#include "osdep/sysname.h"

View File

@ -23,7 +23,7 @@
#include "document/view.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/spidermonkey/navigator.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/select.h"
#include "osdep/newwin.h"
#include "osdep/sysname.h"

View File

@ -25,7 +25,7 @@
#include "ecmascript/ecmascript.h"
#include "ecmascript/spidermonkey/screen.h"
#include "ecmascript/spidermonkey/window.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/select.h"
#include "osdep/newwin.h"
#include "osdep/sysname.h"

View File

@ -25,7 +25,7 @@
#include "ecmascript/ecmascript.h"
#include "ecmascript/spidermonkey/unibar.h"
#include "ecmascript/spidermonkey/window.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/select.h"
#include "osdep/newwin.h"
#include "osdep/sysname.h"

View File

@ -24,7 +24,7 @@
#include "document/view.h"
#include "ecmascript/ecmascript.h"
#include "ecmascript/spidermonkey/window.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/select.h"
#include "osdep/newwin.h"
#include "osdep/sysname.h"

View File

@ -13,7 +13,7 @@
#include "formhist/formhist.h"
#include "dialogs/edit.h"
#include "document/forms.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/object.h"
#include "protocol/uri.h"
#include "session/session.h"

View File

@ -13,7 +13,7 @@
#include "document/forms.h"
#include "formhist/dialogs.h"
#include "formhist/formhist.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "main/object.h"
#include "session/session.h"

View File

@ -13,7 +13,7 @@
#include "dialogs/edit.h"
#include "globhist/dialogs.h"
#include "globhist/globhist.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/object.h"
#include "protocol/uri.h"
#include "terminal/terminal.h"

View File

@ -20,7 +20,7 @@
#include "config/options.h"
#include "globhist/dialogs.h"
#include "globhist/globhist.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "main/object.h"
#include "main/select.h"

View File

@ -25,7 +25,7 @@
#include "elinks.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "intl/gettext/gettextP.h"
#include "util/string.h"

View File

@ -22,7 +22,7 @@
#include "elinks.h"
#include "intl/gettext/gettextP.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
/* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
locale. */

View File

@ -66,7 +66,7 @@ extern int errno;
#include "elinks.h"
#include "intl/gettext/gettextP.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "intl/gettext/hash-string.h"
#include "util/string.h"

View File

@ -22,7 +22,7 @@
#include "elinks.h"
#include "intl/gettext/gettextP.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
/* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
locale. */

View File

@ -22,7 +22,7 @@
#include "elinks.h"
#include "intl/gettext/gettextP.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
/* Look up MSGID in the DOMAINNAME message catalog of the current

View File

@ -32,7 +32,7 @@
#include "elinks.h"
#include "intl/gettext/gettextP.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "util/string.h"
/* List of already loaded domains. */

View File

@ -24,7 +24,7 @@
#include "elinks.h"
#include "intl/gettext/gettextP.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
/* Look up MSGID in the current default message catalog for the current

View File

@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "elinks.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "intl/gettext/gettextP.h"
/* This file redirects the gettext functions (without prefix or suffix) to

View File

@ -9,7 +9,7 @@
#include "elinks.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "intl/gettext/gettextP.h"
#include "util/error.h"
#include "util/memory.h"

View File

@ -24,7 +24,7 @@
#include "elinks.h"
#include "intl/gettext/gettextP.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
/* Look up MSGID in the current default message catalog for the current
LC_MESSAGES locale. If not found, returns MSGID itself (the default

View File

@ -24,7 +24,7 @@
#include "elinks.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "intl/gettext/gettextP.h"
#include "util/string.h"

235
src/intl/libintl.c Normal file
View File

@ -0,0 +1,235 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "elinks.h"
#include "intl/libintl.h"
/* The number of the charset to which the "elinks" domain was last
* bound with bind_textdomain_codeset(), or -1 if none yet. This
* cannot be a static variable in _(), because then it would get
* duplicated in every translation unit, even though the actual
* binding is global. */
int current_charset = -1;
/* This is a language lookup table. Indexed by code. */
/* Update this everytime you add a new translation. */
/* TODO: Try to autogenerate it somehow. Maybe just a complete table? Then we
* will anyway need a table of real translations. */
struct language languages[] = {
{N_("System"), "system"},
{N_("English"), "en_GB"},
{N_("Afrikaans"), "af_ZA"},
{N_("Belarusian"), "be_BY"},
{N_("Brazilian Portuguese"), "pt_BR"},
{N_("Bulgarian"), "bg_BG"},
{N_("Catalan"), "ca_ES"},
{N_("Croatian"), "hr_HR"},
{N_("Czech"), "cs_CZ"},
{N_("Danish"), "da_DK"},
{N_("Dutch"), "nl_NL"},
{N_("Estonian"), "et_EE"},
{N_("Finnish"), "fi_FI"},
{N_("French"), "fr_FR"},
{N_("Galician"), "gl_ES"},
{N_("German"), "de_DE"},
{N_("Greek"), "el_GR"},
{N_("Hungarian"), "hu_HU"},
{N_("Icelandic"), "is_IS"},
{N_("Indonesian"), "id_ID"},
{N_("Italian"), "it_IT"},
{N_("Japanese"), "ja_JP"},
{N_("Lithuanian"), "lt_LT"},
{N_("Norwegian"), "no_NO"},
{N_("Polish"), "pl_PL"},
{N_("Portuguese"), "pt_PT"},
{N_("Romanian"), "ro_RO"},
{N_("Russian"), "ru_RU"},
{N_("Serbian"), "sr_RS"},
{N_("Slovak"), "sk_SK"},
{N_("Spanish"), "es_ES"},
{N_("Swedish"), "sv_SE"},
{N_("Turkish"), "tr_TR"},
{N_("Ukrainian"), "uk_UA"},
{NULL, NULL},
};
/* XXX: In fact this is _NOT_ a real ISO639 code but RFC3066 code (as we're
* supposed to use that one when sending language tags through HTTP/1.1) and
* that one consists basically from ISO639[-ISO3166]. This is important for
* ie. pt vs pt-BR. */
/* TODO: We should reflect this in name of this function and of the tag. On the
* other side, it's ISO639 for gettext as well etc. So what? --pasky */
int
iso639_to_language(char *iso639)
{
char *l = stracpy(iso639);
char *p;
int i, ll;
if (!l)
return 1;
/* The environment variable transformation. */
p = strchr((const char *)l, '.');
if (p)
*p = '\0';
p = strchr((const char *)l, '_');
if (p)
*p = '-';
else
p = strchr((const char *)l, '-');
/* Exact match. */
for (i = 0; languages[i].name; i++) {
if (strcmp(languages[i].iso639, l))
continue;
mem_free(l);
return i;
}
/* Base language match. */
if (p) {
*p = '\0';
for (i = 0; languages[i].name; i++) {
if (strcmp(languages[i].iso639, l))
continue;
mem_free(l);
return i;
}
}
/* Any dialect match. */
ll = strlen(l);
for (i = 0; languages[i].name; i++) {
int il = strcspn(languages[i].iso639, "-");
if (strncmp(languages[i].iso639, l, il > ll ? ll : il))
continue;
mem_free(l);
return i;
}
/* Default to english. */
mem_free(l);
return 1;
}
int system_language = 0;
char *
language_to_iso639(int language)
{
/* Language is "system", we need to extract the index from
* the environment */
if (language == 0) {
return system_language ?
languages[system_language].iso639 :
languages[get_system_language_index()].iso639;
}
return languages[language].iso639;
}
int
name_to_language(const char *name)
{
int i;
for (i = 0; languages[i].name; i++) {
if (c_strcasecmp(languages[i].name, name))
continue;
return i;
}
return 1;
}
char *
language_to_name(int language)
{
return languages[language].name;
}
int
get_system_language_index(void)
{
char *l;
/* At this point current_language must be "system" yet. */
l = getenv("LANGUAGE");
if (!l)
l = getenv("LC_ALL");
if (!l)
l = getenv("LC_MESSAGES");
if (!l)
l = getenv("LANG");
return (l) ? iso639_to_language(l) : 1;
}
int current_language = 0;
char *EL_LANGUAGE;
void
set_language(int language)
{
char *p;
struct string lang;
int charset;
if (!system_language)
system_language = get_system_language_index();
if (language == current_language) {
/* Nothing to do. */
return;
}
current_language = language;
if (!language)
language = system_language;
if (!EL_LANGUAGE) {
/* We never free() this, purely intentionally. */
EL_LANGUAGE = malloc(256);
}
if (EL_LANGUAGE) {
strcpy(EL_LANGUAGE, language_to_iso639(language));
p = strchr((const char *)EL_LANGUAGE, '-');
if (p) {
*p = '_';
}
}
if (!init_string(&lang)) {
return;
}
add_to_string(&lang, "LC_ALL=");
add_to_string(&lang, EL_LANGUAGE);
putenv(lang.source);
done_string(&lang);
setlocale(LC_ALL, EL_LANGUAGE);
bindtextdomain(PACKAGE, LOCALEDIR);
charset = current_charset;
current_charset = -1;
intl_set_charset_by_index(charset);
textdomain(PACKAGE);
}

164
src/intl/libintl.h Normal file
View File

@ -0,0 +1,164 @@
#ifndef EL__INTL_LIBINTL_H
#define EL__INTL_LIBINTL_H
#include "config/options.h"
#include "intl/charsets.h"
#include "terminal/terminal.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef CONFIG_GETTEXT
#include <libintl.h>
extern int current_charset;
/* no-op - just for marking */
#define N_(msg) (gettext_noop(msg))
#define gettext_noop(Str) (Str)
#ifndef CONFIG_SMALL
#define N__(msg) (gettext_noop(msg))
#else
#define N__(msg) (NULL)
#endif
static inline void
intl_set_charset_by_index(int new_charset)
{
/* Prevent useless switching. */
if (current_charset != new_charset) {
bind_textdomain_codeset( /* PACKAGE */ "elinks",
get_cp_mime_name(new_charset));
current_charset = new_charset;
}
}
static inline void
intl_set_charset(struct terminal *term)
{
int new_charset = get_terminal_codepage(term);
intl_set_charset_by_index(new_charset);
}
#ifndef DEBUG_IT
/* Wraps around gettext(), employing charset multiplexing. If you don't care
* about charset (usually during initialization or when you don't use terminals
* at all), use gettext() directly. */
static inline char *
_(const char *msg, struct terminal *term)
{
/* Prevent useless (and possibly dangerous) calls. */
if (!msg || !*msg)
return (char *)msg;
if (term) intl_set_charset(term);
return (char *) gettext(msg);
}
#else
#include "util/error.h"
/* This one will emit errors on null/empty msgs and when multiple calls are
* done for the same result in the same function. Some noise is possible,
* when a function is called twice or more, but then we should cache msg,
* in function caller. --Zas */
/* __FUNCTION__ isn't supported by all, but it's debugging code. */
#define _(m, t) __(__FILE__, __LINE__, __FUNCTION__, m, t)
/* Overflows are theorically possible here. Debug purpose only. */
static inline char *
__(char *file, unsigned int line, char *func,
char *msg, struct terminal *term)
{
static char last_file[512] = "";
static unsigned int last_line = 0;
static char last_func[1024] = "";
static char last_result[16384] = "";
char *result;
/* Prevent useless (and possibly dangerous) calls. */
if (!msg || !*msg) {
ERROR("%s:%u %s msg parameter", file, line, msg ? "empty": "NULL");
return msg;
}
if (term) intl_set_charset(term);
result = (char *) gettext(msg);
if (!strcmp(result, last_result)
&& !strcmp(file, last_file)
&& !strcmp(func, last_func)) {
ERROR("%s:%u Duplicate call to _() in %s() (previous at line %u)",
file, line, func, last_line);
}
/* Risky ;) */
strcpy(last_file, file);
strcpy(last_func, func);
strcpy(last_result, result);
last_line = line;
return result;
}
#endif
/* For plural handling. */
/* Wraps around ngettext(), employing charset multiplexing. If you don't care
* about charset (usually during initialization or when you don't use terminals
* at all), use ngettext() directly. */
static inline char *
n_(char *msg1, char *msg2, unsigned long int n, struct terminal *term)
{
/* Prevent useless (and possibly dangerous) calls. */
if (!msg1 || !*msg1)
return msg1;
if (term) intl_set_charset(term);
return (char *) ngettext(msg1, msg2, n);
}
extern char *EL_LANGUAGE;
/* Languages table lookups. */
struct language {
char *name;
char *iso639;
};
extern struct language languages[];
/* These two calls return 1 (english) if the code/name wasn't found. */
extern int name_to_language(const char *name);
extern int iso639_to_language(char *iso639);
extern char *language_to_name(int language);
extern char *language_to_iso639(int language);
extern int get_system_language_index(void);
/* The current state. The state should be initialized by a set_language(0)
* call. */
extern int current_language, system_language;
extern void set_language(int language);
#else
#include "intl/gettext/libintl.h"
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,6 +1,9 @@
if conf_data.get('CONFIG_NLS')
if conf_data.get('CONFIG_GETTEXT')
srcs += files('libintl.c')
elif conf_data.get('CONFIG_NLS')
subdir('gettext')
endif
srcs += files('charsets.c')
if conf_data.get('CONFIG_UTF8')

View File

@ -41,7 +41,7 @@
#include "config/home.h"
#include "config/options.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/interlink.h"
#include "main/main.h"
#include "main/select.h"

View File

@ -27,7 +27,7 @@
#include "dialogs/menu.h"
#include "document/document.h"
#include "intl/charsets.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/event.h"
#include "main/interlink.h"
#include "main/main.h"

View File

@ -59,7 +59,7 @@ do { \
#include "elinks.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/main.h"
#include "main/select.h"
#include "main/timer.h"

View File

@ -13,7 +13,7 @@
#include "elinks.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "main/version.h"
#include "terminal/terminal.h"

View File

@ -9,7 +9,7 @@
#include "elinks.h"
#include "config/options.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "mime/backend/common.h"
#include "mime/backend/default.h"

View File

@ -27,7 +27,7 @@
#include "elinks.h"
#include "config/options.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "mime/backend/common.h"
#include "mime/backend/mailcap.h"

View File

@ -15,7 +15,7 @@
#include "elinks.h"
#include "config/options.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "mime/backend/common.h"
#include "mime/backend/mimetypes.h"

View File

@ -12,7 +12,7 @@
#include "bfu/menu.h"
#include "config/options.h"
#include "mime/dialogs.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "terminal/terminal.h"
#include "util/color.h"
#include "util/conv.h"

View File

@ -15,7 +15,7 @@
#include "cache/cache.h"
#include "config/options.h"
#include "encoding/encoding.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "mime/backend/common.h"
#include "mime/mime.h"

View File

@ -16,7 +16,7 @@
#include "config/options.h"
#include "document/document.h"
#include "encoding/encoding.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/object.h"
#include "main/select.h"
#include "main/timer.h"

View File

@ -23,7 +23,7 @@
#include "elinks.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "network/connection.h"
#include "network/socket.h"

View File

@ -8,7 +8,7 @@
#include "elinks.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "network/connection.h"
#include "network/state.h"
#include "terminal/terminal.h"

View File

@ -9,7 +9,7 @@
#include "elinks.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "osdep/newwin.h"
#include "osdep/osdep.h"
#include "terminal/terminal.h"

View File

@ -22,7 +22,7 @@
#include "elinks.h"
#include "config/options.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "osdep/osdep.h"
#include "osdep/win32/overrides.h"
#include "osdep/win32/vt100.h"

View File

@ -9,7 +9,7 @@
#include "elinks.h"
#include "bfu/hierbox.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "protocol/auth/auth.h"
#include "protocol/auth/dialogs.h"

View File

@ -11,7 +11,7 @@
#include "bfu/dialog.h"
#include "document/forms.h"
#include "formhist/formhist.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/object.h"
#include "protocol/auth/auth.h"
#include "protocol/auth/dialogs.h"

View File

@ -10,7 +10,7 @@
#include "elinks.h"
#include "config/options.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "network/state.h"
#include "protocol/bittorrent/bittorrent.h"

View File

@ -9,7 +9,7 @@
#include "dialogs/document.h"
#include "dialogs/download.h"
#include "dialogs/progress.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "mime/mime.h"
#include "network/connection.h"
#include "network/state.h"

View File

@ -20,7 +20,7 @@
#include "config/options.h"
#include "cookies/cookies.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "mime/backend/common.h"
#include "network/connection.h"
#include "network/progress.h"

View File

@ -22,7 +22,7 @@
#include "cache/cache.h"
#include "config/options.h"
#include "encoding/encoding.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "network/connection.h"
#include "network/socket.h"

View File

@ -20,7 +20,7 @@
#include "config/options.h"
#include "cookies/cookies.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "mime/backend/common.h"
#include "network/connection.h"
#include "network/progress.h"

View File

@ -7,7 +7,7 @@
#include "elinks.h"
#include "cache/cache.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "network/connection.h"
#include "network/socket.h"

View File

@ -32,7 +32,7 @@ extern "C" {
#include "cache/cache.h"
#include "config/options.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "main/select.h"
#include "network/connection.h"

View File

@ -33,7 +33,7 @@
#include "cache/cache.h"
#include "config/options.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/select.h"
#include "main/module.h"
#include "network/connection.h"

View File

@ -11,7 +11,7 @@
#include "elinks.h"
#include "cache/cache.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "network/connection.h"
#include "protocol/gemini/codes.h"
#include "protocol/uri.h"

View File

@ -16,7 +16,7 @@
#include "config/options.h"
#include "cookies/cookies.h"
#include "intl/charsets.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "network/connection.h"
#include "network/progress.h"

View File

@ -31,7 +31,7 @@
#include "elinks.h"
#include "cache/cache.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "network/connection.h"
#include "network/socket.h"

View File

@ -11,7 +11,7 @@
#include "elinks.h"
#include "cache/cache.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "network/connection.h"
#include "protocol/http/codes.h"
#include "protocol/uri.h"

View File

@ -16,7 +16,7 @@
#include "config/options.h"
#include "cookies/cookies.h"
#include "intl/charsets.h"
#include "intl/gettext/libintl.h"
#include "intl/libintl.h"
#include "main/module.h"
#include "network/connection.h"
#include "network/progress.h"

Some files were not shown because too many files have changed in this diff Show More