Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testI18Ngenerator(self):
'''Runs the i18ngenerator'''
ctl = {}
ctl['plone'] = catalog.MessageCatalog(domain='plone')
# global actions
for provider in self.action_tool.listActionProviders():
provider_tool = getToolByName(self.portal, provider, None)
for action in provider_tool.listActions():
title = norm(action.title)
if action.visible:
ctl['plone'].add(title, msgstr=title, references=['action defined in %s' % provider])
# description of action icons
for icon in self.ai_tool.listActionIcons():
title= icon.getTitle()
ctl['plone'].add(title, msgstr=title, references=['action_icon id %s - category %s' % (icon.getIconURL(), icon.getCategory())])
# workflow states and worflow transitions
for attype in self.at_tool.listRegisteredTypes():
# typename = attype['name']
schema = attype['schema']
for field in schema.fields():
if not isinstance(field, ReferenceField):
domain = field.widget.__dict__.get('i18n_domain')
vocab = field.Vocabulary()
if isinstance(vocab, DisplayList):
for key in vocab:
value = vocab.getValue(key)
if len(value) > 1:
msgid = vocab.getMsgId(key)
if domain == None:
domain = 'plone'
if not domain in ctl.keys():
ctl[domain] = catalog.MessageCatalog(domain=domain)
ctl[domain].add(msgid, msgstr=value, references=['DisplayList entry for field %s' % field.getName()])
# archetypes widgets XXX Should be merged with the DisplayList stuff
for widget in self.at_tool.getWidgets():
w = widget._args.get('widget')
dict = w.__dict__
domain = dict.get('i18n_domain')
if domain:
if not domain in ctl.keys():
ctl[domain] = catalog.MessageCatalog(domain=domain)
label = dict.get('label')
label_msgid = dict.get('label_msgid')
desc = norm(dict.get('description'))
desc_msgid = dict.get('description_msgid')
sys.exit(1)
product = getLongProductName(sys.argv[1])
projectid = sys.argv[2]
os.chdir('..')
os.chdir('i18n')
poFiles = getPoFiles(product, all=True)
if poFiles == []:
print('No po-files were found for the given product.')
sys.exit(2)
for poFile in poFiles:
try:
po_ctl = catalog.MessageCatalog(filename=poFile)
except IOError as e:
print('I/O Error: %s' % e, file=sys.stderr)
po_ctl.mime_header['Project-Id-Version'] = projectid
file = open(poFile, 'w')
writer = catalog.POWriter(file, po_ctl)
writer.write(sort=False)
print('You have to specify the product.')
sys.exit(1)
product = getLongProductName(sys.argv[1])
os.chdir('..')
os.chdir('i18n')
poFiles = getPoFiles(product, all=True)
if poFiles == []:
print('No po-files were found for the given product.')
sys.exit(2)
for poFile in poFiles:
try:
po_ctl = catalog.MessageCatalog(filename=poFile)
except IOError as e:
print('I/O Error: %s' % e, file=sys.stderr)
try:
language = po_ctl.commentary_header[0].split('to ')[1:][0]
po_ctl.commentary_header[0] = 'Translation of '+product+'.pot to '+language
except IndexError:
print(poFile)
file = open(poFile+'-new', 'w')
writer = catalog.POWriter(file, po_ctl)
writer.write(sort=False)
os.chdir('..')
os.chdir('i18n')
poFiles = getPoFiles(product, all=True)
if poFiles == []:
print('No po-files were found for the given product.')
sys.exit(2)
for poFile in poFiles:
try:
po_ctl = catalog.MessageCatalog(filename=poFile)
except IOError as e:
print('I/O Error: %s' % e, file=sys.stderr)
po_ctl.mime_header['Domain'] = domain
file = open(poFile, 'w')
writer = catalog.POWriter(file, po_ctl)
writer.write(sort=False)
os.chdir('..')
os.chdir('i18n')
poFiles = getPoFiles(product, all=True)
if poFiles == []:
print('No po-files were found for the given product.')
sys.exit(2)
for poFile in poFiles:
try:
po_ctl = catalog.MessageCatalog(filename=poFile)
except IOError as e:
print('I/O Error: %s' % e, file=sys.stderr)
po_ctl.mime_header['Project-Id-Version'] = projectid
file = open(poFile, 'w')
writer = catalog.POWriter(file, po_ctl)
writer.write(sort=False)
sys.exit(2)
for poFile in poFiles:
try:
po_ctl = catalog.MessageCatalog(filename=poFile)
except IOError as e:
print('I/O Error: %s' % e, file=sys.stderr)
try:
language = po_ctl.commentary_header[0].split('to ')[1:][0]
po_ctl.commentary_header[0] = 'Translation of '+product+'.pot to '+language
except IndexError:
print(poFile)
file = open(poFile+'-new', 'w')
writer = catalog.POWriter(file, po_ctl)
writer.write(sort=False)
sys.exit(1)
product = getLongProductName(sys.argv[1])
domain = sys.argv[2]
os.chdir('..')
os.chdir('i18n')
poFiles = getPoFiles(product, all=True)
if poFiles == []:
print('No po-files were found for the given product.')
sys.exit(2)
for poFile in poFiles:
try:
po_ctl = catalog.MessageCatalog(filename=poFile)
except IOError as e:
print('I/O Error: %s' % e, file=sys.stderr)
po_ctl.mime_header['Domain'] = domain
file = open(poFile, 'w')
writer = catalog.POWriter(file, po_ctl)
writer.write(sort=False)
product = sys.argv[1]
os.chdir('..')
poFiles = getPoFiles(product, all=True)
if poFiles == '':
print 'No po-files were found for the given product.'
sys.exit(2)
old = sys.argv[2]
new = sys.argv[3]
for poFile in poFiles:
try:
po_ctl = catalog.MessageCatalog(filename=poFile)
except IOError, e:
print >> sys.stderr, 'I/O Error: %s' % e
try:
msgids = po_ctl.keys()
if old in msgids:
if new in msgids:
print 'New message already in %s' % poFile
else:
po_ctl[new] = po_ctl.get(old)
print 'Copied %s into %s in file %s' % (old, new, poFile)
else:
print 'Old message not found in %s' % poFile
except IndexError:
print poFile
'label_related_items', 'label_short_name',
'label_string_criteria_value', 'label_url',
]
}
# make sure we only try on languages for which both po files exist
ploneLanguages = [getLanguage('plone', p) for p in poFilesPlone]
atctLanguages = [getLanguage('atcontenttypes', p) for p in poFilesATCT]
languages = [l for l in ploneLanguages if l in atctLanguages and l != 'en']
changes = {'plone' : False, 'atcontenttypes' : False}
for lang in languages:
po_ctl = {}
try:
po_ctl['plone'] = catalog.MessageCatalog(filename='plone-%s.po' % lang)
except IOError as e:
print('I/O Error: %s' % e, file=sys.stderr)
try:
po_ctl['atcontenttypes'] = catalog.MessageCatalog(filename='atcontenttypes-%s.po' % lang)
except IOError as e:
print('I/O Error: %s' % e, file=sys.stderr)
changes = {'plone' : False, 'atcontenttypes' : False}
relocate_domain = {'plone' : 'atcontenttypes', 'atcontenttypes' : 'plone'}
msgids = {}
msgids['plone'] = list(po_ctl['plone'].keys())
msgids['atcontenttypes'] = list(po_ctl['atcontenttypes'].keys())
for old_domain in relocated: