Commits

Anonymous committed 6af61c6

translation scripts: made more easily reusable, misc. cleanup (see below)

Made os.path usage more similar for all translation scripts (from os import path).

Made module docstrings more similar and more informative.

Replaced 'Zine' by 'main application'.

Replaced *zine* names by something more generic, e.g. 'app_dir' for the
application package directory (instead of 'zine').

Compute app_path (full path to application package dir) always in the
same way, at same place.

  • Participants
  • Parent commits 5c2fab1

Comments (0)

Files changed (4)

scripts/add-translation

     Add new Translation
     ~~~~~~~~~~~~~~~~~~~
 
-    This script adds a new translation to Zine or a Zine plugin.
+    This script adds a new translation to the main application or a plugin.
 
     :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details.
     :license: BSD, see LICENSE for more details.
 """
-from os import makedirs
-from os.path import dirname, join, realpath, pardir, isdir, isfile
+from os import path, makedirs
 from optparse import OptionParser
 from datetime import datetime
 from babel import Locale, UnknownLocaleError
 from babel.messages.pofile import read_po, write_po
 from babel.util import LOCALTZ
 
-zine = realpath(join(dirname(__file__), '..', 'zine'))
+app_dir = 'zine'
+i18n_dir = 'i18n'
+app_path = path.realpath(path.join(path.dirname(__file__), path.pardir, app_dir))
+app_i18n_path = path.join(app_path, i18n_dir)
+
 
 def main():
     global parser
 
 
 def write_catalog(catalog, folder):
-    target = join(folder, str(catalog.locale))
-    if not isdir(target):
+    target = path.join(folder, str(catalog.locale))
+    if not path.isdir(target):
         makedirs(target)
-    f = file(join(target, 'messages.po'), 'w')
+    f = file(path.join(target, 'messages.po'), 'w')
     try:
         write_po(f, catalog, width=79)
     finally:
 
 
 def create_application_lang(locale):
-    catalog = create_from_pot(locale, join(zine, 'i18n', 'messages.pot'))
-    write_catalog(catalog, join(zine, 'i18n'))
+    catalog = create_from_pot(locale, path.join(app_i18n_path, 'messages.pot'))
+    write_catalog(catalog, app_i18n_path)
     print 'Created catalog for %s' % locale
 
 
 def create_plugin_lang(locale, path):
-    catalog = create_from_pot(locale, join(path, 'i18n', 'messages.pot'))
+    catalog = create_from_pot(locale, path.join(path, i18n_dir, 'messages.pot'))
 
     # incorporate existing translations from the application
-    zinepath = join(zine, 'i18n', str(locale), 'messages.po')
-    if isfile(zinepath):
-        f = file(zinepath)
+    app_messages = path.join(app_i18n_path, str(locale), 'messages.po')
+    if path.isfile(app_messages):
+        f = file(app_messages)
         try:
             translated = read_po(f)
         finally:
             if message.id and message.id in catalog:
                 catalog[message.id].string = message.string
 
-    write_catalog(catalog, join(path, 'i18n'))
+    write_catalog(catalog, path.join(path, i18n_dir))
     print 'Created catalog for %s' % locale
 
 

scripts/compile-translations

     Compile translations
     ~~~~~~~~~~~~~~~~~~~~
 
-    Compile translations into (almost) standard MO files and append pickled
-    translations for client-side usage by javascript code.
+    This script compiles translations of the main application or a plugin.
+    It writes standard MO files and then appends pickled translations for
+    client-side usage by javascript code.
 
     :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details.
     :license: BSD, see LICENSE for more details.
 """
 import pickle
 import struct
-from os import listdir, path
+from os import path, listdir
 from optparse import OptionParser
 from babel.messages.pofile import read_po
 from babel.messages.mofile import write_mo
 
 domains = ['messages']
 
+app_dir = 'zine'
+i18n_dir = 'i18n'
+app_path = path.realpath(path.join(path.dirname(__file__), path.pardir, app_dir))
+app_i18n_path = path.join(app_path, i18n_dir)
+
 
 def is_untranslated(obj):
     if not obj:
     options, args = parser.parse_args()
     if not args:
         print 'Compiling builtin languages'
-        root = path.abspath(path.join(path.dirname(__file__),
-                                      path.pardir, 'zine', 'i18n'))
+        root = app_i18n_path
     elif len(args) == 1:
-        root = path.join(path.abspath(args[0]), 'i18n')
+        root = path.join(path.abspath(args[0]), i18n_dir)
         if not path.isdir(root):
-            parser.error('i18n folder missing')
+            parser.error('%s folder missing' % i18n_dir)
         print 'Compiling', root
     else:
         parser.error('incorrect number of arguments')

scripts/extract-messages

     Extract Messages
     ~~~~~~~~~~~~~~~~
 
-    Extract messages into a PO-Template.
+    This script extracts messages from the main application or a plugin and
+    writes them into a PO-Template (POT).
 
     :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details.
     :license: BSD, see LICENSE for more details.
 from babel.messages.extract import extract_from_dir
 from babel.messages.pofile import write_po
 
+app_dir = 'zine'
+i18n_dir = 'i18n'
+app_path = path.realpath(path.join(path.dirname(__file__), path.pardir, app_dir))
 
 KEYWORDS = {
     '_': None,
     options, args = parser.parse_args()
     if not args:
         print 'Extracting core strings'
-        root = path.abspath(path.join(path.dirname(__file__),
-                                      path.pardir, 'zine'))
+        root = app_path
     elif len(args) == 1:
         root = path.join(path.abspath(args[0]))
         if not path.isdir(root):
         catalog.add(message, None, [(strip_path(filename, root), lineno)],
                     auto_comments=comments)
 
-    output_path = path.join(root, 'i18n')
+    output_path = path.join(root, i18n_dir)
     if not path.isdir(output_path):
         makedirs(output_path)
 

scripts/update-translations

     Update the translations
     ~~~~~~~~~~~~~~~~~~~~~~~
 
-    Update the translations from the POT.
+    This script updates the translations of the main application or a plugin
+    from a POT file.
 
     :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details.
     :license: BSD, see LICENSE for more details.
 
 domains = ['messages']
 
+app_dir = 'zine'
+i18n_dir = 'i18n'
+app_path = path.realpath(path.join(path.dirname(__file__), path.pardir, app_dir))
+
 
 def main():
     global parser
     options, args = parser.parse_args()
     if not args:
         print 'Updating core strings'
-        root = path.abspath(path.join(path.dirname(__file__),
-                                      path.pardir, 'zine', 'i18n'))
+        root = path.join(app_path, i18n_dir)
     elif len(args) == 1:
-        root = path.join(path.abspath(args[0]), 'i18n')
+        root = path.join(path.abspath(args[0]), i18n_dir)
         if not path.isdir(root):
             parser.error('source folder missing')
         print 'Updating', root