GRASS GIS 8 Programmer's Manual
8.3.2(2024)-exported
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 GIS 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
66
char
*
G_gettext
(
const
char
*package
NO_NLS_UNUSED
,
const
char
*msgid)
67
{
68
#if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
69
G_init_locale
();
70
71
return
dgettext(package, msgid);
72
#else
73
return
(
char
*)msgid;
74
#endif
75
}
76
77
/**
78
* \brief Gets localized text with correct plural forms.
79
*
80
* \param[in] package
81
* \param[in] msgids A singular version of string
82
* \param[in] msgidp A plural version of string
83
* \param[in] n The number
84
* \retval char * Pointer to string
85
*/
86
87
char
*
G_ngettext
(
const
char
*package
NO_NLS_UNUSED
,
const
char
*msgids,
88
const
char
*msgidp,
unsigned
long
int
n)
89
{
90
#if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
91
G_init_locale
();
92
93
return
dngettext(package, msgids, msgidp, n);
94
#else
95
return
n == 1 ? (
char
*)msgids : (
char
*)msgidp;
96
#endif
97
}
G_initialize_done
void G_initialize_done(int *p)
Definition
counter.c:77
G_is_initialized
int G_is_initialized(int *p)
Definition
counter.c:60
NO_NLS_UNUSED
#define NO_NLS_UNUSED
Definition
locale.c:26
G_init_locale
void G_init_locale(void)
Definition
locale.c:29
G_gettext
char * G_gettext(const char *package NO_NLS_UNUSED, const char *msgid)
Gets localized text.
Definition
locale.c:66
G_ngettext
char * G_ngettext(const char *package NO_NLS_UNUSED, const char *msgids, const char *msgidp, unsigned long int n)
Gets localized text with correct plural forms.
Definition
locale.c:87
gis
locale.c
Generated on Fri May 24 2024 09:06:59 for GRASS GIS 8 Programmer's Manual by
1.9.8