diff --git a/CHANGELOG b/CHANGELOG index 2d67aa5..0ad42bb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +v 0.9.0 [19-oct-2019] + - Add support for generate locales + - Start support for forms + + v 0.8.0 [13-oct-2019] - Generate manifest - Add support for execute dialogs in documents. diff --git a/VERSION b/VERSION index a3df0a6..ac39a10 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.8.0 +0.9.0 diff --git a/source/conf.py.example b/source/conf.py.example index 9be5aeb..892ab8c 100644 --- a/source/conf.py.example +++ b/source/conf.py.example @@ -206,6 +206,8 @@ PATHS = { 'soffice': ('soffice', PROGRAM, FILE_TEST), 'install': ('unopkg', 'add', '-v', '-f', '-s'), 'profile': '/home/mau/.config/libreoffice/4/user', + 'gettext': PATH_PYGETTEXT, + 'msgmerge': PATH_MSGMERGE, } diff --git a/source/zaz.py b/source/zaz.py index 2cac1bc..9cad0c8 100644 --- a/source/zaz.py +++ b/source/zaz.py @@ -33,6 +33,7 @@ from xml.dom.minidom import parseString from conf import ( DATA, DIRS, + DOMAIN, EXTENSION, FILES, INFO, @@ -138,6 +139,19 @@ def _save(path, data): return +def _get_files(path, filters=''): + paths = [] + if filters in ('*', '*.*'): + filters = '' + for folder, _, files in os.walk(path): + if filters: + pattern = re.compile(r'\.(?:{})$'.format(filters), re.IGNORECASE) + paths += [_join(folder, f) for f in files if pattern.search(f)] + else: + paths += files + return paths + + def _compress_oxt(): log.info('Compress OXT extension...') @@ -435,8 +449,50 @@ def _embed(args): return +def _locales(args): + EASYMACRO = 'easymacro.py' + + if args.files: + files = args.files.split(',') + else: + files = _get_files(DIRS['source'], 'py') + paths = ' '.join([f for f in files if not EASYMACRO in f]) + path_pot = _join(DIRS['source'], DIRS['locales'], '{}.pot'.format(DOMAIN)) + call([PATHS['gettext'], '-o', path_pot, paths]) + log.info('POT generate successfully...') + return + + +def _update(): + path_locales = _join(DIRS['source'], DIRS['locales']) + path_pot = _join(DIRS['source'], DIRS['locales'], '{}.pot'.format(DOMAIN)) + if not _exists(path_pot): + log.error('Not exists file POT...') + return + + files = _get_files(path_locales, 'po') + if not files: + log.error('First, generate files PO...') + return + + for f in files: + call([PATHS['msgmerge'], '-U', f, path_pot]) + log.info('\tUpdate: {}'.format(f)) + + log.info('Locales update successfully...') + return + + def main(args): + if args.update: + _update() + return + + if args.locales: + _locales(args) + return + if args.embed: _embed(args) return @@ -469,6 +525,10 @@ def _process_command_line_arguments(): default=False, required=False) parser.add_argument('-d', '--document', dest='document', default='') parser.add_argument('-f', '--files', dest='files', default='') + parser.add_argument('-l', '--locales', dest='locales', action='store_true', + default=False, required=False) + parser.add_argument('-u', '--update', dest='update', action='store_true', + default=False, required=False) return parser.parse_args()