GRASS 8 Programmer's Manual 8.6.0dev(2026)-79cd2b35f7
Loading...
Searching...
No Matches
locale.c
Go to the documentation of this file.
1/*!
2 * \file lib/gis/locale.c
3 *
4 * \brief GIS Library - Functions to handle locale.
5 *
6 * SPDX-FileCopyrightText: 2001-2014 GRASS Development Team
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 *
9 * \author GRASS Development Team
10 *
11 * \date 2004-2008
12 */
13
14#include <grass/config.h>
15#include <stdlib.h>
16#include <string.h>
17#include <locale.h>
18#include <grass/glocale.h>
19#include <grass/gis.h>
20
21#if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
22#define NO_NLS_UNUSED
23#else
24#define NO_NLS_UNUSED G_UNUSED
25#endif
26
27void G_init_locale(void)
28{
29 static int initialized;
30
31 if (G_is_initialized(&initialized))
32 return;
33
35
36#if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
37#ifdef LC_MESSAGES
39#endif
40 /* Not using G_locale_dir(): its G_fatal_error() would translate the
41 message and re-enter G_init_locale(), recursing without bound. */
42 const char *localedir = getenv("GRASS_LOCALEDIR");
43
44 if (localedir && *localedir) {
45 bindtextdomain("grasslibs", localedir);
46 bindtextdomain("grassmods", localedir);
47 }
48#endif
49
50 G_initialize_done(&initialized);
51}
52
53/**
54 * \brief Gets localized text.
55 *
56 * \param[in] package
57 * \param[in] msgid
58 * \retval char * Pointer to string
59 */
60char *G_gettext(const char *package NO_NLS_UNUSED, const char *msgid)
61{
62#if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
64
65 return dgettext(package, msgid);
66#else
67 return (char *)msgid;
68#endif
69}
70
71/**
72 * \brief Gets localized text with correct plural forms.
73 *
74 * \param[in] package
75 * \param[in] msgids A singular version of string
76 * \param[in] msgidp A plural version of string
77 * \param[in] n The number
78 * \retval char * Pointer to string
79 */
80char *G_ngettext(const char *package NO_NLS_UNUSED, const char *msgids,
81 const char *msgidp, unsigned long int n)
82{
83#if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
85
86 return dngettext(package, msgids, msgidp, n);
87#else
88 return n == 1 ? (char *)msgids : (char *)msgidp;
89#endif
90}
int G_is_initialized(int *)
Definition counter.c:60
void G_initialize_done(int *)
Definition counter.c:77
char * G_gettext(const char *package, const char *msgid)
Gets localized text.
Definition locale.c:60
#define NO_NLS_UNUSED
Definition locale.c:22
char * G_ngettext(const char *package, const char *msgids, const char *msgidp, unsigned long int n)
Gets localized text with correct plural forms.
Definition locale.c:80
void G_init_locale(void)
Definition locale.c:27