Back to index

plone3  3.1.7
Functions | Variables
relocate Namespace Reference

Functions

def main

Variables

tuple __PYTHON = os.environ.get('PYTHON', 'python')
tuple __I18NDUDE = os.environ.get('I18NDUDE', 'i18ndude')

Detailed Description

   Usage: relocate.py

   As we moved quite some messages between domains lately, this script
   automates this process, so it can be repeatedly and safely called on po
   files to preserve translations.

   Note that PYTHON and I18NDUDE must have been set as enviroment variables
   before calling this script

Function Documentation

def relocate.main ( )

Definition at line 20 of file relocate.py.

00020 
00021 def main():
00022     os.chdir('..')
00023     os.chdir('i18n')
00024 
00025     poFilesPlone = getPoFiles('plone')
00026     if not poFilesPlone:
00027         print 'No po-files were found for Plone.'
00028         sys.exit(2)
00029 
00030     poFilesATCT = getPoFiles('atcontenttypes')
00031     if not poFilesATCT:
00032         print 'No po-files were found for ATContentTypes.'
00033         sys.exit(3)
00034 
00035     # format: 'old-domain' : ['msgid1', 'msgid2', ...]
00036     relocated = {'plone' :
00037                   ['Changes saved.', 'Please correct the indicated errors.',
00038                    'Rotate 180', 'help_boolean_criteria_bool',
00039                    'help_criteria_field_name', 'help_custom_view',
00040                    'help_custom_view_fields', 'help_date_range_criteria_end',
00041                    'help_date_range_criteria_start', 'help_exclude_from_nav',
00042                    'help_limit_number', 'help_news_image', 'help_shortname',
00043                    'help_path_criteria_value', 'help_string_criteria_value',
00044                    'help_portal_type_criteria_value', 'help_url',
00045                    'label_body_text', 'label_boolean_criteria_bool',
00046                    'label_contact_email', 'label_contact_name',
00047                    'label_contact_phone', 'label_criteria_field_name',
00048                    'label_custom_view', 'label_custom_view_fields',
00049                    'label_date_range_criteria_end', 'label_event_announcement',
00050                    'label_date_range_criteria_start', 'label_event_attendees',
00051                    'label_event_end', 'label_event_location',
00052                    'label_event_start', 'label_event_type',
00053                    'label_exclude_from_nav', 'label_file', 'label_image',
00054                    'label_image_caption', 'label_inherit_criteria',
00055                    'label_item_count', 'label_limit_number', 'label_news_image',
00056                    'label_path_criteria_recurse', 'label_path_criteria_value',
00057                    'label_related_items', 'label_short_name',
00058                    'label_string_criteria_value', 'label_url',
00059                   ]
00060                 }
00061 
00062     # make sure we only try on languages for which both po files exist
00063     ploneLanguages = [getLanguage('plone', p) for p in poFilesPlone]
00064     atctLanguages = [getLanguage('atcontenttypes', p) for p in poFilesATCT]
00065 
00066     languages = [l for l in ploneLanguages if l in atctLanguages and l != 'en']
00067     changes = {'plone' : False, 'atcontenttypes' : False}
00068 
00069     for lang in languages:
00070         po_ctl = {}
00071         try:
00072             po_ctl['plone'] = catalog.MessageCatalog(filename='plone-%s.po' % lang)
00073         except IOError, e:
00074             print >> sys.stderr, 'I/O Error: %s' % e
00075         try:
00076             po_ctl['atcontenttypes'] = catalog.MessageCatalog(filename='atcontenttypes-%s.po' % lang)
00077         except IOError, e:
00078             print >> sys.stderr, 'I/O Error: %s' % e
00079 
00080         changes = {'plone' : False, 'atcontenttypes' : False}
00081 
00082         relocate_domain = {'plone' : 'atcontenttypes', 'atcontenttypes' : 'plone'}
00083 
00084         msgids = {}
00085         msgids['plone'] = po_ctl['plone'].keys()
00086         msgids['atcontenttypes'] = po_ctl['atcontenttypes'].keys()
00087 
00088         for old_domain in relocated:
00089             relocate_msgids = relocated.get(old_domain)
00090             for relocate_msgid in relocate_msgids:
00091                 if relocate_msgid in msgids[old_domain]:
00092                     msgstr = po_ctl[old_domain].get(relocate_msgid)
00093                     # We copy over messages for now
00094                     # del po_ctl[old_domain][relocate_msgid]
00095                     changes[old_domain] = True
00096 
00097                     new_domain = relocate_domain.get(old_domain)
00098                     if relocate_msgid in msgids[new_domain]:
00099                         old_msgstr = po_ctl[new_domain].get(relocate_msgid)
00100                         if old_msgstr.msgstr == '' and msgstr:
00101                             po_ctl[new_domain][relocate_msgid] = msgstr
00102                             changes[new_domain] = True
00103                             print 'copied msgstr for %s' % relocate_msgid
00104                         #else:
00105                         #    print '%s was already there' % relocate_msgid
00106                     else:
00107                         po_ctl[new_domain][relocate_msgid] = msgstr
00108                         changes[new_domain] = True
00109                         print 'copied %s to %s-%s.po' % (relocate_msgid, new_domain, lang)
00110                 #else:
00111                 #    print '%s was not found anymore' % relocate_msgid
00112 
00113         for domain in changes:
00114             if changes[domain]:
00115                 file = open('%s-%s.po' % (domain, lang), 'w')
00116                 writer = catalog.POWriter(file, po_ctl[domain])
00117                 writer.write(sort=True)

Here is the call graph for this function:


Variable Documentation

tuple relocate.__I18NDUDE = os.environ.get('I18NDUDE', 'i18ndude')

Definition at line 18 of file relocate.py.

tuple relocate.__PYTHON = os.environ.get('PYTHON', 'python')

Definition at line 17 of file relocate.py.