user-visible strings.
This makes it easier to translate the patterns. See the comment added
to src/util/gettext.hpp .
SVN-Revision: 6634
* GLEW
http://glew.sourceforge.net/
-* Boost's smart_ptr headers
+* Boost's smart_ptr and format headers
http://www.boost.org/
Note: We tried to write our code clean, portable and platform neutral, so it
#include "util/gettext.hpp"
#include <sstream>
+#include <boost/format.hpp>
LevelIntro::LevelIntro(const Level* level, const Statistics* best_level_statistics) :
level(level),
std::string author = level->get_author();
if ((author != "") && (author != "SuperTux Team")) {
- std::string author_text = std::string(_("contributed by ")) + author;
+ std::string author_text = str(boost::format(_("contributed by %s")) % author);
context.draw_center_text(Resources::small_font, author_text, Vector(0, py), LAYER_FOREGROUND1, LevelIntro::author_color);
py += static_cast<int>(Resources::small_font->get_height());
}
#include <iostream>
#include <binreloc.h>
#include <tinygettext/log.hpp>
+#include <boost/format.hpp>
#include "supertux/main.hpp"
void
Main::print_usage(const char* argv0)
{
- std::cerr << _("Usage: ") << argv0 << _(" [OPTIONS] [LEVELFILE]\n\n")
- << _("Options:\n"
+ std::cerr << boost::format(_(
+ "\n"
+ "Usage: %s [OPTIONS] [LEVELFILE]\n\n"
+ "Options:\n"
" -f, --fullscreen Run in fullscreen mode\n"
" -w, --window Run in window mode\n"
" -g, --geometry WIDTHxHEIGHT Run SuperTux in given resolution\n"
" --record-demo FILE LEVEL Record a demo to FILE\n"
" --play-demo FILE LEVEL Play a recorded demo\n"
" -s, --debug-scripts Enable script debugger.\n"
- "\n")
+ "\n"
+ ))
+ % argv0
<< std::flush;
}
#include "supertux/globals.hpp"
+/*
+ * If you need to do a nontrivial substitution of values into a pattern, use
+ * boost::format rather than an ad-hoc concatenation. That way, translators can
+ * translate the format string as a whole (and even rearrange the values if
+ * necessary with "%1$s"-style codes) instead of multiple pieces. Patterns like
+ * "Label: %s" with only one string piece are a borderline case where
+ * boost::format is not really necessary.
+ *
+ * http://www.mihai-nita.net/article.php?artID=20060430a
+ *
+ * Bad:
+ * std::string msg = _("You collected ") + num + _(" coins");
+ * std::cout << _("You collected ") << num << _(" coins");
+ * Good:
+ * #include <boost/format.hpp>
+ * std::string msg = str(boost::format(_("You collected %d coins")) % num);
+ * std::cout << boost::format(_("You collected %d coins")) % num;
+ */
+
static inline std::string _(const std::string& message)
{
if (dictionary_manager)