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