The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
gettext.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2003 - 2025
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#include "utils/span.hpp"
44
45#ifndef GETTEXT_DOMAIN
46# define GETTEXT_DOMAIN PACKAGE
47#endif
48
49//A Hack to make the eclipse-cdt parser happy.
50#ifdef __CDT_PARSER__
51# define GETTEXT_DOMAIN ""
52#endif
53
54namespace translation
55{
56 std::string dgettext(const char* domain, const char* msgid);
57 std::string egettext(const char*);
58 std::string dsgettext(const char * domainname, const char *msgid);
59 //const char* sngettext(const char *singular, const char *plural, int n);
60 std::string dsngettext(const char * domainname, const char *singular, const char *plural, int n);
61
62 [[maybe_unused]] inline static std::string gettext(const char* str)
64 [[maybe_unused]] inline static std::string sgettext(const char* str)
66 [[maybe_unused]] inline static std::string sngettext(const char* str1, const char* str2, int n)
67 { return translation::dsngettext(GETTEXT_DOMAIN, str1, str2 , n); }
68
69
70 void bind_textdomain(const char* domain, const char* directory, const char* encoding);
71 void set_default_textdomain(const char* domain);
72
73 void set_language(const std::string& language, const std::vector<std::string>* alternates);
74
75 /** Case-sensitive lexicographical comparison. */
76 int compare(const std::string& s1,const std::string& s2);
77
78 /** Case-insensitive lexicographical comparison. */
79 int icompare(const std::string& s1,const std::string& s2);
80
81 /** Case-insensitive search. @a s2 will be checked against @a s1. */
82 bool ci_search(const std::string& s1, const std::string& s2);
83
84 /** Case-insensitive search. @a s2 will be checked against any element of @a s1. */
85 bool ci_search(utils::span<const std::string> s1, const std::string& s2);
86
87 /**
88 * A facet that holds general information about the effective locale.
89 * This describes the actual translation target language,
90 * unlike language_def.localename in language.hpp, where the "System
91 * default language" is represented by an empty string.
92 */
93 const boost::locale::info& get_effective_locale_info();
94
95 /** Translates the passed timestamp and returns it in the requested format. */
96 std::string translate_timestamp(time_t time, std::string_view format = "%F %T");
97}
98
99//#define _(String) translation::dsgettext(GETTEXT_DOMAIN,String)
100[[maybe_unused]] inline static std::string _(const char* str)
102
103//#define _n(String1, String2, Int) translation::dsngettext(GETTEXT_DOMAIN, String1,String2,Int)
104[[maybe_unused]] 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)
109#define N_n(String1, String2) String1, String2
#define GETTEXT_DOMAIN
#define GETTEXT_DOMAIN
How to use gettext for wesnoth source files:
Definition gettext.hpp:46
static std::string _n(const char *str1, const char *str2, int n)
Definition gettext.hpp:104
static std::string _(const char *str)
Definition gettext.hpp:100
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:62
void bind_textdomain(const char *domain, const char *directory, const char *)
Definition gettext.cpp:479
std::string translate_timestamp(time_t time, std::string_view format)
Translates the passed timestamp and returns it in the requested format.
Definition gettext.cpp:577
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:572
std::string dgettext(const char *domain, const char *msgid)
Definition gettext.cpp:425
bool ci_search(const std::string &s1, const std::string &s2)
Case-insensitive search.
Definition gettext.cpp:559
static std::string sngettext(const char *str1, const char *str2, int n)
Definition gettext.hpp:66
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:64
static map_location::direction n
Some defines: VERSION, PACKAGE, MIN_SAVEGAME_VERSION.