[Supertux-Commit] [tinygettext commit] r136 - in branches/tinygettext-portable: . src

codesite-noreply at google.com codesite-noreply at google.com
Sun Feb 1 07:15:23 PST 2009


Author: grumbel
Date: Sun Feb  1 05:58:50 2009
New Revision: 136

Modified:
    branches/tinygettext-portable/TODO
    branches/tinygettext-portable/src/dictionary_manager.cpp
    branches/tinygettext-portable/src/dictionary_manager.hpp
    branches/tinygettext-portable/src/po_parser.cpp
    branches/tinygettext-portable/src/po_parser.hpp

Log:
Added fuzzy flag handling

Modified: branches/tinygettext-portable/TODO
==============================================================================
--- branches/tinygettext-portable/TODO	(original)
+++ branches/tinygettext-portable/TODO	Sun Feb  1 05:58:50 2009
@@ -24,12 +24,6 @@
  tinygettext API related stuff:
  ==============================

-* add a way to toggle if fuzzy messages should be included or not
-  (requires changes to POParser)
-
-* comments should be parsed, since they contain meta information such
-  as fuzzy markers
-
  * enumerating files should fallback to more generic languages, i.e.:

    de_AT should load de.po (somewhat already the case, but different  
mechanic then supertux)

Modified: branches/tinygettext-portable/src/dictionary_manager.cpp
==============================================================================
--- branches/tinygettext-portable/src/dictionary_manager.cpp	(original)
+++ branches/tinygettext-portable/src/dictionary_manager.cpp	Sun Feb  1  
05:58:50 2009
@@ -46,6 +46,7 @@

  DictionaryManager::DictionaryManager(const std::string& charset_)
    : charset(charset_),
+    use_fuzzy(true),
      current_dict(0),
      empty_dict(Language::from_spec("en"))
  {
@@ -204,6 +205,19 @@
  {
    clear_cache(); // changing charset invalidates cache
    charset = charset_;
+}
+
+void
+DictionaryManager::set_use_fuzzy(bool t)
+{
+  clear_cache();
+  use_fuzzy = t;
+}
+
+bool
+DictionaryManager::get_use_fuzzy(bool t) const
+{
+  return use_fuzzy;
  }

  void

Modified: branches/tinygettext-portable/src/dictionary_manager.hpp
==============================================================================
--- branches/tinygettext-portable/src/dictionary_manager.hpp	(original)
+++ branches/tinygettext-portable/src/dictionary_manager.hpp	Sun Feb  1  
05:58:50 2009
@@ -43,6 +43,7 @@
    SearchPath search_path;

    std::string charset;
+  bool        use_fuzzy;

    Language    current_language;
    Dictionary* current_dict;
@@ -69,6 +70,9 @@

    /** returns the (normalized) country code of the currently used language  
*/
    Language get_language() const;
+
+  void set_use_fuzzy(bool t);
+  bool get_use_fuzzy(bool t) const;

    /** Set a charset that will be set on the returned dictionaries */
    void set_charset(const std::string& charset);

Modified: branches/tinygettext-portable/src/po_parser.cpp
==============================================================================
--- branches/tinygettext-portable/src/po_parser.cpp	(original)
+++ branches/tinygettext-portable/src/po_parser.cpp	Sun Feb  1 05:58:50 2009
@@ -44,8 +44,8 @@
  
  class POParserError {};

-POParser::POParser(const std::string& filename_, std::istream& in_,  
Dictionary& dict_)
-  : filename(filename_), in(in_), dict(dict_),
+POParser::POParser(const std::string& filename_, std::istream& in_,  
Dictionary& dict_, bool use_fuzzy_)
+  : filename(filename_), in(in_), dict(dict_), use_fuzzy(use_fuzzy_),
      running(false), eof(false), big5(false),
      line_number(0)
  {
@@ -321,7 +321,7 @@
      {
        try
          {
-          uint32_t flags = 0;
+          bool fuzzy =  false;
            bool has_msgctxt = false;
            std::string msgctxt;
            std::string msgid;
@@ -330,11 +330,10 @@
              {
                if (current_line.size() >= 2 && current_line[1] == ',')
                  {
-                  flags = 0;
-                  if (0)
-                    std::cout << "flags: " << current_line << std::endl;
+                  // FIXME: Rather simplistic hunt for fuzzy flag
+                  if (current_line.find("fuzzy", 2) != std::string::npos)
+                    fuzzy = true;
                  }
-              //parse_comments(&flags);

                next_line();
              }
@@ -383,10 +382,13 @@
                    if (!is_empty_line())
                      error("expected 'msgstr[N]' or empty line");

-                  if (has_msgctxt)
-                    dict.add_translation(msgctxt, msgid, msgid_plural,  
msgstr_num);
-                  else
-                    dict.add_translation(msgid, msgid_plural, msgstr_num);
+                  if (use_fuzzy || !fuzzy)
+                    {
+                      if (has_msgctxt)
+                        dict.add_translation(msgctxt, msgid, msgid_plural,  
msgstr_num);
+                      else
+                        dict.add_translation(msgid, msgid_plural,  
msgstr_num);
+                    }

                    if (0)
                      {
@@ -407,10 +409,13 @@
                      }
                    else
                      {
-                      if (has_msgctxt)
-                        dict.add_translation(msgctxt, msgid, msgstr);
-                      else
-                        dict.add_translation(msgid, msgstr);
+                      if (use_fuzzy || !fuzzy)
+                        {
+                          if (has_msgctxt)
+                            dict.add_translation(msgctxt, msgid, msgstr);
+                          else
+                            dict.add_translation(msgid, msgstr);
+                        }

                        if (0)
                          {

Modified: branches/tinygettext-portable/src/po_parser.hpp
==============================================================================
--- branches/tinygettext-portable/src/po_parser.hpp	(original)
+++ branches/tinygettext-portable/src/po_parser.hpp	Sun Feb  1 05:58:50 2009
@@ -33,6 +33,7 @@
    std::string filename;
    std::istream& in;
    Dictionary& dict;
+  bool  use_fuzzy;
    IConv conv;

    bool running;
@@ -42,7 +43,7 @@
    int line_number;
    std::string current_line;

-  POParser(const std::string& filename, std::istream& in_, Dictionary&  
dict_);
+  POParser(const std::string& filename, std::istream& in_, Dictionary&  
dict_, bool use_fuzzy = true);
    ~POParser();

    void parse_header(const std::string& header);


More information about the Supertux-Commit mailing list