GRASS 8 Programmer's Manual
8.6.0dev(2026)-4bb960b182
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
const
char
*
gisbase
=
getenv
(
"GISBASE"
);
41
42
if
(
gisbase
&& *
gisbase
) {
43
char
localedir
[
GPATH_MAX
];
44
45
strcpy
(
localedir
,
gisbase
);
46
strcat
(
localedir
,
"/locale"
);
47
48
bindtextdomain
(
"grasslibs"
,
localedir
);
49
bindtextdomain
(
"grassmods"
,
localedir
);
50
}
51
#endif
52
53
G_initialize_done
(&initialized);
54
}
55
56
/**
57
* \brief Gets localized text.
58
*
59
* \param[in] package
60
* \param[in] msgid
61
* \retval char * Pointer to string
62
*/
63
char
*
G_gettext
(
const
char
*
package
NO_NLS_UNUSED
,
const
char
*
msgid
)
64
{
65
#if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
66
G_init_locale
();
67
68
return
dgettext
(
package
,
msgid
);
69
#else
70
return
(
char
*)
msgid
;
71
#endif
72
}
73
74
/**
75
* \brief Gets localized text with correct plural forms.
76
*
77
* \param[in] package
78
* \param[in] msgids A singular version of string
79
* \param[in] msgidp A plural version of string
80
* \param[in] n The number
81
* \retval char * Pointer to string
82
*/
83
char
*
G_ngettext
(
const
char
*
package
NO_NLS_UNUSED
,
const
char
*
msgids
,
84
const
char
*
msgidp
,
unsigned
long
int
n)
85
{
86
#if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
87
G_init_locale
();
88
89
return
dngettext
(
package
,
msgids
,
msgidp
, n);
90
#else
91
return
n == 1 ? (
char
*)
msgids
: (
char
*)
msgidp
;
92
#endif
93
}
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:196
glocale.h
G_gettext
char * G_gettext(const char *package, const char *msgid)
Gets localized text.
Definition
locale.c:63
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:83
G_init_locale
void G_init_locale(void)
Definition
locale.c:27
strcpy
#define strcpy
Definition
parson.c:66
stdlib.h
string.h
lib
gis
locale.c
Generated on Mon Sep 14 2026 06:57:43 for GRASS 8 Programmer's Manual by
1.9.8