def handler_keydate_saved(sender, **kwargs): """Write file _i18n_keydates.py with key dates to translate.""" # pylint: disable=unused-argument strings = [] for keydate in Keydate.objects.order_by('-date'): strings.append(keydate.text) i18n_autogen('about', 'keydates', strings)
def handler_repo_saved(sender, **kwargs): """Handler called when a Repo is saved.""" # pylint: disable=unused-argument strings = [] for repo in Repo.objects.order_by('priority'): if repo.message: strings.append(repo.message) i18n_autogen('debian', 'repo', strings)
def handler_security_saved(sender, **kwargs): """Write file _i18n_security.py with security issues to translate.""" strings = [] for security in Security.objects.filter(visible=1).order_by('-date'): if security.description: strings.append(security.description) if security.workaround: strings.append(security.workaround) i18n_autogen('download', 'security', strings)
def handler_security_saved(sender, **kwargs): """Write file _i18n_security.py with security issues to translate.""" strings = [] for security in Security.objects.filter(visible=1).order_by('-date'): if security.description: strings.append(security.description) if security.workaround: strings.append(security.workaround) i18n_autogen('doc', 'security', strings)
def handler_info_saved(sender, **kwargs): strings = [] for info in Info.objects.filter(visible=1).order_by("-date"): m = PATTERN_TITLE_VERSION.match(info.title) if m: # if the title is "Version x.y.z", translate only "Version" strings.append(m.group(1)) else: strings.append(info.title) if info.text: strings.append(info.text) i18n_autogen("news", "info", strings)
def handler_info_saved(sender, **kwargs): strings = [] for info in Info.objects.filter(visible=1).order_by('-date'): m = PATTERN_TITLE_VERSION.match(info.title) if m: # if the title is "Version x.y.z", translate only "Version" strings.append(m.group(1)) else: strings.append(info.title) if info.text: strings.append(info.text) i18n_autogen('news', 'info', strings)
def handler_info_saved(sender, **kwargs): """Write file _i18n_info.py with infos to translate.""" # pylint: disable=unused-argument strings = [] for info in Info.objects.filter(visible=1).order_by('-date'): match = PATTERN_TITLE_VERSION.match(info.title) if match: # if the title is "Version x.y.z", translate only "Version" strings.append(match.group(1)) else: strings.append(info.title) if info.text: strings.append(info.text) i18n_autogen('news', 'info', strings)
def handler_repo_saved(sender, **kwargs): strings = [] for repo in Repo.objects.order_by('priority'): if repo.message: strings.append(repo.message) i18n_autogen('debian', 'repo', strings)
def handler_script_changed(sender, **kwargs): """Build files plugins.{xml,json}(.gz) after update/delete of a script.""" xml = '<?xml version="1.0" encoding="utf-8"?>\n' xml += '<plugins>\n' json = '[\n' strings = [] for script in Script.objects.filter(visible=1).order_by('id'): if script.visible and not script.is_legacy(): xml += ' <plugin id="%s">\n' % script.id json += ' {\n' json += ' "id": "%s",\n' % script.id for key, value in script.__dict__.items(): value_i18n = {} if key not in ['_state', 'id', 'visible', 'comment']: if value is None: value = '' else: if key == 'url': # FIXME: use the "Host" from request, but… # request is not available in this handler! value = ('https://weechat.org/%s' % script.build_url()[1:]) elif key == 'mail': value = value.replace('@', ' [at] ') value = value.replace('.', ' [dot] ') elif key == 'md5sum': value = script.md5() elif key.startswith('desc'): if key == 'desc_en': for lang, locale in \ settings.LANGUAGES_LOCALES.items(): if lang[0:2] != 'en': translation.activate(lang) value_i18n['desc_%s' % locale] = \ escape(ugettext(value)) translation.deactivate() value = escape(value) xml += getxmlline(key, value) json += getjsonline(key, value) for field in value_i18n: xml += getxmlline(field, value_i18n[field]) json += getjsonline(field, value_i18n[field]) xml += ' </plugin>\n' json = json[:-2] + '\n },\n' strings.append(( script.desc_en, 'description for script "%s" (%s)' % (script.name_with_extension(), script.version_weechat()), )) xml += '</plugins>\n' json = json[:-2] + '\n]\n' # create plugins.xml filename = files_path_join('plugins.xml') with open(filename, 'w', encoding='utf-8') as _file: _file.write(xml) # create plugins.xml.gz with open(filename, 'rb') as _f_in: _f_out = gzip.open(filename + '.gz', 'wb') _f_out.writelines(_f_in) _f_out.close() # create plugins.json filename = files_path_join('plugins.json') with open(filename, 'w', encoding='utf-8') as _file: _file.write(json) # create plugins.json.gz with open(filename, 'rb') as _f_in: _f_out = gzip.open(filename + '.gz', 'wb') _f_out.writelines(_f_in) _f_out.close() # create _i18n_scripts.py i18n_autogen('scripts', 'scripts', strings)
def handler_plugin_saved(sender, **kwargs): """Build files plugins.{xml,json}(.gz) after update of a script.""" xml = '<?xml version="1.0" encoding="utf-8"?>\n' xml += '<plugins>\n' json = '[\n' strings = [] for plugin in Plugin.objects.filter(visible=1).order_by('id'): if plugin.visible: xml += ' <plugin id="%s">\n' % plugin.id json += ' {\n' json += ' "id": "%s",\n' % plugin.id for key, value in plugin.__dict__.items(): value_i18n = {} if key not in ['_state', 'id', 'visible', 'approval']: if value is None: value = '' else: if key == 'url': # FIXME: use the "Host" from request, but... # request is not available in this handler! value = 'http://www.weechat.org/%s' % \ plugin.build_url()[1:] elif key == 'mail': value = value.replace('@', ' [at] ') value = value.replace('.', ' [dot] ') elif key == 'md5sum': value = plugin.md5() elif key.startswith('desc'): if key == 'desc_en': for lang, locale in \ settings.LANGUAGES_LOCALES.items(): if lang[0:2] != 'en': translation.activate(lang) value_i18n['desc_%s' % locale] = \ escape(ugettext(value)) translation.deactivate() value = escape(value) xml += getxmlline(key, value) json += getjsonline(key, value) for field in value_i18n: xml += getxmlline(field, value_i18n[field]) json += getjsonline(field, value_i18n[field]) xml += ' </plugin>\n' json += ' },\n' strings.append( ( plugin.desc_en, 'description for script "%s" (%s)' % ( plugin.name_with_extension(), plugin.version_weechat()), )) xml += '</plugins>\n' json = json[:-2] json += '\n]\n' # create plugins.xml filename = files_path_join('plugins.xml') with open(filename, 'w') as _file: _file.write(xml.encode('utf-8')) # create plugins.xml.gz with open(filename, 'rb') as _f_in: _f_out = gzip.open(filename + '.gz', 'wb') _f_out.writelines(_f_in) _f_out.close() # create plugins.json filename = files_path_join('plugins.json') with open(filename, 'w') as _file: _file.write(json.encode('utf-8')) # create plugins.json.gz with open(filename, 'rb') as _f_in: _f_out = gzip.open(filename + '.gz', 'wb') _f_out.writelines(_f_in) _f_out.close() # create _i18n_plugins.py i18n_autogen('plugins', 'plugins', strings)
def handler_scripts_changed(sender, **kwargs): """Build files scripts.{xml,json}(.gz) after update/delete of a script.""" # pylint: disable=unused-argument,too-many-locals,too-many-nested-blocks # pylint: disable=too-many-branches,too-many-statements xml = '<?xml version="1.0" encoding="utf-8"?>\n' xml += '<plugins>\n' json_data = [] strings = [] # add disabled reasons in strings to translate reasons = { script.disabled for script in Script.objects.exclude(disabled='') } for reason in reasons: strings.append((reason, 'reason for a disabled script')) # build xml/json content script_list = Script.objects.filter(approved=True).order_by('id') for script in script_list: strings.append(( script.desc_en, (f'description for script "{script.name_with_extension()}" ' f'({script.version_weechat()})'), )) if script.disabled: continue xml += f' <plugin id="{script.id}">\n' json_script = OrderedDict([ ('id', f'{script.id}'), ]) for key, value in script.__dict__.items(): value_i18n = {} if key in ('_state', 'id', 'approved', 'approval'): continue if value is None: value = '' else: if key == 'url': # FIXME: use the "Host" from request, but… # request is not available in this handler! value = f'https://weechat.org/{script.build_url()[1:]}' elif key == 'mail': value = value.replace('@', ' [at] ') value = value.replace('.', ' [dot] ') elif key == 'md5sum': value = script.get_md5sum() elif key == 'sha512sum': value = script.get_sha512sum() elif key == 'desc_en': for lang, locale in settings.LANGUAGES_LOCALES.items(): if lang[0:2] != 'en': translation.activate(lang) value_i18n[f'desc_{locale}'] = ugettext(value) translation.deactivate() value = f'{value}' xml += f' <{key}>{escape(value)}</{key}>\n' json_script[key] = value for field in value_i18n: xml += f' <{field}>{escape(value_i18n[field])}</{field}>\n' json_script[field] = value_i18n[field] xml += ' </plugin>\n' json_data.append(json_script) xml += '</plugins>\n' # create scripts.xml filename = files_path_join('scripts.xml') with open(filename, 'w', encoding='utf-8') as _file: _file.write(xml) # create scripts.xml.gz with open(filename, 'rb') as _f_in: _f_out = gzip.open(filename + '.gz', 'wb') _f_out.writelines(_f_in) _f_out.close() # create scripts.json filename = files_path_join('scripts.json') with open(filename, 'w', encoding='utf-8') as _file: _file.write( json.dumps(json_data, indent=2, ensure_ascii=False, separators=(',', ': '))) # json.dump(json_data, _file) # create scripts.json.gz with open(filename, 'rb') as _f_in: _f_out = gzip.open(filename + '.gz', 'wb') _f_out.writelines(_f_in) _f_out.close() # create _i18n_scripts.py i18n_autogen('scripts', 'scripts', strings)
def handler_keydate_saved(sender, **kwargs): """Write file _i18n_keydates.py with key dates to translate.""" strings = [] for keydate in Keydate.objects.order_by('-date'): strings.append(keydate.text) i18n_autogen('about', 'keydates', strings)
def handler_scripts_changed(sender, **kwargs): """Build files plugins.{xml,json}(.gz) after update/delete of a script.""" xml = '<?xml version="1.0" encoding="utf-8"?>\n' xml += '<plugins>\n' json_data = [] strings = [] for script in Script.objects.filter(visible=1).order_by('id'): if not script.visible or script.is_legacy(): continue xml += ' <plugin id="%s">\n' % script.id json_script = OrderedDict([ ('id', '%s' % script.id), ]) for key, value in script.__dict__.items(): value_i18n = {} if key in ('_state', 'id', 'visible', 'comment'): continue if value is None: value = '' else: if key == 'url': # FIXME: use the "Host" from request, but… # request is not available in this handler! value = ('https://weechat.org/%s' % script.build_url()[1:]) elif key == 'mail': value = value.replace('@', ' [at] ') value = value.replace('.', ' [dot] ') elif key == 'md5sum': value = script.get_md5sum() elif key == 'sha512sum': value = script.get_sha512sum() elif key == 'desc_en': for lang, locale in settings.LANGUAGES_LOCALES.items(): if lang[0:2] != 'en': translation.activate(lang) value_i18n['desc_%s' % locale] = ugettext(value) translation.deactivate() value = '%s' % value xml += ' <%s>%s</%s>\n' % (key, escape(value), key) json_script[key] = value for field in value_i18n: xml += ' <%s>%s</%s>\n' % (field, escape( value_i18n[field]), field) json_script[field] = value_i18n[field] xml += ' </plugin>\n' json_data.append(json_script) strings.append(( script.desc_en, 'description for script "%s" (%s)' % (script.name_with_extension(), script.version_weechat()), )) xml += '</plugins>\n' # create plugins.xml filename = files_path_join('plugins.xml') with open(filename, 'w', encoding='utf-8') as _file: _file.write(xml) # create plugins.xml.gz with open(filename, 'rb') as _f_in: _f_out = gzip.open(filename + '.gz', 'wb') _f_out.writelines(_f_in) _f_out.close() # create plugins.json filename = files_path_join('plugins.json') with open(filename, 'w', encoding='utf-8') as _file: _file.write( json.dumps(json_data, indent=2, ensure_ascii=False, separators=(',', ': '))) # json.dump(json_data, _file) # create plugins.json.gz with open(filename, 'rb') as _f_in: _f_out = gzip.open(filename + '.gz', 'wb') _f_out.writelines(_f_in) _f_out.close() # create _i18n_scripts.py i18n_autogen('scripts', 'scripts', strings)