From 8c34a4fd0a0c8c50018b66d6d3ba00c3e5248955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Sun, 31 Aug 2014 21:59:40 +0200 Subject: [PATCH] Improved support of translation related things in setup.py Allow specifying a locale for refreshing only that translation from extracted messages, new command for just extracting messages. --- setup.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index fb3a6b5b..49b8d03b 100644 --- a/setup.py +++ b/setup.py @@ -79,9 +79,36 @@ class NewTranslation(Command): self.babel_init_messages.run() +class ExtractTranslation(Command): + description = "extract translations" + user_options = [] + boolean_options = [] + + def __init__(self, dist, **kw): + from babel.messages import frontend as babel + self.babel_extract_messages = babel.extract_messages(dist) + Command.__init__(self, dist, **kw) + + def initialize_options(self): + self.babel_extract_messages.initialize_options() + + def finalize_options(self): + self.babel_extract_messages.mapping_file = I18N_MAPPING_FILE + self.babel_extract_messages.output_file = I18N_POT_FILE + self.babel_extract_messages.input_dirs = I18N_INPUT_DIRS + self.babel_extract_messages.msgid_bugs_address = "i18n@octoprint.org" + self.babel_extract_messages.copyright_holder = "The OctoPrint Project" + self.babel_extract_messages.finalize_options() + + def run(self): + self.babel_extract_messages.run() + + class RefreshTranslation(Command): description = "refresh translations" - user_options = [] + user_options = [ + ('locale=', 'l', 'locale for the translation to refresh'), + ] boolean_options = [] def __init__(self, dist, **kw): @@ -91,6 +118,7 @@ class RefreshTranslation(Command): Command.__init__(self, dist, **kw) def initialize_options(self): + self.locale = None self.babel_extract_messages.initialize_options() self.babel_update_messages.initialize_options() @@ -104,6 +132,7 @@ class RefreshTranslation(Command): self.babel_update_messages.input_file = I18N_MAPPING_FILE self.babel_update_messages.output_dir = I18N_OUTPUT_DIR_PY + self.babel_update_messages.locale = self.locale def run(self): self.babel_extract_messages.run() @@ -150,6 +179,7 @@ def get_cmdclass(): cmdclass.update({ 'clean': CleanCommand, 'babel_new': NewTranslation, + 'babel_extract': ExtractTranslation, 'babel_refresh': RefreshTranslation, 'babel_compile': CompileTranslation })