[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-Devel] PATCH: properly use gettext on platforms with a real gett
From: |
Hans de Goede |
Subject: |
[Pingus-Devel] PATCH: properly use gettext on platforms with a real gettext |
Date: |
Sun, 13 Aug 2006 11:19:26 +0200 |
User-agent: |
Thunderbird 1.5.0.4 (X11/20060613) |
Hi all,
First a short intro, I'm a Linux enthousiast and developer and lately
mainly work on Fedora Extras. As such I've rescently packaged pingus for
Fedora. I've used a CVS snapshot as the stable release is really really old.
The attached patch changes the meaning of HAVE_GETTEXT, to mean what the
name of the define says if HAVE_GETTEXT is defined it will use the
system (c-library) gettext such as available on any modern unix OS. If
not defined it will use the build in gettext replacement.
With this patch applied the translations need to be compiled and
installed as usualy instead of just being dropped into the datadir. I
haven't patched the makefiles todo this yet, in order to install the
compiled translations execute the following from the dir holding the .po
files:
for i in *.po; do
POLANG=`echo $i|sed 's/\.po//'`
mkdir -p $DESDIR/usr/share/locale/$POLANG/LC_MESSAGES
msgfmt $i -o $DESDIR/usr/share/locale/$POLANG/LC_MESSAGES/pingus.mo
done
Also notice that this patch changes the encoding choosen by LANG /
LC_ALL to an encoding matching the fonts shipped with pingus for this to
work (using setlocale). In order for the startup messages to appear
correctly on the console/terminal it does this changing of the encoding
after the startup messages have been printed. Otherwise the startup
messages get printed in this encoding too, which could be different from
the encoding of the terminal they are printed too.
Last this patch changes a number of C++ strings to C-strings so that
gettext can work on them.
Regards,
Hans
--- pingus-20060721/src/gettext.h.gettext 2006-07-19 16:00:35.000000000
+0200
+++ pingus-20060721/src/gettext.h 2006-07-21 12:36:49.000000000 +0200
@@ -19,7 +19,11 @@
#ifndef HEADER_GETTEXT_HXX
#define HEADER_GETTEXT_HXX
-
+#include <config.h>
+#ifdef HAVE_GETTEXT
+#include <libintl.h>
+#define _(String) gettext(String)
+#else
#include "tinygettext/tinygettext.hxx"
namespace Pingus {
@@ -28,5 +32,5 @@
#define _(String)
::Pingus::dictionary_manager.get_dictionary().translate(String).c_str()
#define N_(id, id2, num)
::Pingus::dictionary_manager.get_dictionary().translate(id, di2, num).c_str()
-
+#endif /* HAVE_GETTEXT */
#endif /* HEADER_GETTEXT_HXX */
--- pingus-20060721/src/pingus_main.cxx.gettext 2006-07-19 16:00:35.000000000
+0200
+++ pingus-20060721/src/pingus_main.cxx 2006-07-21 15:02:37.000000000 +0200
@@ -127,6 +127,7 @@
editor(false),
refresh_rate(60)
{
+ font_encoding_locale[0] = 0;
}
PingusMain::~PingusMain()
@@ -585,9 +586,14 @@
exit(EXIT_FAILURE);
}
+#ifdef HAVE_GETTEXT
+ textdomain("pingus");
+ setlocale(LC_ALL, "");
+#else
dictionary_manager.add_directory(path_manager.complete("po/"));
// Language is automatically picked from env variable
// dictionary_manager.set_language("de");
+#endif
const char* lang = getenv("LC_ALL");
if(!lang) lang = getenv("LC_MESSAGES");
@@ -596,19 +602,52 @@
{
std::string language(lang);
language.resize(2);
+#ifdef HAVE_GETTEXT
+ char *p;
+ strcpy(font_encoding_locale, lang);
+ /* remove encoding if any */
+ if ((p = strchr(font_encoding_locale, '.')))
+ *p = 0;
+ /* remove modifier if any */
+ if ((p = strchr(font_encoding_locale, '@')))
+ *p = 0;
+ /* Add a territory if none is present */
+ if (!strchr(font_encoding_locale, '_'))
+ {
+ unsigned int i;
+ char buf[16];
+ strcpy(buf, font_encoding_locale);
+ for (i=0; i<strlen(buf); i++)
+ buf[i] = toupper(buf[i]);
+ strcat(font_encoding_locale, "_");
+ strcat(font_encoding_locale, buf);
+ }
+#endif
if(language == "cs" || language == "sr")
{
+#ifdef HAVE_GETTEXT
+ strcat(font_encoding_locale, ".ISO-8859-2");
+#else
dictionary_manager.set_charset("ISO-8859-2");
+#endif
Pingus::Fonts::encoding = "ISO-8859-2";
}
else if(language == "tr")
{
+#ifdef HAVE_GETTEXT
+ strcat(font_encoding_locale, ".ISO-8859-9");
+#else
dictionary_manager.set_charset("ISO-8859-9");
+#endif
Pingus::Fonts::encoding = "ISO-8859-9";
}
else
{
+#ifdef HAVE_GETTEXT
+ strcat(font_encoding_locale, ".ISO-8859-1");
+#else
dictionary_manager.set_charset("ISO-8859-1");
+#endif
Pingus::Fonts::encoding = "ISO-8859-1";
}
}
@@ -643,10 +682,10 @@
#endif
#ifdef HAVE_GETTEXT
- std::cout << _("getext support: ok") << std::endl;
+ std::cout << _("gettext support: ok") << std::endl;
std::cout << _("gettext language: english") << std::endl;
#else
- std::cout << "getext support: missing (only support for english will be
available)" << std::endl;
+ std::cout << "getext support: missing, using tinygettext" << std::endl;
#endif
if (sound_enabled)
@@ -798,6 +837,9 @@
check_args(argc, argv);
print_greeting_message();
+#ifdef HAVE_GETTEXT
+ setlocale(LC_ALL, font_encoding_locale);
+#endif
init_clanlib();
init_pingus();
--- pingus-20060721/src/file_dialog_item.cxx.gettext 2006-07-19
16:00:35.000000000 +0200
+++ pingus-20060721/src/file_dialog_item.cxx 2006-07-21 12:36:49.000000000
+0200
@@ -94,7 +94,7 @@
reader.read_string("levelname", file_item.friendly_name);
reader.read_string("difficulty", file_info);
file_item.is_accessible
= true;
- file_item.friendly_name
= _(file_item.friendly_name);
+ file_item.friendly_name
= _(file_item.friendly_name.c_str());
file_info =
_("Difficulty: ") + file_info;
Savegame* sg =
SavegameManager::instance()->get(file_item.friendly_name);
if (sg)
@@ -133,8 +133,8 @@
status =
_("Finished!");
file_item.is_finished = true;
}
- file_item.friendly_name
= _(file_item.friendly_name);
- file_info =
_(file_info);
+ file_item.friendly_name
= _(file_item.friendly_name.c_str());
+ file_info =
_(file_info.c_str());
}
// Have to limit the size of
the printed name
--- pingus-20060721/src/gettext.cxx.gettext 2006-07-19 16:00:35.000000000
+0200
+++ pingus-20060721/src/gettext.cxx 2006-07-21 12:36:49.000000000 +0200
@@ -18,9 +18,9 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "gettext.h"
-
+#ifndef HAVE_GETTEXT
namespace Pingus {
TinyGetText::DictionaryManager dictionary_manager;
}
-
+#endif
/* EOF */
--- pingus-20060721/src/result_screen.cxx.gettext 2006-07-19
16:00:35.000000000 +0200
+++ pingus-20060721/src/result_screen.cxx 2006-07-21 14:39:16.000000000
+0200
@@ -177,7 +177,7 @@
gc.print_center(Fonts::chalk_large, gc.get_width()/2,
(float)CL_Display::get_height()/2 - 200,
- _(result.plf.get_levelname()));
+ _(result.plf.get_levelname().c_str()));
if (result.success())
{
--- pingus-20060721/src/theme.cxx.gettext 2006-07-19 16:00:35.000000000
+0200
+++ pingus-20060721/src/theme.cxx 2006-07-21 12:36:49.000000000 +0200
@@ -56,15 +56,15 @@
if (verbose) std::cout << "Theme: loading: " << filename << std::endl;
plt.parse(filename);
- title_name = _(plt.get_name());
+ title_name = _(plt.get_name().c_str());
level_filenames = plt.get_levels();
load_levels();
- if (_(plt.get_description()) != "-")
+ if (_(plt.get_description().c_str()) != "-")
{
description.set_font(font);
- description.set_text(_(plt.get_description()), 350);
+ description.set_text(_(plt.get_description().c_str()), 350);
has_description = true;
}
else
@@ -327,7 +327,7 @@
try
{
XMLPingusLevel plf(filename, filename);
- levelnames.push_back(_(plf.get_levelname()));
+ levelnames.push_back(_(plf.get_levelname().c_str()));
}
catch (PingusError& err)
{
--- pingus-20060721/src/worldmap/level_dot.cxx.gettext 2006-07-19
16:00:32.000000000 +0200
+++ pingus-20060721/src/worldmap/level_dot.cxx 2006-07-21 12:36:49.000000000
+0200
@@ -131,7 +131,7 @@
if (accessible())
{
- int length = Fonts::pingus_small.bounding_rect(0, 0,
_(get_plf().get_levelname())).get_width() / 2;
+ int length = Fonts::pingus_small.bounding_rect(0, 0,
_(get_plf().get_levelname().c_str())).get_width() / 2;
int realpos = static_cast<int>(gc.world_to_screen(Vector(pos.x, pos.y,
0)).x);
if (realpos - length < 0)
pos_correction = realpos - length;
@@ -141,7 +141,7 @@
gc.print_center(Fonts::pingus_small,
pos.x - (float)pos_correction,
pos.y - 40,
- _(get_plf().get_levelname()),
+ _(get_plf().get_levelname().c_str()),
10000);
}
else
--- pingus-20060721/src/worldmap/worldmap.cxx.gettext 2006-07-19
16:00:32.000000000 +0200
+++ pingus-20060721/src/worldmap/worldmap.cxx 2006-07-21 12:36:49.000000000
+0200
@@ -195,7 +195,7 @@
gc.print_center(Fonts::chalk_small,
display_gc->get_width ()/2,
display_gc->get_height() - 20,
- _(leveldot->get_plf().get_levelname()));
+ _(leveldot->get_plf().get_levelname().c_str()));
}
else
--- pingus-20060721/src/worldmap/worldmap_story.cxx.gettext 2006-07-19
16:00:32.000000000 +0200
+++ pingus-20060721/src/worldmap/worldmap_story.cxx 2006-07-21
12:36:49.000000000 +0200
@@ -40,7 +40,7 @@
WorldMapStory::WorldMapStory(const FileReader &reader)
{
reader.read_string("title", title);
- title = _(title);
+ title = _(title.c_str());
reader.read_string("music", music);
FileReader all_pages = reader.read_section("pages");
@@ -58,7 +58,7 @@
i->read_desc("surface", desc);
i->read_string("text", text);
// Translate the text and break it up.
- text = StringFormat::break_line(_(text), 570,
Fonts::chalk_normal);
+ text = StringFormat::break_line(_(text.c_str()), 570,
Fonts::chalk_normal);
pages.push_back(StoryPage(desc, text, page_name));
}
std::stable_sort(pages.begin(), pages.end(), &StoryPageCompare);
--- pingus-20060721/src/tinygettext/tinygettext.hxx.gettext 2006-07-19
16:00:34.000000000 +0200
+++ pingus-20060721/src/tinygettext/tinygettext.hxx 2006-07-21
12:36:49.000000000 +0200
@@ -25,6 +25,7 @@
#include <set>
#include <string>
+#ifndef HAVE_GETTEXT
namespace TinyGetText {
typedef int (*PluralFunc)(int n);
@@ -149,6 +150,7 @@
} // namespace TinyGetText
+#endif /* HAVE_GETTEXT */
#endif
/* EOF */
--- pingus-20060721/src/tinygettext/tinygettext.cxx.gettext 2006-07-19
16:00:34.000000000 +0200
+++ pingus-20060721/src/tinygettext/tinygettext.cxx 2006-07-21
12:36:49.000000000 +0200
@@ -32,6 +32,7 @@
#include <errno.h>
#include "tinygettext.hxx"
+#ifndef HAVE_GETTEXT
//#define TRANSLATION_DEBUG
namespace TinyGetText {
@@ -789,4 +790,7 @@
} // namespace TinyGetText
+#endif /* HAVE_GETTEXT */
+
+
/* EOF */
--- pingus-20060721/src/pingus_main.hxx.gettext 2006-07-21 14:56:52.000000000
+0200
+++ pingus-20060721/src/pingus_main.hxx 2006-07-21 14:56:52.000000000 +0200
@@ -54,6 +54,14 @@
CL_Slot on_button_release_slot;
CL_Slot on_exit_press_slot;
+#ifdef HAVE_GETTEXT
+ /* We need to set a modified local with the correct encoding for our fonts
+ but only after printing oru welcome header to stdout in the default
+ encoding. This is used to store the modified local, which gets build in
+ init_path_finder() but doesn't get used until print_greeting_message()
+ is done */
+ char font_encoding_locale[32];
+#endif
public:
PingusMain();
virtual ~PingusMain();
--- pingus-20060721/src/start_screen.cxx.gettext 2006-07-19
16:00:35.000000000 +0200
+++ pingus-20060721/src/start_screen.cxx 2006-07-21 12:36:49.000000000
+0200
@@ -157,7 +157,7 @@
gc.print_center(Fonts::chalk_large,
gc.get_width()/2,
(float)CL_Display::get_height()/2 - 200,
- _(plf.get_levelname()));
+ _(plf.get_levelname().c_str()));
gc.print_left(Fonts::chalk_normal,
(float)CL_Display::get_width()/2 - 290,
@@ -191,7 +191,7 @@
if (description != "")
return description;
- description = _(plf.get_description());
+ description = _(plf.get_description().c_str());
if (description == "")
return description;
- [Pingus-Devel] PATCH: properly use gettext on platforms with a real gettext,
Hans de Goede <=