GRASS GIS 8 Programmer's Manual
8.2.1(2023)-exported
locale.c
Go to the documentation of this file.
1
2
/*!
3
* \file lib/gis/locale.c
4
*
5
* \brief GIS Library - Functions to handle locale.
6
*
7
* (C) 2001-2014 by the GRASS Development Team
8
*
9
* This program is free software under the GNU General Public License
10
* (>=v2). Read the file COPYING that comes with GRASS for details.
11
*
12
* \author GRASS GIS Development Team
13
*
14
* \date 2004-2008
15
*/
16
17
#include <grass/config.h>
18
#include <stdlib.h>
19
#include <string.h>
20
#include <locale.h>
21
#include <grass/glocale.h>
22
#include <grass/gis.h>
23
24
void
G_init_locale
(
void
)
25
{
26
static
int
initialized;
27
28
if
(
G_is_initialized
(&initialized))
29
return
;
30
31
setlocale(LC_CTYPE,
""
);
32
33
#if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
34
#ifdef LC_MESSAGES
35
setlocale(LC_MESSAGES,
""
);
36
#endif
37
const
char
*gisbase = getenv(
"GISBASE"
);
38
if
(gisbase && *gisbase) {
39
char
localedir[GPATH_MAX];
40
41
strcpy(localedir, gisbase);
42
strcat(localedir,
"/locale"
);
43
44
bindtextdomain(
"grasslibs"
, localedir);
45
bindtextdomain(
"grassmods"
, localedir);
46
}
47
#endif
48
49
G_initialize_done
(&initialized);
50
}
51
52
53
/**
54
* \brief Gets localized text.
55
*
56
* \param[in] package
57
* \param[in] msgid
58
* \retval char * Pointer to string
59
*/
60
61
char
*
G_gettext
(
const
char
*package,
const
char
*msgid)
62
{
63
#if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
64
G_init_locale
();
65
66
return
dgettext(package, msgid);
67
#else
68
return
(
char
*)msgid;
69
#endif
70
}
71
72
/**
73
* \brief Gets localized text with correct plural forms.
74
*
75
* \param[in] package
76
* \param[in] msgids A singular version of string
77
* \param[in] msgidp A plural version of string
78
* \param[in] n The number
79
* \retval char * Pointer to string
80
*/
81
82
char
*
G_ngettext
(
const
char
*package,
const
char
*msgids,
const
char
*msgidp,
unsigned
long
int
n)
83
{
84
#if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
85
G_init_locale
();
86
87
return
dngettext(package, msgids, msgidp, n);
88
#else
89
return
n == 1 ? (
char
*)msgids : (
char
*)msgidp;
90
#endif
91
}
G_is_initialized
int G_is_initialized(int *p)
Definition:
counter.c:59
G_initialize_done
void G_initialize_done(int *p)
Definition:
counter.c:76
G_gettext
char * G_gettext(const char *package, const char *msgid)
Gets localized text.
Definition:
locale.c:61
G_init_locale
void G_init_locale(void)
Definition:
locale.c:24
G_ngettext
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:82
gis
locale.c
Generated on Thu Mar 12 2026 13:17:54 for GRASS GIS 8 Programmer's Manual by
1.8.20