The Battle for Wesnoth  1.15.6+dev
gettext.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 /**
18  * How to use gettext for wesnoth source files:
19  * -# include this header file in the .cpp file
20  * -# make sure, that the source file is listed in the respective POTFILES.in
21  * for the textdomain, in the case of wesnoth-lib it is this file:
22  * po/wesnoth-lib/POTFILES.in
23  * -# add the following include to set the correct textdomain, in this example
24  * wesnoth-lib (not required for the domain 'wesnoth', required for all
25  * other textdomains).
26  * @code
27  * #define GETTEXT_DOMAIN "wesnoth-lib"
28  * @endcode
29  *
30  * This should be all that is required to have your strings that are marked
31  * translatable in the po files and translated ingame. So you at least have
32  * to mark the strings translatable, too. ;)
33  */
34 
35 // gettext-related declarations
36 #include "wesconfig.h"
37 #include <string>
38 #include <vector>
39 #include <ctime>
40 #include <boost/locale.hpp>
41 
42 #ifndef GETTEXT_DOMAIN
43 # define GETTEXT_DOMAIN PACKAGE
44 #endif
45 
46 //A Hack to make the eclipse-cdt parser happy.
47 #ifdef __CDT_PARSER__
48 # define GETTEXT_DOMAIN ""
49 #endif
50 
51 #ifdef HAVE_CXX17
52 #define UNUSEDNOWARN [[maybe_unused]]
53 #elif defined(__GNUCC__) || defined(__clang__) || defined(__MINGW32__)
54 #define UNUSEDNOWARN __attribute__((unused))
55 #else
56 #define UNUSEDNOWARN
57 #endif
58 
59 namespace translation
60 {
61  std::string dgettext(const char* domain, const char* msgid);
62  std::string egettext(const char*);
63  std::string dsgettext(const char * domainname, const char *msgid);
64  //const char* sngettext(const char *singular, const char *plural, int n);
65  std::string dsngettext(const char * domainname, const char *singular, const char *plural, int n);
66 
67  UNUSEDNOWARN inline static std::string gettext(const char* str)
68  { return translation::dgettext(GETTEXT_DOMAIN, str); }
69  UNUSEDNOWARN inline static std::string sgettext(const char* str)
70  { return translation::dsgettext(GETTEXT_DOMAIN, str); }
71  UNUSEDNOWARN inline static std::string sngettext(const char* str1, const char* str2, int n)
72  { return translation::dsngettext(GETTEXT_DOMAIN, str1, str2 , n); }
73 
74 
75  void bind_textdomain(const char* domain, const char* directory, const char* encoding);
76  void set_default_textdomain(const char* domain);
77 
78  void set_language(const std::string& language, const std::vector<std::string>* alternates);
79 
80  /** Case-sensitive lexicographical comparison. */
81  int compare(const std::string& s1,const std::string& s2);
82 
83  /** Case-insensitive lexicographical comparison. */
84  int icompare(const std::string& s1,const std::string& s2);
85 
86  std::string strftime(const std::string& format, const std::tm* time);
87 
88  bool ci_search(const std::string& s1, const std::string& s2);
89 
90  /**
91  * A facet that holds general information about the effective locale.
92  * This describes the actual translation target language,
93  * unlike language_def.localename in language.hpp, where the "System
94  * default language" is represented by an empty string.
95  */
97 }
98 
99 //#define _(String) translation::dsgettext(GETTEXT_DOMAIN,String)
100 UNUSEDNOWARN inline static std::string _(const char* str)
101 { return translation::dsgettext(GETTEXT_DOMAIN, str); }
102 
103 //#define _n(String1, String2, Int) translation::dsngettext(GETTEXT_DOMAIN, String1,String2,Int)
104 UNUSEDNOWARN inline static std::string _n(const char* str1, const char* str2, int n)
105 { return translation::dsngettext(GETTEXT_DOMAIN, str1, str2, n); }
106 
107 #define gettext_noop(String) String
108 #define N_(String) gettext_noop (String)
void bind_textdomain(const char *domain, const char *directory, const char *)
Definition: gettext.cpp:431
#define UNUSEDNOWARN
Definition: gettext.hpp:56
logger & info()
Definition: log.cpp:91
int compare(const std::string &s1, const std::string &s2)
Case-sensitive lexicographical comparison.
Definition: gettext.cpp:457
void set_language(const std::string &language, const std::vector< std::string > *)
Definition: gettext.cpp:448
std::string dsngettext(const char *domainname, const char *singular, const char *plural, int n)
Definition: gettext.cpp:416
std::string dgettext(const char *domain, const char *msgid)
Definition: gettext.cpp:392
std::string str
Definition: statement.cpp:110
std::string dsgettext(const char *domainname, const char *msgid)
Definition: gettext.cpp:403
std::string strftime(const std::string &format, const std::tm *time)
Definition: gettext.cpp:507
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:100
static UNUSEDNOWARN std::string _n(const char *str1, const char *str2, int n)
Definition: gettext.hpp:104
void set_default_textdomain(const char *domain)
Definition: gettext.cpp:440
static UNUSEDNOWARN std::string gettext(const char *str)
Definition: gettext.hpp:67
std::string egettext(char const *msgid)
Definition: gettext.cpp:397
bool ci_search(const std::string &s1, const std::string &s2)
Definition: gettext.cpp:518
Some defines: VERSION, PACKAGE, MIN_SAVEGAME_VERSION.
#define GETTEXT_DOMAIN
How to use gettext for wesnoth source files:include this header file in the .cpp filemake sure...
Definition: gettext.hpp:43
std::string language()
Definition: general.cpp:474
int icompare(const std::string &s1, const std::string &s2)
Case-insensitive lexicographical comparison.
Definition: gettext.cpp:475
static UNUSEDNOWARN std::string sgettext(const char *str)
Definition: gettext.hpp:69
static UNUSEDNOWARN std::string sngettext(const char *str1, const char *str2, int n)
Definition: gettext.hpp:71
static map_location::DIRECTION n
const boost::locale::info & get_effective_locale_info()
A facet that holds general information about the effective locale.
Definition: gettext.cpp:530