new editor image for infoblock
[supertux.git] / lib / app / tinygettext.cpp
index babb201..91c29b7 100644 (file)
@@ -16,6 +16,7 @@
 //  You should have received a copy of the GNU General Public License
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#include <config.h>
 
 #include <sys/types.h>
 #include <iconv.h>
@@ -26,6 +27,8 @@
 #include <errno.h>
 #include "tinygettext.h"
 
+//#define TRANSLATION_DEBUG
+
 namespace TinyGetText {
 
 /** Convert \a which is in \a from_charset to \a to_charset and return it */
@@ -235,6 +238,8 @@ DictionaryManager::get_dictionary(const std::string& spec)
       Dictionary& dict = dictionaries[lang];
 
       dict.set_language(get_language_def(lang));
+      if(charset != "")
+        dict.set_charset(charset);
 
       for (SearchPath::iterator p = search_path.begin(); p != search_path.end(); ++p)
         {
@@ -307,6 +312,14 @@ DictionaryManager::set_language(const std::string& lang)
 }
 
 void
+DictionaryManager::set_charset(const std::string& charset)
+{
+  dictionaries.clear(); // changing charset invalidates cache
+  this->charset = charset;
+  set_language(language);
+}
+
+void
 DictionaryManager::set_language_alias(const std::string& alias,
     const std::string& language)
 {
@@ -332,9 +345,8 @@ DictionaryManager::get_language_from_spec(const std::string& spec)
 void
 DictionaryManager::add_directory(const std::string& pathname)
 {
+  dictionaries.clear(); // adding directories invalidates cache
   search_path.push_back(pathname);
-  // cache is outdated now
-  dictionaries.clear();
   set_language(language);
 }
 
@@ -390,10 +402,12 @@ Dictionary::translate(const std::string& msgid, const std::string& msgid2, int n
     }
   else
     {
+#ifdef TRANSLATION_DEBUG
       std::cerr << "Warning: Couldn't translate: " << msgid << std::endl;
       std::cerr << "Candidates: " << std::endl;
       for (PluralEntries::iterator i = plural_entries.begin(); i != plural_entries.end(); ++i)
         std::cout << "'" << i->first << "'" << std::endl;
+#endif
 
       if (plural2_1(num)) // default to english rules
         return msgid2;
@@ -412,7 +426,9 @@ Dictionary::translate(const std::string& msgid)
     }
   else
     {
+#ifdef TRANSLATION_DBEUG
       std::cout << "Error: Couldn't translate: " << msgid << std::endl;
+#endif
       return msgid;
     }
 }