259 from logilab.common.fileutils import ensure_fs_mode |
259 from logilab.common.fileutils import ensure_fs_mode |
260 from logilab.common.shellutils import globfind, find, rm |
260 from logilab.common.shellutils import globfind, find, rm |
261 from cubicweb.common.i18n import extract_from_tal, execute |
261 from cubicweb.common.i18n import extract_from_tal, execute |
262 tempdir = tempdir.mkdtemp() |
262 tempdir = tempdir.mkdtemp() |
263 potfiles = [join(I18NDIR, 'entities.pot')] |
263 potfiles = [join(I18NDIR, 'entities.pot')] |
264 print '******** extract schema messages' |
264 print '-> extract schema messages.' |
265 schemapot = join(tempdir, 'schema.pot') |
265 schemapot = join(tempdir, 'schema.pot') |
266 potfiles.append(schemapot) |
266 potfiles.append(schemapot) |
267 # explicit close necessary else the file may not be yet flushed when |
267 # explicit close necessary else the file may not be yet flushed when |
268 # we'll using it below |
268 # we'll using it below |
269 schemapotstream = file(schemapot, 'w') |
269 schemapotstream = file(schemapot, 'w') |
270 generate_schema_pot(schemapotstream.write, cubedir=None) |
270 generate_schema_pot(schemapotstream.write, cubedir=None) |
271 schemapotstream.close() |
271 schemapotstream.close() |
272 print '******** extract TAL messages' |
272 print '-> extract TAL messages.' |
273 tali18nfile = join(tempdir, 'tali18n.py') |
273 tali18nfile = join(tempdir, 'tali18n.py') |
274 extract_from_tal(find(join(BASEDIR, 'web'), ('.py', '.pt')), tali18nfile) |
274 extract_from_tal(find(join(BASEDIR, 'web'), ('.py', '.pt')), tali18nfile) |
275 print '******** .pot files generation' |
275 print '-> generate .pot files.' |
276 for id, files, lang in [('pycubicweb', get_module_files(BASEDIR) + list(globfind(join(BASEDIR, 'misc', 'migration'), '*.py')), None), |
276 for id, files, lang in [('pycubicweb', get_module_files(BASEDIR) + list(globfind(join(BASEDIR, 'misc', 'migration'), '*.py')), None), |
277 ('schemadescr', globfind(join(BASEDIR, 'schemas'), '*.py'), None), |
277 ('schemadescr', globfind(join(BASEDIR, 'schemas'), '*.py'), None), |
278 ('yams', get_module_files(yams.__path__[0]), None), |
278 ('yams', get_module_files(yams.__path__[0]), None), |
279 ('tal', [tali18nfile], None), |
279 ('tal', [tali18nfile], None), |
280 ('js', globfind(join(BASEDIR, 'web'), 'cub*.js'), 'java'), |
280 ('js', globfind(join(BASEDIR, 'web'), 'cub*.js'), 'java'), |
329 |
328 |
330 def update_cubes_catalogs(cubes): |
329 def update_cubes_catalogs(cubes): |
331 toedit = [] |
330 toedit = [] |
332 for cubedir in cubes: |
331 for cubedir in cubes: |
333 if not isdir(cubedir): |
332 if not isdir(cubedir): |
334 print 'not a directory', cubedir |
333 print '-> ignoring %s that is not a directory.' % cubedir |
335 continue |
334 continue |
336 try: |
335 try: |
337 toedit += update_cube_catalogs(cubedir) |
336 toedit += update_cube_catalogs(cubedir) |
338 except Exception: |
337 except Exception: |
339 import traceback |
338 import traceback |
340 traceback.print_exc() |
339 traceback.print_exc() |
341 print 'error while updating catalogs for', cubedir |
340 print '-> Error while updating catalogs for cube', cubedir |
342 # instructions pour la suite |
341 # instructions pour la suite |
343 print '*' * 72 |
342 print '-> regenerated this cube\'s .po catalogs.' |
344 print 'you can now edit the following files:' |
343 print '\nYou can now edit the following files:' |
345 print '* ' + '\n* '.join(toedit) |
344 print '* ' + '\n* '.join(toedit) |
346 |
345 print 'when you are done, run "cubicweb-ctl i18ninstance yourinstance".' |
347 |
346 |
348 def update_cube_catalogs(cubedir): |
347 def update_cube_catalogs(cubedir): |
349 import shutil |
348 import shutil |
350 import tempfile |
349 import tempfile |
351 from logilab.common.fileutils import ensure_fs_mode |
350 from logilab.common.fileutils import ensure_fs_mode |
352 from logilab.common.shellutils import find, rm |
351 from logilab.common.shellutils import find, rm |
353 from cubicweb.common.i18n import extract_from_tal, execute |
352 from cubicweb.common.i18n import extract_from_tal, execute |
354 toedit = [] |
353 toedit = [] |
355 cube = basename(normpath(cubedir)) |
354 cube = basename(normpath(cubedir)) |
356 tempdir = tempfile.mkdtemp() |
355 tempdir = tempfile.mkdtemp() |
357 print '*' * 72 |
356 print underline_title('Updating i18n catalogs for cube %s' % cube) |
358 print 'updating %s cube...' % cube |
|
359 chdir(cubedir) |
357 chdir(cubedir) |
360 potfiles = [join('i18n', scfile) for scfile in ('entities.pot',) |
358 potfiles = [join('i18n', scfile) for scfile in ('entities.pot',) |
361 if exists(join('i18n', scfile))] |
359 if exists(join('i18n', scfile))] |
362 print '******** extract schema messages' |
360 print '-> extract schema messages' |
363 schemapot = join(tempdir, 'schema.pot') |
361 schemapot = join(tempdir, 'schema.pot') |
364 potfiles.append(schemapot) |
362 potfiles.append(schemapot) |
365 # explicit close necessary else the file may not be yet flushed when |
363 # explicit close necessary else the file may not be yet flushed when |
366 # we'll using it below |
364 # we'll using it below |
367 schemapotstream = file(schemapot, 'w') |
365 schemapotstream = file(schemapot, 'w') |
368 generate_schema_pot(schemapotstream.write, cubedir) |
366 generate_schema_pot(schemapotstream.write, cubedir) |
369 schemapotstream.close() |
367 schemapotstream.close() |
370 print '******** extract TAL messages' |
368 print '-> extract TAL messages' |
371 tali18nfile = join(tempdir, 'tali18n.py') |
369 tali18nfile = join(tempdir, 'tali18n.py') |
372 extract_from_tal(find('.', ('.py', '.pt'), blacklist=STD_BLACKLIST+('test',)), tali18nfile) |
370 extract_from_tal(find('.', ('.py', '.pt'), blacklist=STD_BLACKLIST+('test',)), tali18nfile) |
373 print '******** extract Javascript messages' |
371 print '-> extract Javascript messages' |
374 jsfiles = [jsfile for jsfile in find('.', '.js') if basename(jsfile).startswith('cub')] |
372 jsfiles = [jsfile for jsfile in find('.', '.js') if basename(jsfile).startswith('cub')] |
375 if jsfiles: |
373 if jsfiles: |
376 tmppotfile = join(tempdir, 'js.pot') |
374 tmppotfile = join(tempdir, 'js.pot') |
377 execute('xgettext --no-location --omit-header -k_ -L java --from-code=utf-8 -o %s %s' |
375 execute('xgettext --no-location --omit-header -k_ -L java --from-code=utf-8 -o %s %s' |
378 % (tmppotfile, ' '.join(jsfiles))) |
376 % (tmppotfile, ' '.join(jsfiles))) |
379 # no pot file created if there are no string to translate |
377 # no pot file created if there are no string to translate |
380 if exists(tmppotfile): |
378 if exists(tmppotfile): |
381 potfiles.append(tmppotfile) |
379 potfiles.append(tmppotfile) |
382 print '******** create cube specific catalog' |
380 print '-> create cube-specific catalog' |
383 tmppotfile = join(tempdir, 'generated.pot') |
381 tmppotfile = join(tempdir, 'generated.pot') |
384 cubefiles = find('.', '.py', blacklist=STD_BLACKLIST+('test',)) |
382 cubefiles = find('.', '.py', blacklist=STD_BLACKLIST+('test',)) |
385 cubefiles.append(tali18nfile) |
383 cubefiles.append(tali18nfile) |
386 execute('xgettext --no-location --omit-header -k_ -o %s %s' |
384 execute('xgettext --no-location --omit-header -k_ -o %s %s' |
387 % (tmppotfile, ' '.join(cubefiles))) |
385 % (tmppotfile, ' '.join(cubefiles))) |
388 if exists(tmppotfile): # doesn't exists of no translation string found |
386 if exists(tmppotfile): # doesn't exists of no translation string found |
389 potfiles.append(tmppotfile) |
387 potfiles.append(tmppotfile) |
390 potfile = join(tempdir, 'cube.pot') |
388 potfile = join(tempdir, 'cube.pot') |
391 print '******** merging .pot files' |
389 print '-> merging %i .pot files:' % len(potfiles) |
392 execute('msgcat %s > %s' % (' '.join(potfiles), potfile)) |
390 execute('msgcat %s > %s' % (' '.join(potfiles), potfile)) |
393 print '******** merging main pot file with existing translations' |
391 print '-> merging main pot file with existing translations:' |
394 chdir('i18n') |
392 chdir('i18n') |
395 for lang in LANGS: |
393 for lang in LANGS: |
396 print '****', lang |
394 print '-> language', lang |
397 cubepo = '%s.po' % lang |
395 cubepo = '%s.po' % lang |
398 if not exists(cubepo): |
396 if not exists(cubepo): |
399 shutil.copy(potfile, cubepo) |
397 shutil.copy(potfile, cubepo) |
400 else: |
398 else: |
401 execute('msgmerge -N -s %s %s > %snew' % (cubepo, potfile, cubepo)) |
399 execute('msgmerge -N -s %s %s > %snew' % (cubepo, potfile, cubepo)) |