E-MailRelay

ggettext.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 Graeme Walker <graeme_walker@users.sourceforge.net>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16// ===
17///
18/// \file ggettext.h
19///
20
21#ifndef G_GETTEXT_H
22#define G_GETTEXT_H
23
24#include "gdef.h"
25#include <string>
26#include <clocale>
27
28#if GCONFIG_HAVE_GETTEXT
29#include <libintl.h>
30#endif
31
32 namespace G
33{
34 void gettext_init( const std::string & localedir , const std::string & name ) ;
35 ///< Initialises the gettext() library. This uses environment variables
36 ///< to set the CTYPE and MESSAGES facets of the global C locale as a
37 ///< side-effect.
38
39 constexpr const char * gettext_noop( const char * p ) ;
40 ///< Marks a string for translation at build-time, but no translation is
41 ///< applied at run-time.
42
43 const char * gettext( const char * ) ;
44 ///< Returns the message translation in the current locale's codeset,
45 ///< eg. ISO8859-1 or UTF-8, transcoding from the catalogue as
46 ///< necessary.
47}
48
49#if GCONFIG_HAVE_GETTEXT
50 inline void G::gettext_init( const std::string & localedir , const std::string & appname )
51{
52 if( !appname.empty() )
53 {
54 std::setlocale( LC_MESSAGES , "" ) ;
55 std::setlocale( LC_CTYPE , "" ) ;
56 if( !localedir.empty() )
57 bindtextdomain( appname.c_str() , localedir.c_str() ) ;
58 textdomain( appname.c_str() ) ;
59 }
60}
61 inline const char * G::gettext( const char * p )
62{
63 return ::gettext( p ) ;
64}
65#else
66 inline void G::gettext_init( const std::string & , const std::string & )
67{
68}
69 inline const char * G::gettext( const char * p )
70{
71 return p ;
72}
73#endif
74
75 constexpr const char * G::gettext_noop( const char * p )
76{
77 return p ;
78}
79
80#endif
G
Low-level classes.
Definition: galign.h:28
G::gettext_noop
constexpr const char * gettext_noop(const char *p)
Marks a string for translation at build-time, but no translation is applied at run-time.
Definition: ggettext.h:75
G::gettext
const char * gettext(const char *)
Returns the message translation in the current locale's codeset, eg.
Definition: ggettext.h:69
G::gettext_init
void gettext_init(const std::string &localedir, const std::string &name)
Initialises the gettext() library.
Definition: ggettext.h:66