[Supertux-Commit] [tinygettext commit] r137 - in branches/tinygettext-portable: . src test test/po

codesite-noreply at google.com codesite-noreply at google.com
Sun Feb 1 08:54:44 PST 2009


Author: grumbel
Date: Sun Feb  1 08:47:53 2009
New Revision: 137

Added:
    branches/tinygettext-portable/test/po/de_AT.po
Removed:
    branches/tinygettext-portable/test/po/de2.po
Modified:
    branches/tinygettext-portable/TODO
    branches/tinygettext-portable/src/dictionary.cpp
    branches/tinygettext-portable/src/dictionary.hpp
    branches/tinygettext-portable/src/dictionary_manager.cpp
    branches/tinygettext-portable/src/iconv.cpp
    branches/tinygettext-portable/src/language.cpp
    branches/tinygettext-portable/src/po_parser.cpp
    branches/tinygettext-portable/test/po/de.po
    branches/tinygettext-portable/test/po_parser_test.cpp
    branches/tinygettext-portable/test/tinygettext.cpp

Log:
Moved Language out of Dictionary and replaced it by Plural-Forms

Modified: branches/tinygettext-portable/TODO
==============================================================================
--- branches/tinygettext-portable/TODO	(original)
+++ branches/tinygettext-portable/TODO	Sun Feb  1 08:47:53 2009
@@ -24,6 +24,9 @@
  tinygettext API related stuff:
  ==============================

+* translate, translate_ctxt, translate_ctxt_plural, ... could be
+  unified via overloading, not sure if that is a good idea
+
  * 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)
@@ -46,30 +49,6 @@

  tinygettext implementation details:
  ===================================
-
-* the transformation from POFile -> Dictionary shouldn't need a
-  Language object, only PluralForms are needed and those are in the
-  POFile itself. Not much a practical issue, since that is handled by
-  DictionaryManager anyway, but still a little ugly. Maybe have a
-  simple string parser that maps PluralForms string to plurar_*
-  functions? Could be useful for the tinygettext command line test
-  tool, which currently just defaults to german.
-
-  Problem: Reading .po from different files into a single Dictionary
-  would be somewhat troublesome, since PluralForms could differ from
-  .po to .po (in theory only, in practice they would have to be the
-  same to make sense).
-
-* Charset matching in the PO header doesn't accept whitespace before
-  it, this works:
-
-   Content-Type: text/plain; charset=ISO-8859-1
-
-   this doesn't:
-
-   Content-Type:  text/plain; charset=ISO-8859-1
-
-   Should probally warn here, since its currently silently ignored.

  * get rid of goto


Modified: branches/tinygettext-portable/src/dictionary.cpp
==============================================================================
--- branches/tinygettext-portable/src/dictionary.cpp	(original)
+++ branches/tinygettext-portable/src/dictionary.cpp	Sun Feb  1 08:47:53  
2009
@@ -23,8 +23,8 @@

  namespace tinygettext {
  
-Dictionary::Dictionary(const Language& language_, const std::string&  
charset_)
-  : language(language_), charset(charset_)
+Dictionary::Dictionary(const std::string& charset_)
+  : charset(charset_), plural_forms(PluralForms::create(0,0))
  {
  }

@@ -34,6 +34,18 @@
    return charset;
  }

+void
+Dictionary::set_plural_forms(const PluralForms& plural_forms_)
+{
+  plural_forms = plural_forms_;
+}
+
+PluralForms
+Dictionary::get_plural_forms() const
+{
+  return plural_forms;
+}
+
  const char*
  Dictionary::translate_plural(const char* msgid, const char* msgidplural,  
int num)
  {
@@ -54,7 +66,11 @@

    if (i != dict.end())
      {
-      unsigned int n = language.plural(count);
+      unsigned int n = 0;
+      if (plural_forms.plural)
+        n = plural_forms.plural(count);
+      else // FIXME: Should give that warning when parsing the po, not at  
runtime
+        log_warning << "warning: Plural-Forms missing" << std::endl;

        assert(n >= 0 && n < msgstrs.size());

@@ -172,7 +188,8 @@
      }
    else
      {
-      log_warning << "collision in add_translation(\"" << msgid << "\",  
\"" << msgstr << "\")" << std::endl;
+      log_warning << "collision in add_translation: '"
+                  << msgid << "' -> '" << msgstr << "' vs '" << vec[0]  
<< "'" << std::endl;
        vec[0] = msgstr;
      }
  }
@@ -207,12 +224,6 @@
        log_warning << "collision in add_translation(\"" << msgctxt << "\",  
\"" << msgid << "\")" << std::endl;
        vec[0] = msgstr;
      }
-}
-
-Language
-Dictionary::get_language() const
-{
-  return language;
  }
  
  } // namespace tinygettext

Modified: branches/tinygettext-portable/src/dictionary.hpp
==============================================================================
--- branches/tinygettext-portable/src/dictionary.hpp	(original)
+++ branches/tinygettext-portable/src/dictionary.hpp	Sun Feb  1 08:47:53  
2009
@@ -39,21 +39,21 @@
    typedef std::map<std::string, Entries> CtxtEntries;
    CtxtEntries ctxt_entries;

-  Language language;
    std::string charset;
+  PluralForms plural_forms;

    std::string translate(const Entries& dict, const std::string& msgid);
    std::string translate_plural(const Entries& dict, const std::string&  
msgid, const std::string& msgidplural, int num);

  public:
    /** */
-  Dictionary(const Language& language, const std::string& charset  
= "UTF-8");
+  Dictionary(const std::string& charset = "UTF-8");

    /** Return the charset used for this dictionary */
    std::string get_charset() const;

-  /** Return the language used for this dictionary */
-  Language get_language() const;
+  void set_plural_forms(const PluralForms&);
+  PluralForms get_plural_forms() const;

    /** Translate the string \a msgid. */
    std::string translate(const std::string& msgid);

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  
08:47:53 2009
@@ -28,14 +28,6 @@

  namespace tinygettext {

-static bool has_prefix(const std::string& lhs, const std::string rhs)
-{
-  if (lhs.length() < rhs.length())
-    return false;
-  else
-    return lhs.compare(0, rhs.length(), rhs) == 0;
-}
-
  static bool has_suffix(const std::string& lhs, const std::string rhs)
  {
    if (lhs.length() < rhs.length())
@@ -48,7 +40,7 @@
    : charset(charset_),
      use_fuzzy(true),
      current_dict(0),
-    empty_dict(Language::from_spec("en"))
+    empty_dict()
  {
    dir_op.enumerate_files = unix_enumerate_files;
    dir_op.free_list       = unix_free_list;
@@ -110,7 +102,7 @@
    else // Dictionary for languages lang isn't loaded, so we load it
      {
        //log_debug << "get_dictionary: " << lang << std::endl;
-      Dictionary* dict = new Dictionary(language, charset);
+      Dictionary* dict = new Dictionary(charset);

        dictionaries[language] = dict;

@@ -123,15 +115,15 @@
              }
            else
              {
-              for(const char* const* filename = files;
-                  *filename != 0; filename++)
+              for(const char* const* filename = files; *filename != 0;  
filename++)
                  {
                    // check if filename matches requested language
                    if (has_suffix(*filename, ".po"))
                      { // ignore anything that isn't a .po file
+                      Language po_language =  
Language::from_env(std::string(*filename, strlen(*filename)-3));

-                      //
-                      if (has_prefix(*filename, language.get_language()))
+                      // FIXME: Should compare all things and find the  
best match
+                      if (language.get_language() ==  
po_language.get_language())
                          {
                            //log_debug << "Loading dictionary for language  
\"" << lang << "\" from \"" << filename << "\"" << std::endl;
                            std::string pofile = *p + "/" + *filename;

Modified: branches/tinygettext-portable/src/iconv.cpp
==============================================================================
--- branches/tinygettext-portable/src/iconv.cpp	(original)
+++ branches/tinygettext-portable/src/iconv.cpp	Sun Feb  1 08:47:53 2009
@@ -119,7 +119,7 @@
                iconv(cd, NULL, NULL, NULL, NULL); // reset state

                // FIXME: Could try to skip the invalid byte and continue
-              log_warning << "tinygettext:iconv: invalid multibyte  
sequence in:  \"" << text << "\"" << std::endl;
+              log_error << "error: tinygettext:iconv: invalid multibyte  
sequence in:  \"" << text << "\"" << std::endl;
              }
            else if (errno == E2BIG)
              { // output buffer to small

Modified: branches/tinygettext-portable/src/language.cpp
==============================================================================
--- branches/tinygettext-portable/src/language.cpp	(original)
+++ branches/tinygettext-portable/src/language.cpp	Sun Feb  1 08:47:53 2009
@@ -349,7 +349,10 @@
    if (language_aliases.empty())
      {
        // FIXME: Many of those are not useful for us, since we leave
-      // encoding to the app, not to the language
+      // encoding to the app, not to the language, we could/should
+      // also match against all language names, not just aliases from
+      // locale.alias
+
        // Aliases taken from /etc/locale.alias
        language_aliases["bokmal"]           = "nb_NO.ISO-8859-1";
        language_aliases["bokmål"]           = "nb_NO.ISO-8859-1";

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 08:47:53 2009
@@ -244,15 +244,32 @@
                  }
                else
                  {
-                  error("malformed Content-Type header");
+                  warning("malformed Content-Type header");
                  }
              }
            else if (has_prefix(line, "Plural-Forms:"))
              {
-              // FIXME: Do something with this
-              PluralForms::from_string(line);
+              PluralForms plural_forms = PluralForms::from_string(line);
+              if (plural_forms.nplural == 0 || plural_forms.plural == 0)
+                {
+                  warning("unknown Plural-Forms given");
+                }
+              else
+                {
+                  if (dict.get_plural_forms().nplural == 0 &&  
dict.get_plural_forms().plural == 0)
+                    {
+                      dict.set_plural_forms(plural_forms);
+                    }
+                  else
+                    {
+                      if (dict.get_plural_forms().nplural !=  
plural_forms.nplural ||
+                          dict.get_plural_forms().plural !=  
plural_forms.plural)
+                        {
+                          warning("Plural-Forms missmatch");
+                        }
+                    }
+                }
              }
-
            start = i+1;
          }
      }
@@ -392,6 +409,7 @@

                    if (0)
                      {
+                      std::cout << (fuzzy?"fuzzy":"not-fuzzy") <<  
std::endl;
                        std::cout << "msgid \"" << msgid << "\"" <<  
std::endl;
                        std::cout << "msgid_plural \"" << msgid_plural  
<< "\"" << std::endl;
                        for(std::vector<std::string>::size_type i = 0; i <  
msgstr_num.size(); ++i)
@@ -419,6 +437,7 @@

                        if (0)
                          {
+                          std::cout << (fuzzy?"fuzzy":"not-fuzzy") <<  
std::endl;
                            std::cout << "msgid \"" << msgid << "\"" <<  
std::endl;
                            std::cout << "msgstr \"" << conv.convert(msgstr)  
<< "\"" << std::endl;
                            std::cout << std::endl;

Modified: branches/tinygettext-portable/test/po/de.po
==============================================================================
--- branches/tinygettext-portable/test/po/de.po	(original)
+++ branches/tinygettext-portable/test/po/de.po	Sun Feb  1 08:47:53 2009
@@ -7,13 +7,16 @@
  "Project-Id-Version: Pingus 0.6.0\n"
  "Report-Msgid-Bugs-To: \n"
  "POT-Creation-Date: 2004-04-09 18:37+0000\n"
-"PO-Revision-Date: 2009-02-01 13:33+0100\n"
+"PO-Revision-Date: 2009-02-01 17:44+0100\n"
  "Last-Translator: David Philippi <david at torangan.de>\n"
  "Language-Team: David Philippi <david at torangan.de>, Ingo Ruhnke  
<grumbel at gmx.de>, Giray Devlet <giray at devlet.cc>\n"
  "MIME-Version: 1.0\n"
  "Plural-Forms: nplurals=2; plural=(n != 1);\n"
-"Content-Type: text/plain; charset=ISO-8859-1\n"
+"Content-Type: text/plain; charset=UTF-8\n"
  "Content-Transfer-Encoding: 8bit\n"
+
+msgid "umlaut"
+msgstr "ÄÖÜäöüß"

  #: src/actions/bridger.cxx:48 src/actions/bridger.cxx:232
  #: src/pingu_enums.cxx:40

Added: branches/tinygettext-portable/test/po/de_AT.po
==============================================================================
--- (empty file)
+++ branches/tinygettext-portable/test/po/de_AT.po	Sun Feb  1 08:47:53 2009
@@ -0,0 +1,28 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR Free Software Foundation, Inc.
+# FIRST AUTHOR <EMAIL at ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"PO-Revision-Date: 2004-07-27 23:27+0200\n"
+"Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
+"Language-Team: LANGUAGE <LL at li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "umlaut"
+msgstr "ÄÖÜäöü߀¢"
+
+msgid "You got %d error."
+msgid_plural "You got %d error."
+msgstr[0] "Du hast %d fehler"
+msgstr[1] "Du hast %d fehlers"
+
+msgid "found %d fatal error"
+msgid_plural "found %d fatal errors"
+msgstr[0] "s'ha trobat %d error fätal"
+msgstr[1] "s'han trobat %d errors fätals"
+

Modified: branches/tinygettext-portable/test/po_parser_test.cpp
==============================================================================
--- branches/tinygettext-portable/test/po_parser_test.cpp	(original)
+++ branches/tinygettext-portable/test/po_parser_test.cpp	Sun Feb  1  
08:47:53 2009
@@ -53,7 +53,7 @@
              {
                try
                  {
-                  tinygettext::Dictionary  
dict1(tinygettext::Language::from_spec("de"));
+                  tinygettext::Dictionary dict1;
                    tinygettext::POParser::parse(argv[i], in, dict1);

                    //tinygettext::Dictionary dict2;

Modified: branches/tinygettext-portable/test/tinygettext.cpp
==============================================================================
--- branches/tinygettext-portable/test/tinygettext.cpp	(original)
+++ branches/tinygettext-portable/test/tinygettext.cpp	Sun Feb  1 08:47:53  
2009
@@ -58,7 +58,7 @@
            const char* filename = argv[2];
            const char* message  = argv[3];

-          Dictionary dict(Language::from_spec("de"));
+          Dictionary dict;
            read_dictionary(filename, dict);
            std::cout << dict.translate(message) << std::endl;
          }
@@ -68,7 +68,7 @@
            const char* context  = argv[3];
            const char* message  = argv[4];

-          Dictionary dict(Language::from_spec("de"));
+          Dictionary dict;
            read_dictionary(filename, dict);
            std::cout << dict.translate_ctxt(context, message) << std::endl;
          }
@@ -79,7 +79,7 @@
            const char* message_plural   = argv[4];
            int num = atoi(argv[5]);

-          Dictionary dict(Language::from_spec("de"));
+          Dictionary dict;
            read_dictionary(filename, dict);
            std::cout << dict.translate_plural(message_singular,  
message_plural, num) << std::endl;
          }
@@ -91,7 +91,7 @@
            const char* message_plural   = argv[5];
            int num = atoi(argv[6]);

-          Dictionary dict(Language::from_spec("de"));
+          Dictionary dict;
            read_dictionary(filename, dict);
            std::cout << dict.translate_ctxt_plural(context,  
message_singular, message_plural, num) << std::endl;
          }


More information about the Supertux-Commit mailing list