The Battle for Wesnoth  1.17.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 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/info.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 namespace translation
52 {
53  std::string dgettext(const char* domain, const char* msgid);
54  std::string egettext(const char*);
55  std::string dsgettext(const char * domainname, const char *msgid);
56  //const char* sngettext(const char *singular, const char *plural, int n);
57  std::string dsngettext(const char * domainname, const char *singular, const char *plural, int n);
58 
59  [[maybe_unused]] inline static std::string gettext(const char* str)
60  { return translation::dgettext(GETTEXT_DOMAIN, str); }
61  [[maybe_unused]] inline static std::string sgettext(const char* str)
62  { return translation::dsgettext(GETTEXT_DOMAIN, str); }
63  [[maybe_unused]] inline static std::string sngettext(const char* str1, const char* str2, int n)
64  { return translation::dsngettext(GETTEXT_DOMAIN, str1, str2 , n); }
65 
66 
67  void bind_textdomain(const char* domain, const char* directory, const char* encoding);
68  void set_default_textdomain(const char* domain);
69 
70  void set_language(const std::string& language, const std::vector<std::string>* alternates);
71 
72  /** Case-sensitive lexicographical comparison. */
73  int compare(const std::string& s1,const std::string& s2);
74 
75  /** Case-insensitive lexicographical comparison. */
76  int icompare(const std::string& s1,const std::string& s2);
77 
78  std::string strftime(const std::string& format, const std::tm* time);
79 
80  bool ci_search(const std::string& s1, const std::string& s2);
81 
82  /**
83  * A facet that holds general information about the effective locale.
84  * This describes the actual translation target language,
85  * unlike language_def.localename in language.hpp, where the "System
86  * default language" is represented by an empty string.
87  */
89 }
90 
91 //#define _(String) translation::dsgettext(GETTEXT_DOMAIN,String)
92 [[maybe_unused]] inline static std::string _(const char* str)
93 { return translation::dsgettext(GETTEXT_DOMAIN, str); }
94 
95 //#define _n(String1, String2, Int) translation::dsngettext(GETTEXT_DOMAIN, String1,String2,Int)
96 [[maybe_unused]] inline static std::string _n(const char* str1, const char* str2, int n)
97 { return translation::dsngettext(GETTEXT_DOMAIN, str1, str2, n); }
98 
99 #define gettext_noop(String) String
100 #define N_(String) gettext_noop (String)
static std::string _n(const char *str1, const char *str2, int n)
Definition: gettext.hpp:96
void bind_textdomain(const char *domain, const char *directory, const char *)
Definition: gettext.cpp:429
logger & info()
Definition: log.cpp:88
int compare(const std::string &s1, const std::string &s2)
Case-sensitive lexicographical comparison.
Definition: gettext.cpp:455
void set_language(const std::string &language, const std::vector< std::string > *)
Definition: gettext.cpp:446
std::string dsngettext(const char *domainname, const char *singular, const char *plural, int n)
Definition: gettext.cpp:414
std::string dgettext(const char *domain, const char *msgid)
Definition: gettext.cpp:390
static std::string _(const char *str)
Definition: gettext.hpp:92
std::string dsgettext(const char *domainname, const char *msgid)
Definition: gettext.cpp:401
std::string strftime(const std::string &format, const std::tm *time)
Definition: gettext.cpp:505
void set_default_textdomain(const char *domain)
Definition: gettext.cpp:438
static std::string sngettext(const char *str1, const char *str2, int n)
Definition: gettext.hpp:63
std::string egettext(char const *msgid)
Definition: gettext.cpp:395
bool ci_search(const std::string &s1, const std::string &s2)
Definition: gettext.cpp:516
Some defines: VERSION, PACKAGE, MIN_SAVEGAME_VERSION.
static std::string gettext(const char *str)
Definition: gettext.hpp:59
#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:494
int icompare(const std::string &s1, const std::string &s2)
Case-insensitive lexicographical comparison.
Definition: gettext.cpp:473
static std::string sgettext(const char *str)
Definition: gettext.hpp:61
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:528