src/util/gettext.hpp

Go to the documentation of this file.
00001 //  SuperTux 
00002 //  Copyright (C) 2006 Ingo Ruhnke <grumbel@gmx.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #ifndef HEADER_SUPERTUX_UTIL_GETTEXT_HPP
00018 #define HEADER_SUPERTUX_UTIL_GETTEXT_HPP
00019 
00020 #include <tinygettext/tinygettext.hpp>
00021 #include <assert.h>
00022 
00023 #include "supertux/globals.hpp"
00024 
00025 /*
00026  * If you need to do a nontrivial substitution of values into a pattern, use
00027  * boost::format rather than an ad-hoc concatenation.  That way, translators can
00028  * translate the format string as a whole (and even rearrange the values if
00029  * necessary with "%1$s"-style codes) instead of multiple pieces.  Patterns like
00030  * "Label: %s" with only one string piece are a borderline case where
00031  * boost::format is not really necessary.
00032  *
00033  * http://www.mihai-nita.net/article.php?artID=20060430a
00034  *
00035  * Bad:
00036  *     std::string msg = _("You collected ") + num + _(" coins");
00037  *     std::cout << _("You collected ") << num << _(" coins");
00038  * Good:
00039  *     #include <boost/format.hpp>
00040  *     std::string msg = str(boost::format(_("You collected %d coins")) % num);
00041  *     std::cout << boost::format(_("You collected %d coins")) % num;
00042  */
00043 
00044 static inline std::string _(const std::string& message)
00045 {
00046   if (dictionary_manager)
00047   {
00048     return dictionary_manager->get_dictionary().translate(message);
00049   }
00050   else
00051   {
00052     return message;
00053   }
00054 }
00055 
00056 #endif
00057 
00058 /* EOF */

Generated on Mon Jun 9 03:38:23 2014 for SuperTux by  doxygen 1.5.1