Changeset 1380:6af61c656d9d for scripts
- Timestamp:
- 07/12/10 04:40:02 (23 months ago)
- Branch:
- default
- Location:
- scripts
- Files:
-
- 4 edited
-
add-translation (modified) (5 diffs)
-
compile-translations (modified) (4 diffs)
-
extract-messages (modified) (4 diffs)
-
update-translations (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
scripts/add-translation
r1279 r1380 5 5 ~~~~~~~~~~~~~~~~~~~ 6 6 7 This script adds a new translation to Zine or a Zineplugin.7 This script adds a new translation to the main application or a plugin. 8 8 9 9 :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. 10 10 :license: BSD, see LICENSE for more details. 11 11 """ 12 from os import makedirs 13 from os.path import dirname, join, realpath, pardir, isdir, isfile 12 from os import path, makedirs 14 13 from optparse import OptionParser 15 14 from datetime import datetime … … 19 18 from babel.util import LOCALTZ 20 19 21 zine = realpath(join(dirname(__file__), '..', 'zine')) 20 app_dir = 'zine' 21 i18n_dir = 'i18n' 22 app_path = path.realpath(path.join(path.dirname(__file__), path.pardir, app_dir)) 23 app_i18n_path = path.join(app_path, i18n_dir) 24 22 25 23 26 def main(): … … 57 60 58 61 def 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): 61 64 makedirs(target) 62 f = file( join(target, 'messages.po'), 'w')65 f = file(path.join(target, 'messages.po'), 'w') 63 66 try: 64 67 write_po(f, catalog, width=79) … … 68 71 69 72 def 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) 72 75 print 'Created catalog for %s' % locale 73 76 74 77 75 78 def 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')) 77 80 78 81 # 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) 82 85 try: 83 86 translated = read_po(f) … … 89 92 catalog[message.id].string = message.string 90 93 91 write_catalog(catalog, join(path, 'i18n'))94 write_catalog(catalog, path.join(path, i18n_dir)) 92 95 print 'Created catalog for %s' % locale 93 96 -
scripts/compile-translations
r1379 r1380 5 5 ~~~~~~~~~~~~~~~~~~~~ 6 6 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. 9 10 10 11 :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. … … 13 14 import pickle 14 15 import struct 15 from os import listdir, path16 from os import path, listdir 16 17 from optparse import OptionParser 17 18 from babel.messages.pofile import read_po … … 19 20 20 21 domains = ['messages'] 22 23 app_dir = 'zine' 24 i18n_dir = 'i18n' 25 app_path = path.realpath(path.join(path.dirname(__file__), path.pardir, app_dir)) 26 app_i18n_path = path.join(app_path, i18n_dir) 21 27 22 28 … … 39 45 if not args: 40 46 print 'Compiling builtin languages' 41 root = path.abspath(path.join(path.dirname(__file__), 42 path.pardir, 'zine', 'i18n')) 47 root = app_i18n_path 43 48 elif len(args) == 1: 44 root = path.join(path.abspath(args[0]), 'i18n')49 root = path.join(path.abspath(args[0]), i18n_dir) 45 50 if not path.isdir(root): 46 parser.error(' i18n folder missing')51 parser.error('%s folder missing' % i18n_dir) 47 52 print 'Compiling', root 48 53 else: -
scripts/extract-messages
r1379 r1380 5 5 ~~~~~~~~~~~~~~~~ 6 6 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). 8 9 9 10 :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. … … 16 17 from babel.messages.pofile import write_po 17 18 19 app_dir = 'zine' 20 i18n_dir = 'i18n' 21 app_path = path.realpath(path.join(path.dirname(__file__), path.pardir, app_dir)) 18 22 19 23 KEYWORDS = { … … 47 51 if not args: 48 52 print 'Extracting core strings' 49 root = path.abspath(path.join(path.dirname(__file__), 50 path.pardir, 'zine')) 53 root = app_path 51 54 elif len(args) == 1: 52 55 root = path.join(path.abspath(args[0])) … … 72 75 auto_comments=comments) 73 76 74 output_path = path.join(root, 'i18n')77 output_path = path.join(root, i18n_dir) 75 78 if not path.isdir(output_path): 76 79 makedirs(output_path) -
scripts/update-translations
r1379 r1380 5 5 ~~~~~~~~~~~~~~~~~~~~~~~ 6 6 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. 8 9 9 10 :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. … … 19 20 domains = ['messages'] 20 21 22 app_dir = 'zine' 23 i18n_dir = 'i18n' 24 app_path = path.realpath(path.join(path.dirname(__file__), path.pardir, app_dir)) 25 21 26 22 27 def main(): … … 30 35 if not args: 31 36 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) 34 38 elif len(args) == 1: 35 root = path.join(path.abspath(args[0]), 'i18n')39 root = path.join(path.abspath(args[0]), i18n_dir) 36 40 if not path.isdir(root): 37 41 parser.error('source folder missing')
Note: See TracChangeset
for help on using the changeset viewer.