reorder gettext.hpp
We want to put all dependencies of linintl.h to getttext.cpp so we can easily replace gettext/libintl with boost locale gettext by replacing that file.
This commit is contained in:
parent
33becb6100
commit
c5cf699210
18 changed files with 99 additions and 79 deletions
|
@ -38,7 +38,6 @@
|
|||
#include "video.hpp" // for update_rect, CVideo
|
||||
#include "widgets/button.hpp" // for button
|
||||
|
||||
#include <libintl.h> // for gettext
|
||||
#include <algorithm> // for max
|
||||
#include <boost/foreach.hpp> // for auto_any_base, etc
|
||||
#include <boost/scoped_ptr.hpp> // for scoped_ptr
|
||||
|
@ -105,7 +104,7 @@ static void add_lines(std::vector<std::string> &res, config const &c, bool split
|
|||
if (!line.empty())
|
||||
{
|
||||
if (line[0] == '_')
|
||||
line = gettext(line.substr(1).c_str());
|
||||
line = translation::gettext(line.substr(1).c_str());
|
||||
res.push_back(line);
|
||||
}
|
||||
}
|
||||
|
@ -176,7 +175,7 @@ void set_about(const config &cfg)
|
|||
{
|
||||
text << '+';
|
||||
if (subtitle[0] == '_')
|
||||
text << gettext(subtitle.substr(1, subtitle.size() - 1).c_str());
|
||||
text << translation::gettext(subtitle.substr(1, subtitle.size() - 1).c_str());
|
||||
else
|
||||
text << subtitle;
|
||||
text << '\n';
|
||||
|
|
|
@ -226,7 +226,7 @@ std::string vgettext(const char *domain
|
|||
, const char *msgid
|
||||
, const utils::string_map& symbols)
|
||||
{
|
||||
const std::string orig(dgettext(domain, msgid));
|
||||
const std::string orig(translation::dgettext(domain, msgid));
|
||||
const std::string msg = utils::interpolate_variables_into_string(orig, &symbols);
|
||||
return msg;
|
||||
}
|
||||
|
|
|
@ -910,7 +910,7 @@ bool game_launcher::play_multiplayer()
|
|||
ERR_NET << "caught network::error: " << e.message << std::endl;
|
||||
gui2::show_transient_message(disp().video()
|
||||
, ""
|
||||
, gettext(e.message.c_str()));
|
||||
, translation::gettext(e.message.c_str()));
|
||||
} else {
|
||||
ERR_NET << "caught network::error" << std::endl;
|
||||
}
|
||||
|
|
|
@ -1701,11 +1701,11 @@ void show_preferences_dialog(display& disp, const config& game_cfg)
|
|||
|
||||
std::string const pre = IMAGE_PREFIX + std::string("icons/icon-");
|
||||
char const sep = COLUMN_SEPARATOR;
|
||||
items.push_back(pre + "general.png" + sep + sgettext("Prefs section^General"));
|
||||
items.push_back(pre + "display.png" + sep + sgettext("Prefs section^Display"));
|
||||
items.push_back(pre + "music.png" + sep + sgettext("Prefs section^Sound"));
|
||||
items.push_back(pre + "multiplayer.png" + sep + sgettext("Prefs section^Multiplayer"));
|
||||
items.push_back(pre + "advanced.png" + sep + sgettext("Advanced section^Advanced"));
|
||||
items.push_back(pre + "general.png" + sep + translation::sgettext("Prefs section^General"));
|
||||
items.push_back(pre + "display.png" + sep + translation::sgettext("Prefs section^Display"));
|
||||
items.push_back(pre + "music.png" + sep + translation::sgettext("Prefs section^Sound"));
|
||||
items.push_back(pre + "multiplayer.png" + sep + translation::sgettext("Prefs section^Multiplayer"));
|
||||
items.push_back(pre + "advanced.png" + sep + translation::sgettext("Advanced section^Advanced"));
|
||||
|
||||
for(;;) {
|
||||
try {
|
||||
|
|
|
@ -320,7 +320,7 @@ void default_map_generator::user_config(display& disp)
|
|||
slider_right + horz_margin, castlesize_rect.y);
|
||||
|
||||
std::stringstream landform_str;
|
||||
landform_str << gettext(island_size_ == 0 ? N_("Inland") : (island_size_ < max_coastal ? N_("Coastal") : N_("Island")));
|
||||
landform_str << translation::gettext(island_size_ == 0 ? N_("Inland") : (island_size_ < max_coastal ? N_("Coastal") : N_("Island")));
|
||||
font::draw_text(&screen,screen_area(),font::SIZE_NORMAL,font::NORMAL_COLOR,landform_str.str(),
|
||||
slider_right+horz_margin,landform_rect.y);
|
||||
|
||||
|
|
|
@ -12,20 +12,28 @@
|
|||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include <libintl.h>
|
||||
#include "global.hpp"
|
||||
|
||||
#include "gettext.hpp"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <cstring>
|
||||
namespace translation
|
||||
{
|
||||
const char* dgettext(const char* domain, const char* msgid)
|
||||
{
|
||||
return ::dgettext(domain, msgid);
|
||||
}
|
||||
char const *egettext(char const *msgid)
|
||||
{
|
||||
return msgid[0] == '\0' ? msgid : gettext(msgid);
|
||||
return msgid[0] == '\0' ? msgid : (::gettext)(msgid);
|
||||
}
|
||||
|
||||
const char* sgettext (const char *msgid)
|
||||
const char* dsgettext (const char * domainname, const char *msgid)
|
||||
{
|
||||
const char *msgval = gettext (msgid);
|
||||
bind_textdomain_codeset(domainname, "UTF-8");
|
||||
const char *msgval = dgettext (domainname, msgid);
|
||||
if (msgval == msgid) {
|
||||
msgval = std::strrchr (msgid, '^');
|
||||
if (msgval == NULL)
|
||||
|
@ -36,10 +44,11 @@ const char* sgettext (const char *msgid)
|
|||
return msgval;
|
||||
}
|
||||
|
||||
const char* dsgettext (const char * domainname, const char *msgid)
|
||||
#if 0
|
||||
|
||||
const char* sgettext (const char *msgid)
|
||||
{
|
||||
bind_textdomain_codeset(domainname, "UTF-8");
|
||||
const char *msgval = dgettext (domainname, msgid);
|
||||
const char *msgval = gettext (msgid);
|
||||
if (msgval == msgid) {
|
||||
msgval = std::strrchr (msgid, '^');
|
||||
if (msgval == NULL)
|
||||
|
@ -63,6 +72,7 @@ const char* sngettext (const char *singular, const char *plural, int n)
|
|||
return msgval;
|
||||
}
|
||||
|
||||
#endif
|
||||
const char* dsngettext (const char * domainname, const char *singular, const char *plural, int n)
|
||||
{
|
||||
bind_textdomain_codeset(domainname, "UTF-8");
|
||||
|
@ -76,3 +86,18 @@ const char* dsngettext (const char * domainname, const char *singular, const cha
|
|||
}
|
||||
return msgval;
|
||||
}
|
||||
|
||||
void bind_textdomain(const char* domain, const char* direcory, const char* encoding)
|
||||
{
|
||||
if(direcory != NULL)
|
||||
bindtextdomain(domain, direcory);
|
||||
if(encoding != NULL)
|
||||
bind_textdomain_codeset(domain, encoding);
|
||||
}
|
||||
|
||||
void set_default_textdomain(const char* domain)
|
||||
{
|
||||
textdomain(domain);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,39 +34,39 @@
|
|||
*/
|
||||
|
||||
// gettext-related declarations
|
||||
|
||||
#include <libintl.h>
|
||||
|
||||
#ifdef setlocale
|
||||
// Someone in libintl world decided it was a good idea to define a "setlocale" macro.
|
||||
#undef setlocale
|
||||
#endif
|
||||
|
||||
const char* egettext(const char*);
|
||||
const char* sgettext(const char*);
|
||||
const char* dsgettext(const char * domainname, const char *msgid);
|
||||
const char* sngettext(const char *singular, const char *plural, int n);
|
||||
const char* dsngettext(const char * domainname, const char *singular, const char *plural, int n);
|
||||
#include "wesconfig.h"
|
||||
|
||||
//A Hack to make the eclipse-cdt parser happy.
|
||||
#ifdef __CDT_PARSER__
|
||||
#define GETTEXT_DOMAIN ""
|
||||
#ifndef GETTEXT_DOMAIN
|
||||
# define GETTEXT_DOMAIN PACKAGE
|
||||
#endif
|
||||
|
||||
#ifdef GETTEXT_DOMAIN
|
||||
# define _(String) dsgettext(GETTEXT_DOMAIN,String)
|
||||
# define _n(String1,String2,Int) dsngettext(String1,String2,Int)
|
||||
# ifdef gettext
|
||||
# undef gettext
|
||||
# endif
|
||||
# define gettext(String) dgettext(GETTEXT_DOMAIN,String)
|
||||
# define sgettext(String) dsgettext(GETTEXT_DOMAIN,String)
|
||||
# define sngettext(String1,String2,Int) dsngettext(GETTEXT_DOMAIN,String1,String2,Int)
|
||||
#else
|
||||
# define _(String) sgettext(String)
|
||||
# define _n(String1,String2,Int) sngettext(String1,String2,Int)
|
||||
#ifdef __CDT_PARSER__
|
||||
# define GETTEXT_DOMAIN ""
|
||||
#endif
|
||||
|
||||
namespace translation
|
||||
{
|
||||
const char* dgettext(const char* domain, const char* msgid);
|
||||
const char* egettext(const char*);
|
||||
const char* dsgettext(const char * domainname, const char *msgid);
|
||||
//const char* sngettext(const char *singular, const char *plural, int n);
|
||||
const char* dsngettext(const char * domainname, const char *singular, const char *plural, int n);
|
||||
|
||||
static const char* gettext(const char* str)
|
||||
{ return translation::dgettext(GETTEXT_DOMAIN, str); }
|
||||
static const char* sgettext(const char* str)
|
||||
{ return translation::dsgettext(GETTEXT_DOMAIN, str); }
|
||||
static const char* sngettext(const char* str1, const char* str2, int n)
|
||||
{ return translation::dsngettext(GETTEXT_DOMAIN, str1, str2 , n); }
|
||||
|
||||
void bind_textdomain(const char* domain, const char* direcory, const char* encoding);
|
||||
void set_default_textdomain(const char* domain);
|
||||
}
|
||||
|
||||
#define _(String) translation::dsgettext(GETTEXT_DOMAIN,String)
|
||||
#define _n(String1, String2, Int) translation::dsngettext(GETTEXT_DOMAIN, String1,String2,Int)
|
||||
|
||||
#define gettext_noop(String) String
|
||||
#define N_(String) gettext_noop (String)
|
||||
|
||||
|
|
|
@ -1773,7 +1773,7 @@ public:
|
|||
|
||||
BOOST_FOREACH(const config & trait, traits) {
|
||||
const std::string trait_name = trait["male_name"];
|
||||
std::string lang_trait_name = gettext(trait_name.c_str());
|
||||
std::string lang_trait_name = translation::gettext(trait_name.c_str());
|
||||
const std::string ref_id = "traits_"+trait["id"].str();
|
||||
((trait["availability"].str() == "musthave") ? must_have_traits : random_traits).push_back(std::make_pair(lang_trait_name, ref_id));
|
||||
}
|
||||
|
@ -1818,7 +1818,7 @@ public:
|
|||
ability_end = type_.abilities().end();
|
||||
ability_it != ability_end; ++ability_it) {
|
||||
const std::string ref_id = "ability_" + ability_it->base_str();
|
||||
std::string lang_ability = gettext(ability_it->c_str());
|
||||
std::string lang_ability = translation::gettext(ability_it->c_str());
|
||||
ss << make_link(lang_ability, ref_id);
|
||||
if (ability_it + 1 != ability_end)
|
||||
ss << ", ";
|
||||
|
@ -1834,7 +1834,7 @@ public:
|
|||
ability_end = type_.adv_abilities().end();
|
||||
ability_it != ability_end; ++ability_it) {
|
||||
const std::string ref_id = "ability_" + ability_it->base_str();
|
||||
std::string lang_ability = gettext(ability_it->c_str());
|
||||
std::string lang_ability = translation::gettext(ability_it->c_str());
|
||||
ss << make_link(lang_ability, ref_id);
|
||||
if (ability_it + 1 != ability_end)
|
||||
ss << ", ";
|
||||
|
|
|
@ -214,13 +214,13 @@ void show_hotkeys_preferences_dialog(display& disp) {
|
|||
|
||||
// tab names and icons
|
||||
items.push_back(pre + "titlescreen.png" + sep
|
||||
+ sgettext("Prefs section^Title Screen"));
|
||||
+ translation::sgettext("Prefs section^Title Screen"));
|
||||
items.push_back(pre + "game.png" + sep
|
||||
+ sgettext("Prefs section^Game"));
|
||||
+ translation::sgettext("Prefs section^Game"));
|
||||
items.push_back(pre + "editor.png" + sep
|
||||
+ sgettext("Prefs section^Editor"));
|
||||
+ translation::sgettext("Prefs section^Editor"));
|
||||
items.push_back(pre + "general.png" + sep
|
||||
+ sgettext("Prefs section^General"));
|
||||
+ translation::sgettext("Prefs section^General"));
|
||||
|
||||
// determine the current scope, but skip general == 0
|
||||
int scope;
|
||||
|
|
|
@ -361,7 +361,7 @@ void loadscreen::start_stage(char const *id)
|
|||
|
||||
const load_stage &cs = stages[s];
|
||||
global_loadscreen->prcnt_ = cs.start_pos;
|
||||
global_loadscreen->draw_screen(gettext(cs.name));
|
||||
global_loadscreen->draw_screen(translation::gettext(cs.name));
|
||||
stage_counter[s] = 0;
|
||||
stage_time[s] = SDL_GetTicks();
|
||||
current_stage = s;
|
||||
|
|
|
@ -585,7 +585,7 @@ void menu_handler::recruit(int side_num, const map_location &last_hex)
|
|||
<< team::get_side_color_index(side_num) << ')';
|
||||
#endif
|
||||
description << COLUMN_SEPARATOR << font::LARGE_TEXT << prefix << type->type_name() << "\n"
|
||||
<< prefix << type->cost() << " " << sngettext("unit^Gold", "Gold", type->cost());
|
||||
<< prefix << type->cost() << " " << translation::sngettext("unit^Gold", "Gold", type->cost());
|
||||
|
||||
items.push_back(description.str());
|
||||
sample_units.push_back(type);
|
||||
|
@ -3303,7 +3303,7 @@ void menu_handler::do_ai_formula(const std::string& str,
|
|||
|
||||
void menu_handler::user_command()
|
||||
{
|
||||
textbox_info_.show(gui::TEXTBOX_COMMAND,sgettext("prompt^Command:"), "", false, *gui_);
|
||||
textbox_info_.show(gui::TEXTBOX_COMMAND, translation::sgettext("prompt^Command:"), "", false, *gui_);
|
||||
}
|
||||
|
||||
void menu_handler::request_control_change ( int side_num, const std::string& player )
|
||||
|
@ -3345,7 +3345,7 @@ void menu_handler::custom_command()
|
|||
void menu_handler::ai_formula()
|
||||
{
|
||||
if (network::nconnections() == 0) {
|
||||
textbox_info_.show(gui::TEXTBOX_AI,sgettext("prompt^Command:"), "", false, *gui_);
|
||||
textbox_info_.show(gui::TEXTBOX_AI, translation::sgettext("prompt^Command:"), "", false, *gui_);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ static void add_status(config &r,
|
|||
char const *path, char const *desc1, char const *desc2)
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << gettext(desc1) << gettext(desc2);
|
||||
s << translation::gettext(desc1) << translation::gettext(desc2);
|
||||
add_image(r, path, s.str());
|
||||
}
|
||||
|
||||
|
@ -431,7 +431,7 @@ static config unit_hp(reports::context& rc, const unit* u)
|
|||
BOOST_FOREACH(const utils::string_map::value_type &resist, u->get_base_resistances())
|
||||
{
|
||||
std::ostringstream line;
|
||||
line << gettext(resist.first.c_str()) << ": ";
|
||||
line << translation::gettext(resist.first.c_str()) << ": ";
|
||||
// Some units have different resistances when attacking or defending.
|
||||
int res_att = 100 - u->resistance_against(resist.first, true, displayed_unit_hex);
|
||||
int res_def = 100 - u->resistance_against(resist.first, false, displayed_unit_hex);
|
||||
|
|
|
@ -54,20 +54,20 @@ static std::string reformat(const std::string& format, const std::tm* time,
|
|||
switch (*it) {
|
||||
case 'a': // abbreviated weekday name
|
||||
new_format += (time->tm_wday < 0 || time->tm_wday > 6) ?
|
||||
"?" : sgettext(wday_abbr[time->tm_wday]);
|
||||
"?" : translation::sgettext(wday_abbr[time->tm_wday]);
|
||||
continue;
|
||||
case 'A': // full weekday name
|
||||
new_format += (time->tm_wday < 0 || time->tm_wday > 6) ?
|
||||
"?" : sgettext(wday_full[time->tm_wday]);
|
||||
"?" : translation::sgettext(wday_full[time->tm_wday]);
|
||||
continue;
|
||||
case 'b': // abbreviated month name
|
||||
case 'h':
|
||||
new_format += (time->tm_mon < 0 || time->tm_mon > 11) ?
|
||||
"?" : sgettext(mon_abbr[time->tm_mon]);
|
||||
"?" : translation::sgettext(mon_abbr[time->tm_mon]);
|
||||
continue;
|
||||
case 'B': // full month name
|
||||
new_format += (time->tm_mon < 0 || time->tm_mon > 11) ?
|
||||
"?" : sgettext(mon_full[time->tm_mon]);
|
||||
"?" : translation::sgettext(mon_full[time->tm_mon]);
|
||||
continue;
|
||||
case 'c': // date and time
|
||||
new_format += reformat(_("%a %b %e %H:%M:%S %Y"), time,
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
*/
|
||||
|
||||
#define GETTEXT_DOMAIN "wesnoth-test"
|
||||
//#include <libintl.h>
|
||||
|
||||
#include "tests/utils/game_config_manager.hpp"
|
||||
|
||||
|
@ -68,11 +69,9 @@ namespace test_utils {
|
|||
std::setlocale(LC_MESSAGES, "");
|
||||
#endif
|
||||
const std::string& intl_dir = filesystem::get_intl_dir();
|
||||
bindtextdomain ("wesnoth", intl_dir.c_str());
|
||||
bind_textdomain_codeset ("wesnoth", "UTF-8");
|
||||
bindtextdomain ("wesnoth-lib", intl_dir.c_str());
|
||||
bind_textdomain_codeset ("wesnoth-lib", "UTF-8");
|
||||
textdomain ("wesnoth");
|
||||
translation::bind_textdomain("wesnoth", intl_dir.c_str(), "UTF-8");
|
||||
translation::bind_textdomain("wesnoth-lib", intl_dir.c_str(), "UTF-8");
|
||||
translation::set_default_textdomain("wesnoth");
|
||||
|
||||
|
||||
font::load_font_config();
|
||||
|
|
|
@ -443,7 +443,7 @@ const std::string& t_string_base::str() const
|
|||
std::string part(w.begin(), w.end());
|
||||
|
||||
if(w.translatable()) {
|
||||
translated_value_ += dsgettext(w.textdomain().c_str(), part.c_str());
|
||||
translated_value_ += translation::dsgettext(w.textdomain().c_str(), part.c_str());
|
||||
} else {
|
||||
translated_value_ += part;
|
||||
}
|
||||
|
@ -498,8 +498,7 @@ void t_string::add_textdomain(const std::string &name, const std::string &path)
|
|||
LOG_CF << "Binding textdomain " << name << " to path " << path << "\n";
|
||||
|
||||
// Register and (re-)bind this textdomain
|
||||
bindtextdomain(name.c_str(), path.c_str());
|
||||
bind_textdomain_codeset(name.c_str(), "UTF-8");
|
||||
translation::bind_textdomain(name.c_str(), path.c_str(), "UTF-8");
|
||||
}
|
||||
|
||||
void t_string::reset_translations()
|
||||
|
|
|
@ -70,7 +70,7 @@ attack_type::attack_type(const config& cfg) :
|
|||
|
||||
{
|
||||
if (description_.empty())
|
||||
description_ = egettext(id_.c_str());
|
||||
description_ = translation::egettext(id_.c_str());
|
||||
|
||||
if(icon_.empty()){
|
||||
if (id_ != "")
|
||||
|
@ -841,7 +841,7 @@ const char* unit_type::alignment_description(unit_type::ALIGNMENT align, unit_ra
|
|||
static const char* aligns_female[] = { N_("female^lawful"), N_("female^neutral"), N_("female^chaotic"), N_("female^liminal") };
|
||||
const char** tlist = (gender == unit_race::MALE ? aligns : aligns_female);
|
||||
|
||||
return (sgettext(tlist[align]));
|
||||
return (translation::sgettext(tlist[align]));
|
||||
}*/
|
||||
|
||||
bool unit_type::has_ability_by_id(const std::string& ability) const
|
||||
|
|
|
@ -252,7 +252,7 @@ public:
|
|||
} else {
|
||||
str = lexical_cast<std::string>(align);
|
||||
}
|
||||
return sgettext(str.c_str());
|
||||
return translation::sgettext(str.c_str());
|
||||
}
|
||||
|
||||
fixed_t alpha() const { return alpha_; }
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "game_config.hpp" // for path, debug, debug_lua, etc
|
||||
#include "game_config_manager.hpp" // for game_config_manager, etc
|
||||
#include "game_launcher.hpp" // for game_launcher, etc
|
||||
#include "gettext.hpp"
|
||||
#include "gui/auxiliary/event/handler.hpp" // for tmanager
|
||||
#include "gui/dialogs/core_selection.hpp" // for tcore_selection
|
||||
#include "gui/dialogs/title_screen.hpp" // for ttitle_screen, etc
|
||||
|
@ -56,7 +57,6 @@
|
|||
#include "wml_exception.hpp" // for twml_exception
|
||||
|
||||
#include <SDL.h> // for SDL_Init, SDL_INIT_TIMER
|
||||
#include <libintl.h> // for bind_textdomain_codeset, etc
|
||||
#include <boost/foreach.hpp> // for auto_any_base, etc
|
||||
#include <boost/iostreams/categories.hpp> // for input, output
|
||||
#include <boost/iostreams/copy.hpp> // for copy
|
||||
|
@ -482,11 +482,9 @@ static void init_locale() {
|
|||
std::setlocale(LC_MESSAGES, "");
|
||||
#endif
|
||||
const std::string& intl_dir = filesystem::get_intl_dir();
|
||||
bindtextdomain (PACKAGE, intl_dir.c_str());
|
||||
bind_textdomain_codeset (PACKAGE, "UTF-8");
|
||||
bindtextdomain (PACKAGE "-lib", intl_dir.c_str());
|
||||
bind_textdomain_codeset (PACKAGE "-lib", "UTF-8");
|
||||
textdomain (PACKAGE);
|
||||
translation::bind_textdomain(PACKAGE, intl_dir.c_str(), "UTF-8");
|
||||
translation::bind_textdomain(PACKAGE "-lib", intl_dir.c_str(), "UTF-8");
|
||||
translation::set_default_textdomain(PACKAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue