damned-lies r1094 - in branches/djamnedlies: stats stats/management/commands templates



Author: claudep
Date: Fri Oct 24 16:13:09 2008
New Revision: 1094
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1094&view=rev

Log:
2008-10-24  Claude Paroz  <claude 2xlibre net>

	* stats/management/commands/compile-trans.py:
	* stats/management/commands/update-trans.py: Added scripts to manage
	translations (wrappers to makemessages and compilemessages).
	* stats/management/commands/migrate.py: Don't migrate Stats, they should
	be regenerated by update-stats script.
	* stats/utils.py: Removed N_ shortcut, because strings are not extracted.
	* stats/models.py: Reworked Statistics (old fields removed, field names
	lowercased).
	* templates/language-release-stats.html: Use lowercase field names from
	Statistics.

Added:
   branches/djamnedlies/stats/management/commands/compile-trans.py
   branches/djamnedlies/stats/management/commands/update-trans.py
Modified:
   branches/djamnedlies/stats/management/commands/migrate.py
   branches/djamnedlies/stats/models.py
   branches/djamnedlies/stats/utils.py
   branches/djamnedlies/templates/language-release-stats.html

Added: branches/djamnedlies/stats/management/commands/compile-trans.py
==============================================================================
--- (empty file)
+++ branches/djamnedlies/stats/management/commands/compile-trans.py	Fri Oct 24 16:13:09 2008
@@ -0,0 +1,30 @@
+from django.core.management.base import BaseCommand
+from django.core.management.commands import compilemessages
+from optparse import make_option
+import os
+import shutil
+
+class Command(BaseCommand):
+    help = "Compile translations of djamnedlies"
+    args = ""
+    
+    output_transaction = False
+
+    def handle(self, *args, **options):
+        if len(args):
+            return "This command doesn't support any argument."
+
+        # Copy all po/ll.po files in locale/ll/LC_MESSAGES/django.po
+        podir = os.path.abspath('po')
+        for pofile in os.listdir(podir):
+            if pofile[-3:] != ".po":
+                continue
+            lang_code = pofile[:-3]
+            localedir = os.path.join(os.path.abspath('locale'), lang_code, 'LC_MESSAGES')
+            if not os.path.isdir(localedir):
+                os.makedirs(localedir)
+            shutil.copy(os.path.join(podir, pofile), os.path.join(localedir, 'django.po'))
+        
+        # Run compilemessages -l ll
+        compilemessages.compile_messages()
+

Modified: branches/djamnedlies/stats/management/commands/migrate.py
==============================================================================
--- branches/djamnedlies/stats/management/commands/migrate.py	(original)
+++ branches/djamnedlies/stats/management/commands/migrate.py	Fri Oct 24 16:13:09 2008
@@ -20,7 +20,7 @@
         print self.migrateTeams()
         print self.migrateModules()
         print self.migrateReleases()
-        print self.migrateStats()
+        #print self.migrateStats()
         
         # Network_manager domains may need renaming (vpn-daemons/openvpn/po -> po-openvpn, ...)
         return "Migration completed."

Added: branches/djamnedlies/stats/management/commands/update-trans.py
==============================================================================
--- (empty file)
+++ branches/djamnedlies/stats/management/commands/update-trans.py	Fri Oct 24 16:13:09 2008
@@ -0,0 +1,60 @@
+from django.core.management.base import BaseCommand
+from django.core.management.commands import makemessages
+from django.db import connection
+from optparse import make_option
+import os
+import shutil
+
+class Command(BaseCommand):
+    help = "Update translations of djamnedlies"
+    args = "LANG_CODE"
+    
+    #option_list = BaseCommand.option_list + (
+    #    make_option('--pot', action='store_true', dest='pot', default=False,
+    #        help="create a pot file"),
+    #)        
+
+    output_transaction = False
+
+    def handle(self, *args, **options):
+        if len(args)!=1:
+            return "You have to specify language code as first and only argument."
+        lang_code = args[0]
+
+        # Copy po/ll.po in locale/ll/LC_MESSAGES/django.po
+        podir = os.path.abspath('po')
+        pofile = os.path.join(podir, '%s.po' % lang_code)
+        if os.path.exists(pofile):
+            localedir = os.path.join(os.path.abspath('locale'), lang_code, 'LC_MESSAGES')
+            if not os.path.isdir(localedir):
+                os.makedirs(localedir)
+            shutil.copy(pofile, os.path.join(localedir, 'django.po'))
+        
+        # Extract DB translatable strings into database-content.py
+        dbfile = os.path.join(os.path.abspath('.'), 'database-content.py')
+        f=open(dbfile, 'w')
+        query = """SELECT description FROM team UNION DISTINCT
+                   SELECT name from `language` UNION DISTINCT
+                   SELECT description FROM domain UNION DISTINCT
+                   SELECT description FROM module UNION DISTINCT
+                   SELECT description FROM category UNION DISTINCT
+                   SELECT name from `release`;"""
+        cursor = connection.cursor()
+        cursor.execute(query)
+        for row in cursor.fetchall():
+            if row[0] is not None:
+                f.write("_(u'%s')\n" % row[0].encode('utf-8'))
+        f.close()
+
+        # Run makemessages -l ll
+        makemessages.make_messages(lang_code, verbosity=2, extensions=['.html'])
+        
+        # Delete database-content.py
+        os.unlink(dbfile)
+        
+        # Copy locale/ll/LC_MESSAGES/django.po to po/ll.po
+        shutil.copy(os.path.join(localedir, 'django.po'), pofile)
+        
+        return "po file for language '%s' updated." % lang_code
+
+

Modified: branches/djamnedlies/stats/models.py
==============================================================================
--- branches/djamnedlies/stats/models.py	(original)
+++ branches/djamnedlies/stats/models.py	Fri Oct 24 16:13:09 2008
@@ -23,7 +23,7 @@
 from time import tzname
 from django.db import models, connection
 from django.contrib.auth.models import User, Group
-from django.utils.translation import ungettext, ugettext as _, ugettext_noop as N_
+from django.utils.translation import ungettext, ugettext as _, ugettext_noop
 from stats.conf import settings
 from stats import utils
 import potdiff
@@ -217,7 +217,7 @@
         elif not b.language:
             return 1
         else:
-            res = -cmp(a.Translated, b.Translated)
+            res = -cmp(a.translated, b.translated)
             if not res:
                 res = cmp(a.get_lang(), b.get_lang())
         return res  
@@ -257,7 +257,7 @@
                 if os.access(previous_pot, os.R_OK):
                     # Use old POT file
                     potfile = previous_pot
-                    errors.append(("error", N_("Can't generate POT file, using old one.")))
+                    errors.append(("error", ugettext_noop("Can't generate POT file, using old one.")))
                 else:
                     # Not sure if we should do something here
                     continue
@@ -280,16 +280,16 @@
             errors.extend(pot_stats['errors'])
 
             if potfile != previous_pot and not utils.copy_file(potfile, previous_pot):
-                errors.append(('error', N_("Can't copy new POT file to public location.")))
+                errors.append(('error', ugettext_noop("Can't copy new POT file to public location.")))
 
             try:
                 stat = Statistics.objects.get(language=None, branch=self, domain=dom)
-                stat.Untranslated = int(pot_stats['untranslated'])
-                stat.Date = datetime.now()
+                stat.untranslated = int(pot_stats['untranslated'])
+                stat.date = datetime.now()
                 Information.objects.filter(Statistics=stat).delete()
             except:
-                stat = Statistics(language = None, branch = self, domain = dom, Translated = 0,
-                                  Fuzzy = 0, Untranslated = int(pot_stats['untranslated']))
+                stat = Statistics(language = None, branch = self, domain = dom, translated = 0,
+                                  fuzzy = 0, untranslated = int(pot_stats['untranslated']))
             for err in errors:
                 stat.information_set.add(Information(Type=err[0], Description=err[1]))
             stat.save()
@@ -316,16 +316,16 @@
                     langstats['errors'].extend(utils.check_lang_support(self.co_path(), domain_path, lang))
                 elif dom.dtype == "doc":
                     if lang not in doclinguas:
-                        langstats['errors'].append(("warn", N_("DOC_LINGUAS list doesn't include this language.")))
+                        langstats['errors'].append(("warn", ugettext_noop("DOC_LINGUAS list doesn't include this language.")))
 
                 if settings.DEBUG: print >>sys.stderr, lang + ":\n" + str(langstats)
                 # Save in DB
                 try:
                     stat = Statistics.objects.get(language__locale=lang, branch=self, domain=dom)
-                    stat.Translated = int(langstats['untranslated'])
-                    stat.Fuzzy = int(langstats['fuzzy'])
-                    stat.Untranslated = int(langstats['untranslated'])
-                    stat.Date = datetime.now()
+                    stat.translated = int(langstats['untranslated'])
+                    stat.fuzzy = int(langstats['fuzzy'])
+                    stat.untranslated = int(langstats['untranslated'])
+                    stat.date = datetime.now()
                     Information.objects.filter(Statistics=stat).delete()
                 except:
                     try:
@@ -333,8 +333,8 @@
                     except:
                         language = Language(name=lang, locale=lang)
                         language.save()
-                    stat = Statistics(language = language, branch = self, domain = dom, Translated = int(langstats['translated']),
-                                      Fuzzy = int(langstats['fuzzy']), Untranslated = int(langstats['untranslated']))
+                    stat = Statistics(language = language, branch = self, domain = dom, translated = int(langstats['translated']),
+                                      fuzzy = int(langstats['fuzzy']), untranslated = int(langstats['untranslated']))
                 stat.save()
                 for err in langstats['errors']:
                     stat.information_set.add(Information(Type=err[0], Description=err[1])) 
@@ -619,8 +619,8 @@
             if not stats[dtype]['categs'].has_key(categdescr):
                 stats[dtype]['categs'][categdescr] = {'cattrans':0, 'catfuzzy':0, 
                                                       'catuntrans':0, 'modules':{}}
-            stats[dtype]['totaluntrans'] += stat.Untranslated
-            stats[dtype]['categs'][categdescr]['catuntrans'] += stat.Untranslated
+            stats[dtype]['totaluntrans'] += stat.untranslated
+            stats[dtype]['categs'][categdescr]['catuntrans'] += stat.untranslated
             if not stats[dtype]['categs'][categdescr]['modules'].has_key(modname):
                 # first element is a placeholder for a fake stat
                 stats[dtype]['categs'][categdescr]['modules'][modname] = {' fake':None, domname:stat}
@@ -641,12 +641,12 @@
             categdescr = stat.branch.category.description
             domname = _(stat.domain.description)
             modname = stat.domain.module.name
-            stats[dtype]['totaltrans'] += stat.Translated
-            stats[dtype]['totalfuzzy'] += stat.Fuzzy
-            stats[dtype]['totaluntrans'] -= (stat.Translated + stat.Fuzzy)
-            stats[dtype]['categs'][categdescr]['cattrans'] += stat.Translated
-            stats[dtype]['categs'][categdescr]['catfuzzy'] += stat.Fuzzy
-            stats[dtype]['categs'][categdescr]['catuntrans'] -= (stat.Translated + stat.Fuzzy)
+            stats[dtype]['totaltrans'] += stat.translated
+            stats[dtype]['totalfuzzy'] += stat.fuzzy
+            stats[dtype]['totaluntrans'] -= (stat.translated + stat.fuzzy)
+            stats[dtype]['categs'][categdescr]['cattrans'] += stat.translated
+            stats[dtype]['categs'][categdescr]['catfuzzy'] += stat.fuzzy
+            stats[dtype]['categs'][categdescr]['catuntrans'] -= (stat.translated + stat.fuzzy)
             if stats[dtype]['categs'][categdescr]['modules'][modname][' fake']:
                 stats[dtype]['categs'][categdescr]['modules'][modname][' fake'].trans(stat)
             # Replace POT stat by translated stat
@@ -692,16 +692,10 @@
     domain = models.ForeignKey(Domain) #alter table statistics add domain_id integer REFERENCES "domain" ("id");
     language = models.ForeignKey(Language, null=True) #alter table statistics add language_id integer REFERENCES "language" ("id");
     
-    Module = models.TextField(db_column='module', null=True)
-    # whether this is about a document or UI translation
-    Type = models.CharField(db_column='type', max_length=3, choices=DOMAIN_TYPE_CHOICES, null=True)
-    Domain = models.TextField(db_column='domain', null=True)
-    Branch = models.TextField(db_column='branch', null=True)
-    Language = models.CharField(db_column='language', max_length=15, null=True)
-    Date = models.DateTimeField(db_column='date', auto_now_add=True)
-    Translated = models.IntegerField(db_column='translated', default=0)
-    Fuzzy = models.IntegerField(db_column='fuzzy', default=0)
-    Untranslated = models.IntegerField(db_column='untranslated', default=0)
+    date = models.DateTimeField(auto_now_add=True)
+    translated = models.IntegerField(default=0)
+    fuzzy = models.IntegerField(default=0)
+    untranslated = models.IntegerField(default=0)
 
     class Meta:
         db_table = 'statistics'
@@ -724,19 +718,19 @@
         if self.pot_size() == 0:
             return 0
         else:
-            return int(100*self.Translated/self.pot_size())
+            return int(100*self.translated/self.pot_size())
     
     def fu_percentage(self):
         if self.pot_size() == 0:
             return 0
         else:
-            return int(100*self.Fuzzy/self.pot_size())
+            return int(100*self.fuzzy/self.pot_size())
     
     def un_percentage(self):
         if self.pot_size() == 0:
             return 0
         else:
-            return int(100*self.Untranslated/self.pot_size())
+            return int(100*self.untranslated/self.pot_size())
 
     def get_lang(self):
         if self.language:
@@ -753,7 +747,7 @@
         return self.branch.module.description
         
     def get_translationstat(self):
-        return "%d%%&nbsp;(%d/%d/%d)" % (self.tr_percentage(), self.Translated, self.Fuzzy, self.Untranslated)
+        return "%d%%&nbsp;(%d/%d/%d)" % (self.tr_percentage(), self.translated, self.fuzzy, self.untranslated)
     
     def filename(self):
         if self.Language:
@@ -762,13 +756,13 @@
             return "%s.%s.pot" % (self.domain.potbase(), self.branch.name)
             
     def pot_size(self):
-        return int(self.Translated) + int(self.Fuzzy) + int(self.Untranslated)
+        return int(self.translated) + int(self.fuzzy) + int(self.untranslated)
     
     def pot_text(self):
         """ Return stat table header: 'POT file (n messages) - updated on ??-??-???? tz' """
         #import pdb; pdb.set_trace()
         msg_text = ungettext(u"%(count)s message", "%(count)s messages", self.pot_size()) % {'count': self.pot_size()}
-        upd_text = _(u"updated on %(date)s") % {'date': self.Date.strftime("%Y-%m-%d %H:%M:%S ")+tzname[0]}
+        upd_text = _(u"updated on %(date)s") % {'date': self.date.strftime("%Y-%m-%d %H:%M:%S ")+tzname[0]}
         if self.fig_count():
             fig_text = ungettext(u"%(count)s figure", "%(count)s figures", self.fig_count()) % {'count': self.fig_count()}
             text = _(u"POT file (%(messages)s, %(figures)s) â %(updated)s") % \
@@ -863,42 +857,42 @@
     def __init__(self, module, dtype):
         self.module = module
         self.dtype = dtype
-        self.Translated = 0
-        self.Fuzzy = 0
-        self.Untranslated = 0
+        self.translated = 0
+        self.fuzzy = 0
+        self.untranslated = 0
         self.partial_po = False
     
     def untrans(self, stat):
-        """ Called for POT file, so only Untranslated is concerned """
-        self.Untranslated += stat.Untranslated
+        """ Called for POT file, so only untranslated is concerned """
+        self.untranslated += stat.untranslated
         stat.partial_po = True
     
     def trans(self, stat):
-        self.Translated += stat.Translated
-        self.Fuzzy += stat.Fuzzy
-        self.Untranslated -= (stat.Translated + stat.Fuzzy)
+        self.translated += stat.translated
+        self.fuzzy += stat.fuzzy
+        self.untranslated -= (stat.translated + stat.fuzzy)
         stat.partial_po = True
     
     def is_fake(self):
         return True
         
     def pot_size(self):
-        return int(self.Translated) + int(self.Fuzzy) + int(self.Untranslated)
+        return int(self.translated) + int(self.fuzzy) + int(self.untranslated)
     def tr_percentage(self):
         if self.pot_size() == 0:
             return 0
         else:
-            return int(100*self.Translated/self.pot_size())
+            return int(100*self.translated/self.pot_size())
     def fu_percentage(self):
         if self.pot_size() == 0:
             return 0
         else:
-            return int(100*self.Fuzzy/self.pot_size())
+            return int(100*self.fuzzy/self.pot_size())
     def un_percentage(self):
         if self.pot_size() == 0:
             return 0
         else:
-            return int(100*self.Untranslated/self.pot_size())
+            return int(100*self.untranslated/self.pot_size())
     def module_name(self):
         return self.module.name
     def module_description(self):

Modified: branches/djamnedlies/stats/utils.py
==============================================================================
--- branches/djamnedlies/stats/utils.py	(original)
+++ branches/djamnedlies/stats/utils.py	Fri Oct 24 16:13:09 2008
@@ -19,7 +19,7 @@
 # along with Damned Lies; if not, write to the Free Software Foundation, Inc.,
 # 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-from django.utils.translation import ugettext as _, ugettext_noop as N_
+from django.utils.translation import ugettext as _, ugettext_noop
 from stats.conf import settings
 import sys, os, re, time, commands
 
@@ -56,13 +56,13 @@
 
     if error:
         if settings.DEBUG: print >> sys.stderr, "Error running 'intltool-update -m' check."
-        errors.append( ("error", N_("Errors while running 'intltool-update -m' check.")) )
+        errors.append( ("error", ugettext_noop("Errors while running 'intltool-update -m' check.")) )
 
     missing = os.path.join(po_path, "missing")
     if os.access(missing, os.R_OK):
         f = open(missing, "r")
         errors.append( ("warn",
-                        N_("There are some missing files from POTFILES.in: %s")
+                        ugettext_noop("There are some missing files from POTFILES.in: %s")
                         % ("<ul><li>"
                         + "</li>\n<li>".join(f.readlines())
                         + "</li>\n</ul>")) )
@@ -71,7 +71,7 @@
     if os.access(notexist, os.R_OK):
         f = open(notexist, "r")
         errors.append(("error",
-                       N_("Following files are referenced in either POTFILES.in or POTFILES.skip, yet they don't exist: %s")
+                       ugettext_noop("Following files are referenced in either POTFILES.in or POTFILES.skip, yet they don't exist: %s")
                        % ("<ul><li>"
                        + "</li>\n<li>".join(f.readlines())
                        + "</li>\n</ul>")))
@@ -91,7 +91,7 @@
     potfile = os.path.join(vcs_path, potbase + ".pot")
 
     if error or not os.access(potfile, os.R_OK):
-        return "", (("error", N_("Error regenerating POT file for %s:\n<pre>%s\n%s</pre>")
+        return "", (("error", ugettext_noop("Error regenerating POT file for %s:\n<pre>%s\n%s</pre>")
                              % (potbase, command, output))
                    )
     else:
@@ -103,13 +103,13 @@
     errors = []
     modulename = read_makefile_variable(vcs_path, "DOC_MODULE")
     if not modulename:
-        return "", (("error", N_("Module %s doesn't look like gnome-doc-utils module.") % moduleid))
+        return "", (("error", ugettext_noop("Module %s doesn't look like gnome-doc-utils module.") % moduleid))
     if not os.access(os.path.join(vcs_path, "C", modulename + ".xml"), os.R_OK):
         if os.access(os.path.join(vcs_path, "C", moduleid + ".xml"), os.R_OK):
-            errors.append(("warn", N_("DOC_MODULE doesn't resolve to a real file, using '%s.xml'.") % (moduleid)))
+            errors.append(("warn", ugettext_noop("DOC_MODULE doesn't resolve to a real file, using '%s.xml'.") % (moduleid)))
             modulename = moduleid
         else:
-            errors.append(("error", N_("DOC_MODULE doesn't point to a real file, probably a macro.")))
+            errors.append(("error", ugettext_noop("DOC_MODULE doesn't point to a real file, probably a macro.")))
             return "", errors
     
     files = os.path.join("C", modulename + ".xml")
@@ -124,7 +124,7 @@
     (error, output) = commands.getstatusoutput(command)
     if error:
         errors.append(("error",
-                       N_("Error regenerating POT file for document %s:\n<pre>%s\n%s</pre>")
+                       ugettext_noop("Error regenerating POT file for document %s:\n<pre>%s\n%s</pre>")
                        % (potbase, command, output)))
     if verbose: print >> sys.stderr, output
     
@@ -171,7 +171,7 @@
     errors = []
 
     try: os.stat(pofile)
-    except OSError: errors.append(("error", N_("PO file '%s' doesn't exist.") % pofile))
+    except OSError: errors.append(("error", ugettext_noop("PO file '%s' doesn't exist.") % pofile))
 
     if msgfmt_checks:
         command = "LC_ALL=C LANG=C LANGUAGE=C msgfmt -cv -o /dev/null %s" % pofile
@@ -184,12 +184,12 @@
 
     if error:
         if msgfmt_checks:
-            errors.append(("error", N_("PO file '%s' doesn't pass msgfmt check: not updating.") % (pofile)))
+            errors.append(("error", ugettext_noop("PO file '%s' doesn't pass msgfmt check: not updating.") % (pofile)))
         else:
-            errors.append(("error", N_("Can't get statistics for POT file '%s'.") % (pofile)))
+            errors.append(("error", ugettext_noop("Can't get statistics for POT file '%s'.") % (pofile)))
 
     if msgfmt_checks and os.access(pofile, os.X_OK):
-        errors.append(("warn", N_("This PO file has an executable bit set.")))
+        errors.append(("warn", ugettext_noop("This PO file has an executable bit set.")))
 
     r_tr = re.search(r"([0-9]+) translated", output)
     r_un = re.search(r"([0-9]+) untranslated", output)
@@ -214,7 +214,7 @@
         if error:
             myfile = os.path.basename(pofile)
             errors.append(("warn",
-                           N_("PO file '%s' is not UTF-8 encoded.") % (myfile)))
+                           ugettext_noop("PO file '%s' is not UTF-8 encoded.") % (myfile)))
     return {
         'translated' : translated,
         'fuzzy' : fuzzy,
@@ -247,7 +247,7 @@
                     break
             lfile.close()
             if not in_config:
-                errors.append(("warn", N_("Entry for this language is not present in LINGUAS file.")))
+                errors.append(("warn", ugettext_noop("Entry for this language is not present in LINGUAS file.")))
             return errors
 
     for configure in [configureac, configurein]:
@@ -274,10 +274,10 @@
                     break
             cfile.close()
             if not in_config:
-                errors.append(("warn", N_("Entry for this language is not present in ALL_LINGUAS in configure file.")))
+                errors.append(("warn", ugettext_noop("Entry for this language is not present in ALL_LINGUAS in configure file.")))
             return errors
 
-    errors.append(("warn", N_("Don't know where to look if this language is actually used, ask the module maintainer.")))
+    errors.append(("warn", ugettext_noop("Don't know where to look if this language is actually used, ask the module maintainer.")))
     return errors
 
 def copy_file(file1, file2):

Modified: branches/djamnedlies/templates/language-release-stats.html
==============================================================================
--- branches/djamnedlies/templates/language-release-stats.html	(original)
+++ branches/djamnedlies/templates/language-release-stats.html	Fri Oct 24 16:13:09 2008
@@ -50,7 +50,7 @@
             {% endif %}
             {{ dom.1.module_description }}</a></td>
           {% endif %}
-          <td>{{ dom.1.tr_percentage }}%&nbsp;({{ dom.1.Translated }}/{{ dom.1.Fuzzy }}/{{ dom.1.Untranslated }})</td>
+          <td>{{ dom.1.tr_percentage }}%&nbsp;({{ dom.1.translated }}/{{ dom.1.fuzzy }}/{{ dom.1.untranslated }})</td>
           <td style="width: 108px; text-align: center; background:inherit;"><div class="graph">
               <div class="translated" style="width: {{ dom.1.tr_percentage }}px;"></div>
               <div class="fuzzy" style="left:{{ dom.1.tr_percentage }}px; width:{{ dom.1.fu_percentage }}px;"></div>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]