Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
PACKAGE_HOME = os.path.join(PACKAGE_HOME, '..')
i18ndir = os.path.normpath(PACKAGE_HOME)
tests=[]
products=[]
pots={}
pot_catalogs={}
pot_lens={}
for potFile in getPotFiles(path=i18ndir):
product = getProductFromPath(potFile)
if product not in products:
products.append(product)
if product not in pot_catalogs:
cat = catalog.MessageCatalog(filename=potFile)
cat_len = len(cat)
pots.update({product: potFile})
pot_catalogs.update({product: cat})
pot_lens.update({product: cat_len})
for product in products:
class TestOnePOT(PotTestCase.PotTestCase):
product = product
pot = pots[product]
tests.append(TestOnePOT)
for poFile in getPoFiles(path=i18ndir, product=product):
class TestOnePoFile(PoTestCase.PoTestCase):
po = poFile
product = product
pot_cat = pot_catalogs[product]
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
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')
if label_msgid and label:
ctl[domain].add(label_msgid, label, references=['widget label of %s - description \"%s\"' % (w.getName(), desc)])
if desc_msgid and desc:
ctl[domain].add(desc_msgid, desc, references=['widget description of %s for label %s' % (w.getName(), label)])
domains = ctl.keys()
for domain in domains:
file = open('%s-generated.pot' % domain, 'w')
writer = catalog.POWriter(file, ctl[domain])
writer.write(sort=True, msgstrToComment=True)
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)