Zine

open source content publishing system


Changeset 1380:6af61c656d9d for scripts


Ignore:
Timestamp:
07/12/10 04:40:02 (23 months ago)
Author:
Thomas Waldmann <tw AT waldmann-edv DOT de>
Branch:
default
Message:

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.

Location:
scripts
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • scripts/add-translation

    r1279 r1380  
    55    ~~~~~~~~~~~~~~~~~~~ 
    66 
    7     This script adds a new translation to Zine or a Zine plugin. 
     7    This script adds a new translation to the main application or a plugin. 
    88 
    99    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. 
    1010    :license: BSD, see LICENSE for more details. 
    1111""" 
    12 from os import makedirs 
    13 from os.path import dirname, join, realpath, pardir, isdir, isfile 
     12from os import path, makedirs 
    1413from optparse import OptionParser 
    1514from datetime import datetime 
     
    1918from babel.util import LOCALTZ 
    2019 
    21 zine = realpath(join(dirname(__file__), '..', 'zine')) 
     20app_dir = 'zine' 
     21i18n_dir = 'i18n' 
     22app_path = path.realpath(path.join(path.dirname(__file__), path.pardir, app_dir)) 
     23app_i18n_path = path.join(app_path, i18n_dir) 
     24 
    2225 
    2326def main(): 
     
    5760 
    5861def write_catalog(catalog, folder): 
    59     target = join(folder, str(catalog.locale)) 
    60     if not isdir(target): 
     62    target = path.join(folder, str(catalog.locale)) 
     63    if not path.isdir(target): 
    6164        makedirs(target) 
    62     f = file(join(target, 'messages.po'), 'w') 
     65    f = file(path.join(target, 'messages.po'), 'w') 
    6366    try: 
    6467        write_po(f, catalog, width=79) 
     
    6871 
    6972def create_application_lang(locale): 
    70     catalog = create_from_pot(locale, join(zine, 'i18n', 'messages.pot')) 
    71     write_catalog(catalog, join(zine, 'i18n')) 
     73    catalog = create_from_pot(locale, path.join(app_i18n_path, 'messages.pot')) 
     74    write_catalog(catalog, app_i18n_path) 
    7275    print 'Created catalog for %s' % locale 
    7376 
    7477 
    7578def create_plugin_lang(locale, path): 
    76     catalog = create_from_pot(locale, join(path, 'i18n', 'messages.pot')) 
     79    catalog = create_from_pot(locale, path.join(path, i18n_dir, 'messages.pot')) 
    7780 
    7881    # incorporate existing translations from the application 
    79     zinepath = join(zine, 'i18n', str(locale), 'messages.po') 
    80     if isfile(zinepath): 
    81         f = file(zinepath) 
     82    app_messages = path.join(app_i18n_path, str(locale), 'messages.po') 
     83    if path.isfile(app_messages): 
     84        f = file(app_messages) 
    8285        try: 
    8386            translated = read_po(f) 
     
    8992                catalog[message.id].string = message.string 
    9093 
    91     write_catalog(catalog, join(path, 'i18n')) 
     94    write_catalog(catalog, path.join(path, i18n_dir)) 
    9295    print 'Created catalog for %s' % locale 
    9396 
  • scripts/compile-translations

    r1379 r1380  
    55    ~~~~~~~~~~~~~~~~~~~~ 
    66 
    7     Compile translations into (almost) standard MO files and append pickled 
    8     translations for client-side usage by javascript code. 
     7    This script compiles translations of the main application or a plugin. 
     8    It writes standard MO files and then appends pickled translations for 
     9    client-side usage by javascript code. 
    910 
    1011    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. 
     
    1314import pickle 
    1415import struct 
    15 from os import listdir, path 
     16from os import path, listdir 
    1617from optparse import OptionParser 
    1718from babel.messages.pofile import read_po 
     
    1920 
    2021domains = ['messages'] 
     22 
     23app_dir = 'zine' 
     24i18n_dir = 'i18n' 
     25app_path = path.realpath(path.join(path.dirname(__file__), path.pardir, app_dir)) 
     26app_i18n_path = path.join(app_path, i18n_dir) 
    2127 
    2228 
     
    3945    if not args: 
    4046        print 'Compiling builtin languages' 
    41         root = path.abspath(path.join(path.dirname(__file__), 
    42                                       path.pardir, 'zine', 'i18n')) 
     47        root = app_i18n_path 
    4348    elif len(args) == 1: 
    44         root = path.join(path.abspath(args[0]), 'i18n') 
     49        root = path.join(path.abspath(args[0]), i18n_dir) 
    4550        if not path.isdir(root): 
    46             parser.error('i18n folder missing') 
     51            parser.error('%s folder missing' % i18n_dir) 
    4752        print 'Compiling', root 
    4853    else: 
  • scripts/extract-messages

    r1379 r1380  
    55    ~~~~~~~~~~~~~~~~ 
    66 
    7     Extract messages into a PO-Template. 
     7    This script extracts messages from the main application or a plugin and 
     8    writes them into a PO-Template (POT). 
    89 
    910    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. 
     
    1617from babel.messages.pofile import write_po 
    1718 
     19app_dir = 'zine' 
     20i18n_dir = 'i18n' 
     21app_path = path.realpath(path.join(path.dirname(__file__), path.pardir, app_dir)) 
    1822 
    1923KEYWORDS = { 
     
    4751    if not args: 
    4852        print 'Extracting core strings' 
    49         root = path.abspath(path.join(path.dirname(__file__), 
    50                                       path.pardir, 'zine')) 
     53        root = app_path 
    5154    elif len(args) == 1: 
    5255        root = path.join(path.abspath(args[0])) 
     
    7275                    auto_comments=comments) 
    7376 
    74     output_path = path.join(root, 'i18n') 
     77    output_path = path.join(root, i18n_dir) 
    7578    if not path.isdir(output_path): 
    7679        makedirs(output_path) 
  • scripts/update-translations

    r1379 r1380  
    55    ~~~~~~~~~~~~~~~~~~~~~~~ 
    66 
    7     Update the translations from the POT. 
     7    This script updates the translations of the main application or a plugin 
     8    from a POT file. 
    89 
    910    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. 
     
    1920domains = ['messages'] 
    2021 
     22app_dir = 'zine' 
     23i18n_dir = 'i18n' 
     24app_path = path.realpath(path.join(path.dirname(__file__), path.pardir, app_dir)) 
     25 
    2126 
    2227def main(): 
     
    3035    if not args: 
    3136        print 'Updating core strings' 
    32         root = path.abspath(path.join(path.dirname(__file__), 
    33                                       path.pardir, 'zine', 'i18n')) 
     37        root = path.join(app_path, i18n_dir) 
    3438    elif len(args) == 1: 
    35         root = path.join(path.abspath(args[0]), 'i18n') 
     39        root = path.join(path.abspath(args[0]), i18n_dir) 
    3640        if not path.isdir(root): 
    3741            parser.error('source folder missing') 
Note: See TracChangeset for help on using the changeset viewer.