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