The Battle for Wesnoth  1.13.11+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 #if defined(__GNUCC__) || defined(__clang__) || defined(__MINGW32__)
51 #define UNUSEDNOWARN __attribute__((unused))
52 #else
53 #define UNUSEDNOWARN
54 #endif
55 
56 namespace translation
57 {
58  std::string dgettext(const char* domain, const char* msgid);
59  std::string egettext(const char*);
60  std::string dsgettext(const char * domainname, const char *msgid);
61  //const char* sngettext(const char *singular, const char *plural, int n);
62  std::string dsngettext(const char * domainname, const char *singular, const char *plural, int n);
63 
64  inline UNUSEDNOWARN static std::string gettext(const char* str)
65  { return translation::dgettext(GETTEXT_DOMAIN, str); }
66  inline UNUSEDNOWARN static std::string sgettext(const char* str)
67  { return translation::dsgettext(GETTEXT_DOMAIN, str); }
68  inline UNUSEDNOWARN static std::string sngettext(const char* str1, const char* str2, int n)
69  { return translation::dsngettext(GETTEXT_DOMAIN, str1, str2 , n); }
70 
71 
72  void bind_textdomain(const char* domain, const char* directory, const char* encoding);
73  void set_default_textdomain(const char* domain);
74 
75  void set_language(const std::string& language, const std::vector<std::string>* alternates);
76 
77  void init();
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 inline static UNUSEDNOWARN 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 inline UNUSEDNOWARN 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)
std::vector< char_t > string
#define UNUSEDNOWARN
Definition: gettext.hpp:53
std::string egettext(const char *)
int compare(const std::string &s1, const std::string &s2)
Case-sensitive lexicographical comparison.
void set_language(const std::string &language, const std::vector< std::string > *alternates)
std::string dsngettext(const char *domainname, const char *singular, const char *plural, int n)
std::string dgettext(const char *domain, const char *msgid)
void init()
Some tasks to run on startup.
std::string dsgettext(const char *domainname, const char *msgid)
void bind_textdomain(const char *domain, const char *directory, const char *encoding)
std::string strftime(const std::string &format, const std::tm *time)
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)
static UNUSEDNOWARN std::string gettext(const char *str)
Definition: gettext.hpp:64
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.
static UNUSEDNOWARN std::string sgettext(const char *str)
Definition: gettext.hpp:66
static UNUSEDNOWARN std::string sngettext(const char *str1, const char *str2, int n)
Definition: gettext.hpp:68
static map_location::DIRECTION n