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
27
void
G_init_locale
(
void
)
28
{
29
static
int
initialized;
30
31
if
(
G_is_initialized
(&initialized))
32
return
;
33
34
setlocale
(
LC_CTYPE
,
""
);
35
36
#if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
37
#ifdef LC_MESSAGES
38
setlocale
(
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
*/
60
char
*
G_gettext
(
const
char
*
package
NO_NLS_UNUSED
,
const
char
*
msgid
)
61
{
62
#if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
63
G_init_locale
();
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
*/
80
char
*
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)
84
G_init_locale
();
85
86
return
dngettext
(
package
,
msgids
,
msgidp
, n);
87
#else
88
return
n == 1 ? (
char
*)
msgids
: (
char
*)
msgidp
;
89
#endif
90
}
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
glocale.h
G_gettext
char * G_gettext(const char *package, const char *msgid)
Gets localized text.
Definition
locale.c:60
NO_NLS_UNUSED
#define NO_NLS_UNUSED
Definition
locale.c:22
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:80
G_init_locale
void G_init_locale(void)
Definition
locale.c:27
stdlib.h
string.h
lib
gis
locale.c
Generated on Mon Oct 26 2026 06:57:50 for GRASS 8 Programmer's Manual by
1.9.8