8 """ |
8 """ |
9 __docformat__ = "restructuredtext en" |
9 __docformat__ = "restructuredtext en" |
10 |
10 |
11 import sys |
11 import sys |
12 from datetime import datetime |
12 from datetime import datetime |
13 from os import mkdir, chdir |
13 from os import mkdir, chdir, getcwd |
14 from os.path import join, exists, abspath, basename, normpath, split, isdir |
14 from os.path import join, exists, abspath, basename, normpath, split, isdir |
15 from warnings import warn |
15 from warnings import warn |
16 |
16 |
17 from logilab.common import STD_BLACKLIST |
17 from logilab.common import STD_BLACKLIST |
18 from logilab.common.modutils import get_module_files |
18 from logilab.common.modutils import get_module_files |
258 import yams |
258 import yams |
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 = tempfile.mkdtemp() |
262 tempdir = tempfile.mkdtemp() |
263 assert exists(tempdir) |
|
264 potfiles = [join(I18NDIR, 'static-messages.pot')] |
263 potfiles = [join(I18NDIR, 'static-messages.pot')] |
265 print '-> extract schema messages.' |
264 print '-> extract schema messages.' |
266 schemapot = join(tempdir, 'schema.pot') |
265 schemapot = join(tempdir, 'schema.pot') |
267 potfiles.append(schemapot) |
266 potfiles.append(schemapot) |
268 # 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 |
295 print '-> merging main pot file with existing translations.' |
294 print '-> merging main pot file with existing translations.' |
296 chdir(I18NDIR) |
295 chdir(I18NDIR) |
297 toedit = [] |
296 toedit = [] |
298 for lang in LANGS: |
297 for lang in LANGS: |
299 target = '%s.po' % lang |
298 target = '%s.po' % lang |
300 execute('msgmerge -N --sort-output -o %snew %s %s' % (target, cubicwebpot, target)) |
299 execute('msgmerge -N --sort-output -o "%snew" "%s" "%s"' % (target, target, cubicwebpot)) |
301 ensure_fs_mode(target) |
300 ensure_fs_mode(target) |
302 shutil.move('%snew' % target, target) |
301 shutil.move('%snew' % target, target) |
303 assert exists(target) |
|
304 toedit.append(abspath(target)) |
302 toedit.append(abspath(target)) |
305 # cleanup |
303 # cleanup |
306 rm(tempdir) |
304 rm(tempdir) |
307 # instructions pour la suite |
305 # instructions pour la suite |
308 print '-> regenerated CubicWeb\'s .po catalogs.' |
306 print '-> regenerated CubicWeb\'s .po catalogs.' |
390 print '-> create cube-specific catalog' |
388 print '-> create cube-specific catalog' |
391 tmppotfile = join(tempdir, 'generated.pot') |
389 tmppotfile = join(tempdir, 'generated.pot') |
392 cubefiles = find('.', '.py', blacklist=STD_BLACKLIST+('test',)) |
390 cubefiles = find('.', '.py', blacklist=STD_BLACKLIST+('test',)) |
393 cubefiles.append(tali18nfile) |
391 cubefiles.append(tali18nfile) |
394 execute('xgettext --no-location --omit-header -k_ -o %s %s' |
392 execute('xgettext --no-location --omit-header -k_ -o %s %s' |
395 % (tmppotfile, ' '.join(cubefiles))) |
393 % (tmppotfile, ' '.join('"%s"' % f for f in cubefiles))) |
396 if exists(tmppotfile): # doesn't exists of no translation string found |
394 if exists(tmppotfile): # doesn't exists of no translation string found |
397 potfiles.append(tmppotfile) |
395 potfiles.append(tmppotfile) |
398 potfile = join(tempdir, 'cube.pot') |
396 potfile = join(tempdir, 'cube.pot') |
399 print '-> merging %i .pot files:' % len(potfiles) |
397 print '-> merging %i .pot files:' % len(potfiles) |
400 execute('msgcat -o %s %s' % (potfile, |
398 execute('msgcat -o %s %s' % (potfile, |
405 print '-> language', lang |
403 print '-> language', lang |
406 cubepo = '%s.po' % lang |
404 cubepo = '%s.po' % lang |
407 if not exists(cubepo): |
405 if not exists(cubepo): |
408 shutil.copy(potfile, cubepo) |
406 shutil.copy(potfile, cubepo) |
409 else: |
407 else: |
410 execute('msgmerge -N -s -o %snew %s %s' % (cubepo, potfile, cubepo)) |
408 execute('msgmerge -N -s -o %snew %s %s' % (cubepo, cubepo, potfile)) |
411 ensure_fs_mode(cubepo) |
409 ensure_fs_mode(cubepo) |
412 shutil.move('%snew' % cubepo, cubepo) |
410 shutil.move('%snew' % cubepo, cubepo) |
413 toedit.append(abspath(cubepo)) |
411 toedit.append(abspath(cubepo)) |
414 # cleanup |
412 # cleanup |
415 rm(tempdir) |
413 rm(tempdir) |