The Battle for Wesnoth  1.15.0-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 http://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 
41 #ifndef GETTEXT_DOMAIN
42 # define GETTEXT_DOMAIN PACKAGE
43 #endif
44 
45 //A Hack to make the eclipse-cdt parser happy.
46 #ifdef __CDT_PARSER__
47 # define GETTEXT_DOMAIN ""
48 #endif
49 
50 #ifdef HAVE_CXX17
51 #define UNUSEDNOWARN [[maybe_unused]]
52 #elif defined(__GNUCC__) || defined(__clang__) || defined(__MINGW32__)
53 #define UNUSEDNOWARN __attribute__((unused))
54 #else
55 #define UNUSEDNOWARN
56 #endif
57 
58 namespace translation
59 {
60  std::string dgettext(const char* domain, const char* msgid);
61  std::string egettext(const char*);
62  std::string dsgettext(const char * domainname, const char *msgid);
63  //const char* sngettext(const char *singular, const char *plural, int n);
64  std::string dsngettext(const char * domainname, const char *singular, const char *plural, int n);
65 
66  UNUSEDNOWARN inline static std::string gettext(const char* str)
67  { return translation::dgettext(GETTEXT_DOMAIN, str); }
68  UNUSEDNOWARN inline static std::string sgettext(const char* str)
69  { return translation::dsgettext(GETTEXT_DOMAIN, str); }
70  UNUSEDNOWARN inline static std::string sngettext(const char* str1, const char* str2, int n)
71  { return translation::dsngettext(GETTEXT_DOMAIN, str1, str2 , n); }
72 
73 
74  void bind_textdomain(const char* domain, const char* directory, const char* encoding);
75  void set_default_textdomain(const char* domain);
76 
77  void set_language(const std::string& language, const std::vector<std::string>* alternates);
78 
79  /** Case-sensitive lexicographical comparison. */
80  int compare(const std::string& s1,const std::string& s2);
81 
82  /** Case-insensitive lexicographical comparison. */
83  int icompare(const std::string& s1,const std::string& s2);
84 
85  std::string strftime(const std::string& format, const std::tm* time);
86 }
87 
88 //#define _(String) translation::dsgettext(GETTEXT_DOMAIN,String)
89 UNUSEDNOWARN inline static std::string _(const char* str)
90 { return translation::dsgettext(GETTEXT_DOMAIN, str); }
91 
92 //#define _n(String1, String2, Int) translation::dsngettext(GETTEXT_DOMAIN, String1,String2,Int)
93 UNUSEDNOWARN inline static std::string _n(const char* str1, const char* str2, int n)
94 { return translation::dsngettext(GETTEXT_DOMAIN, str1, str2, n); }
95 
96 #define gettext_noop(String) String
97 #define N_(String) gettext_noop (String)
void bind_textdomain(const char *domain, const char *directory, const char *)
Definition: gettext.cpp:432
#define UNUSEDNOWARN
Definition: gettext.hpp:55
int compare(const std::string &s1, const std::string &s2)
Case-sensitive lexicographical comparison.
Definition: gettext.cpp:458
void set_language(const std::string &language, const std::vector< std::string > *)
Definition: gettext.cpp:449
std::string dsngettext(const char *domainname, const char *singular, const char *plural, int n)
Definition: gettext.cpp:417
std::string dgettext(const char *domain, const char *msgid)
Definition: gettext.cpp:393
std::string dsgettext(const char *domainname, const char *msgid)
Definition: gettext.cpp:404
std::string strftime(const std::string &format, const std::tm *time)
Definition: gettext.cpp:508
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:89
static UNUSEDNOWARN std::string _n(const char *str1, const char *str2, int n)
Definition: gettext.hpp:93
void set_default_textdomain(const char *domain)
Definition: gettext.cpp:441
static UNUSEDNOWARN std::string gettext(const char *str)
Definition: gettext.hpp:66
std::string egettext(char const *msgid)
Definition: gettext.cpp:398
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:42
std::string language()
Definition: general.cpp:477
int icompare(const std::string &s1, const std::string &s2)
Case-insensitive lexicographical comparison.
Definition: gettext.cpp:476
static UNUSEDNOWARN std::string sgettext(const char *str)
Definition: gettext.hpp:68
static UNUSEDNOWARN std::string sngettext(const char *str1, const char *str2, int n)
Definition: gettext.hpp:70
static map_location::DIRECTION n