Skip to content
Snippets Groups Projects
Commit 3beab96c authored by Fabrice Salvaire's avatar Fabrice Salvaire
Browse files

merged make-translation to manage-project

parent 7d0318a5
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,7 @@ import colors # ansicolors @PyPI
from . import Defaults
from . import LogPrinting
from . import Translation
####################################################################################################
......@@ -38,6 +39,29 @@ BASE_DIR = Path(__file__).parents[2].resolve()
####################################################################################################
class FakeArgument:
##############################################
def __init__(self, args, defaults=None):
self._args = dict(defaults) if defaults else {}
for arg in args.split():
if arg:
if '=' in arg:
key, value = arg.split('=')
self._args[key] = value
else:
self._args[arg] = True
##############################################
def __getattr__(self, key):
return self._args.get(key, None)
####################################################################################################
class Shell(cmd.Cmd):
intro = 'Manage ClimbingAssoPortal. Type help or ? to list commands.\n'
......@@ -85,6 +109,15 @@ class Shell(cmd.Cmd):
##############################################
def _check_args(self, args):
if isinstance(args, str):
return FakeArgument(args)
else:
return args
##############################################
def do_quit(self, arg=None):
'Quit shell'
......@@ -145,7 +178,7 @@ class Shell(cmd.Cmd):
'Create superuser'
# use args
args = self._check_args(args)
self._print_banner('Create superuser / admin')
......@@ -209,7 +242,7 @@ class Shell(cmd.Cmd):
'Dump data'
# use args
args = self._check_args(args)
self._print_banner('Dump Data')
......@@ -230,6 +263,27 @@ class Shell(cmd.Cmd):
##############################################
def do_make_message(self, args=None):
'Make Message'
args = self._check_args(args)
make_message = Translation.MakeMessage(Defaults.APPLICATION)
if args.update:
make_message.extract()
if args.init:
make_message.init()
make_message.update()
if args.compile:
make_message.compile()
# poedit
# linguist-qt5
##############################################
def do_all_setup(self, args=None):
'Run all'
......
......@@ -163,6 +163,19 @@ class ArgumentParser:
dump_data_parser.set_defaults(func=shell.do_dump_data)
################################
make_message_parser = subparsers.add_parser(
'make_message',
help='Make Message',
)
make_message_parser.add_argument('--init', action='store_true')
make_message_parser.add_argument('--update', action='store_true')
make_message_parser.add_argument('--compile', action='store_true')
make_message_parser.set_defaults(func=shell.do_make_message)
##############################################
def parse(self):
......
#! /usr/bin/env python3
####################################################################################################
#
# Climbing Asso Portal - A Portal for Climbing Club (Association)
# Copyright (C) 2018 Fabrice Salvaire
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
####################################################################################################
####################################################################################################
#
# See also ./manage.py makemessages
# but --exclude is tricky
#
####################################################################################################
####################################################################################################
from pathlib import Path
import argparse
import os
import subprocess
####################################################################################################
parser = argparse.ArgumentParser(description='Make Translation.')
parser.add_argument('--init', action='store_true')
parser.add_argument('--update', action='store_true')
parser.add_argument('--compile', action='store_true')
args = parser.parse_args()
####################################################################################################
source_path = Path(__file__).parents[1].resolve()
locale_dir = source_path.joinpath('ClimbingAssoPortal', 'locale')
babel_cfg_path = locale_dir.joinpath('babel.cfg')
message_pot_path = locale_dir.joinpath('messages.pot')
domain = 'ClimbingAssoPortal'
####################################################################################################
if args.update:
# Extract localizable messages from a collection of source files
subprocess.call(('pybabel', 'extract',
'-F', babel_cfg_path, # path to the extraction mapping file
'-k', 'lazy_gettext', # keywords to look for in addition to the defaults
'-o', message_pot_path, # path to the output POT file
source_path))
if args.init:
for language in ('en', 'fr'):
if not locale_dir.joinpath(language, 'LC_MESSAGES', 'portal.po').exists:
# Create a new translations catalog based on a PO template file
subprocess.call(('pybabel', 'init',
'-D', domain, # domain of PO file (default 'messages')
'-i', message_pot_path, # name of the input file
'-d', locale_dir, # path to output directory
'-l', language)) # locale for the new localized catalog
# Update an existing new translations catalog based on a PO template file
subprocess.call(('pybabel', 'update',
'-D', domain,
'-i', message_pot_path,
'-d', locale_dir))
if args.compile:
subprocess.call(('pybabel', 'compile',
'-D', domain,
'-d', locale_dir))
# poedit
# linguist-qt5
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment