From c4bf21c3ed4e47746760509f4283d0209b534eb1 Mon Sep 17 00:00:00 2001 From: Rick Calixte <10281587+rcalixte@users.noreply.github.com> Date: Mon, 5 Feb 2024 15:26:48 -0500 Subject: [PATCH] Rewrite cinnamon-spices-makepot: (#564) New features: * Automatic updating of translations when the template is updated * Updated header format * Add translation support for Glade files and shell scripts --- .../po/cinnamon-dynamic-wallpaper@TobiZog.pot | 39 +-- .../po/es.po | 56 +--- cinnamon-spices-makepot | 279 +++++++++--------- 3 files changed, 173 insertions(+), 201 deletions(-) diff --git a/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/po/cinnamon-dynamic-wallpaper@TobiZog.pot b/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/po/cinnamon-dynamic-wallpaper@TobiZog.pot index d87ef83b..8073898e 100644 --- a/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/po/cinnamon-dynamic-wallpaper@TobiZog.pot +++ b/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/po/cinnamon-dynamic-wallpaper@TobiZog.pot @@ -1,21 +1,20 @@ # SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER -# This file is distributed under the same license as the PACKAGE package. +# This file is put in the public domain. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" -"Project-Id-Version: \n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-02-04 13:24-0500\n" -"PO-Revision-Date: \n" -"Last-Translator: \n" -"Language-Team: \n" +"Project-Id-Version: cinnamon-dynamic-wallpaper@TobiZog 2.2\n" +"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-extensions/issues\n" +"POT-Creation-Date: 2024-02-05 14:52-0500\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 3.4.2\n" #: 5.4/extension.js:127 msgid "Open settings" @@ -26,8 +25,7 @@ msgid "Cinnamon Dynamic Wallpaper" msgstr "" #. metadata.json->description -msgid "" -"Cinnamon extension for dynamic desktop backgrounds based on time and location" +msgid "Cinnamon extension for dynamic desktop backgrounds based on time and location" msgstr "" #: 5.4/res/preferences.glade:135 @@ -266,11 +264,7 @@ msgid "About the project" msgstr "" #: 5.4/res/preferences.glade:2687 -msgid "" -"Based on a location or by user choice, this extensions calculates the " -"periods of a day and switches the background image of your Cinnamon desktop. " -"The extension offers as image sources a set of preconfigured wallpapers, a " -"heic image import by the user or a custom folder with single images." +msgid "Based on a location or by user choice, this extensions calculates the periods of a day and switches the background image of your Cinnamon desktop. The extension offers as image sources a set of preconfigured wallpapers, a heic image import by the user or a custom folder with single images." msgstr "" #: 5.4/res/preferences.glade:2706 @@ -278,9 +272,7 @@ msgid "Developed by TobiZog" msgstr "" #: 5.4/res/preferences.glade:2723 -msgid "" -"If you need more information or want to rate the extension, you can visit " -"the Cinnamon Spices Website." +msgid "If you need more information or want to rate the extension, you can visit the Cinnamon Spices Website." msgstr "" #: 5.4/res/preferences.glade:2734 @@ -292,9 +284,7 @@ msgid "Source Code" msgstr "" #: 5.4/res/preferences.glade:2788 -msgid "" -"This project is Open Source. You can take a look inside the whole source " -"code of this extension on GitHub." +msgid "This project is Open Source. You can take a look inside the whole source code of this extension on GitHub." msgstr "" #: 5.4/res/preferences.glade:2799 @@ -306,10 +296,7 @@ msgid "Issues and Enhancements" msgstr "" #: 5.4/res/preferences.glade:2853 -msgid "" -"Do you find an issue? Or want a new feature? Go to the GitHub repository and " -"create a new issue. If you find an error message in the logs above, add it " -"to the issue report." +msgid "Do you find an issue? Or want a new feature? Go to the GitHub repository and create a new issue. If you find an error message in the logs above, add it to the issue report." msgstr "" #: 5.4/res/preferences.glade:2864 diff --git a/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/po/es.po b/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/po/es.po index 6bf10d34..5dec9b2d 100644 --- a/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/po/es.po +++ b/cinnamon-dynamic-wallpaper@TobiZog/files/cinnamon-dynamic-wallpaper@TobiZog/po/es.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-02-04 13:24-0500\n" +"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-extensions/issues\n" +"POT-Creation-Date: 2024-02-05 14:52-0500\n" "PO-Revision-Date: 2024-02-04 22:02-0300\n" "Last-Translator: \n" "Language-Team: \n" @@ -26,11 +26,8 @@ msgid "Cinnamon Dynamic Wallpaper" msgstr "Fondo de pantalla dinámico de Cinnamon" #. metadata.json->description -msgid "" -"Cinnamon extension for dynamic desktop backgrounds based on time and location" -msgstr "" -"Extensión de Cinnamon para fondos de pantalla dinámicos según la hora y la " -"ubicación" +msgid "Cinnamon extension for dynamic desktop backgrounds based on time and location" +msgstr "Extensión de Cinnamon para fondos de pantalla dinámicos según la hora y la ubicación" #: 5.4/res/preferences.glade:135 msgid "Image Source" @@ -138,8 +135,7 @@ msgstr "Estimación de ubicación" #: 5.4/res/preferences.glade:1167 msgid "Interval time to refresh location via network (min)" -msgstr "" -"Intervalo de tiempo para actualizar la ubicación a través de la red (min)" +msgstr "Intervalo de tiempo para actualizar la ubicación a través de la red (min)" #: 5.4/res/preferences.glade:1212 msgid "Location provider" @@ -269,46 +265,28 @@ msgid "About the project" msgstr "Acerca del proyecto" #: 5.4/res/preferences.glade:2687 -msgid "" -"Based on a location or by user choice, this extensions calculates the " -"periods of a day and switches the background image of your Cinnamon desktop. " -"The extension offers as image sources a set of preconfigured wallpapers, a " -"heic image import by the user or a custom folder with single images." -msgstr "" -"Basándose en una ubicación o por elección del usuario, esta extensión " -"calcula los periodos de un día y cambia la imagen de fondo de su escritorio " -"Cinnamon. La extensión ofrece como fuentes de imagen un conjunto de fondos " -"de pantalla preconfigurados, una imagen heic importada por el usuario o una " -"carpeta personalizada con imágenes individuales." +msgid "Based on a location or by user choice, this extensions calculates the periods of a day and switches the background image of your Cinnamon desktop. The extension offers as image sources a set of preconfigured wallpapers, a heic image import by the user or a custom folder with single images." +msgstr "Basándose en una ubicación o por elección del usuario, esta extensión calcula los periodos de un día y cambia la imagen de fondo de su escritorio Cinnamon. La extensión ofrece como fuentes de imagen un conjunto de fondos de pantalla preconfigurados, una imagen heic importada por el usuario o una carpeta personalizada con imágenes individuales." #: 5.4/res/preferences.glade:2706 msgid "Developed by TobiZog" msgstr "Desarrollado por TobiZog" #: 5.4/res/preferences.glade:2723 -msgid "" -"If you need more information or want to rate the extension, you can visit " -"the Cinnamon Spices Website." -msgstr "" -"Si necesita más información o desea valorar la extensión, puede visitar el " -"sitio web de Cinnamon Spices." +msgid "If you need more information or want to rate the extension, you can visit the Cinnamon Spices Website." +msgstr "Si necesita más información o desea valorar la extensión, puede visitar el sitio web de Cinnamon Spices." #: 5.4/res/preferences.glade:2734 msgid "Cinnamon Dynamic Wallpaper at Cinnamon Spices Website" -msgstr "" -"Fondo de pantalla dinámico de Cinnamon en el sitio web de Cinnamon Spices" +msgstr "Fondo de pantalla dinámico de Cinnamon en el sitio web de Cinnamon Spices" #: 5.4/res/preferences.glade:2759 msgid "Source Code" msgstr "Código fuente" #: 5.4/res/preferences.glade:2788 -msgid "" -"This project is Open Source. You can take a look inside the whole source " -"code of this extension on GitHub." -msgstr "" -"Este proyecto es de código abierto. Puede echar un vistazo al código fuente " -"completo de esta extensión en GitHub." +msgid "This project is Open Source. You can take a look inside the whole source code of this extension on GitHub." +msgstr "Este proyecto es de código abierto. Puede echar un vistazo al código fuente completo de esta extensión en GitHub." #: 5.4/res/preferences.glade:2799 msgid "Source Code on GitHub" @@ -319,14 +297,8 @@ msgid "Issues and Enhancements" msgstr "Problemas y mejoras" #: 5.4/res/preferences.glade:2853 -msgid "" -"Do you find an issue? Or want a new feature? Go to the GitHub repository and " -"create a new issue. If you find an error message in the logs above, add it " -"to the issue report." -msgstr "" -"¿Ha encontrado algún problema? ¿O quieres una nueva funcionalidad? Ve al " -"repositorio de GitHub y crea una nueva incidencia. Si encuentras un mensaje " -"de error en los registros anteriores, añádelo al informe de incidencias." +msgid "Do you find an issue? Or want a new feature? Go to the GitHub repository and create a new issue. If you find an error message in the logs above, add it to the issue report." +msgstr "¿Ha encontrado algún problema? ¿O quieres una nueva funcionalidad? Ve al repositorio de GitHub y crea una nueva incidencia. Si encuentras un mensaje de error en los registros anteriores, añádelo al informe de incidencias." #: 5.4/res/preferences.glade:2864 msgid "Create a new issue on GitHub" diff --git a/cinnamon-spices-makepot b/cinnamon-spices-makepot index 2589889e..7344a239 100755 --- a/cinnamon-spices-makepot +++ b/cinnamon-spices-makepot @@ -1,142 +1,155 @@ -#!/bin/bash +#!/usr/bin/python3 -function usage { - echo "Usage:" - echo "" - echo "./cinnamon-spices-makepot ARGUMENT [-i | -r]" - echo "" - echo "Examples:" - echo "" - echo "./cinnamon-spices-makepot force-quit@cinnamon.org" - echo "./cinnamon-spcies-makepot force-quit@cinnamon.org -i" - echo "" - echo "Options:" - echo "" - echo "-i, --install - Compiles and installs any .po files contained in a spices po folder." - echo " Use this option to test your translations locally before uploading" - echo " to Spices." - echo "" - echo "-r, --remove - The opposite of install, removes translations from the store." - echo "" - echo "-h, --help - Shows the usage of this script." - echo "" - echo "ARGUMENT required:" - echo "" - echo " UUID - The spices UUID." - echo " What it does: Updates the .pot file of UUID." - echo " If .pot file does not exist, it will be created." - echo " Updating a .pot file is done:" - echo " * by running a custom makepot script in UUID/files/UUID/po" - echo " * or else with the command: cinnamon-json-makepot --js" - echo "" - echo " spices-without-pot - Lists all spices, which do not have a .pot file" -} +import argparse +import json +import os +import subprocess +import sys -function makePotFile { - # change directory to UUID/files/UUID - cd $1/files/$1 +from glob import glob - # check if xlet has a makepot file - if [ -f "po/makepot" ]; then - if [ $2 != "doNotUpdatePotFiles" ]; then - cd po - echo "------------------------------------------------------------------------------------------------------" - echo "$1: po/makepot" - echo "------------------------------------------------------------------------------------------------------" - ./makepot - echo "" - cd .. - fi - # generate .pot with default parameters - else - if [ -d po ]; then - potName=$(ls po | grep .pot) # get name of .pot file - else - potName="" - fi - if [ -f "po/$potName" ]; then - if [ $2 != "doNotUpdatePotFiles" ]; then - echo "------------------------------------------------------------------------------------------------------" - echo "$1: cinnamon-json-makepot --js po/$potName (update)" - echo "------------------------------------------------------------------------------------------------------" - cinnamon-json-makepot --js po/$potName - echo "" - fi - else - if [ $2 == "createNewPotFile" ]; then - if [ ! -d po ]; then - mkdir po - fi - echo "------------------------------------------------------------------------------------------------------" - echo "$1: cinnamon-json-makepot --js po/$1.pot (new file)" - echo "------------------------------------------------------------------------------------------------------" - cinnamon-json-makepot --js po/$1.pot - echo "" - elif [ $2 == "doNotUpdatePotFiles" ]; then - echo "$1: has no .pot file" - fi - fi - fi - # change directory back - cd ../../.. -} +def parse_args(): + """ + Get command line arguments and process translation actions + """ + parser = argparse.ArgumentParser() + parser.description = 'Arguments for cinnamon-spices-makepot' + parser.add_argument('-i', '--install', action='store_true', + help='Compiles and installs any .po files contained in' + ' a spices po folder.' + 'Use this option to test your translations' + ' locally before uploading to Spices.') + parser.add_argument('-r', '--remove', action='store_true', + help='The opposite of install, removes local ' + 'translations.') + parser.add_argument('-a', '--all', action='store_true', + help='Create or update translation templates for all ' + 'Spices') + parser.add_argument('uuid', type=str, metavar='UUID', nargs='?', + help='the UUID of the Spice') + args = parser.parse_args() + if args.all and not args.uuid: + for file_path in os.listdir("."): + if os.path.isdir(file_path) and not file_path.startswith("."): + if args.install: + install_po(file_path, True) + elif args.remove: + remove_po(file_path, True) + else: + make_pot(file_path, True) + elif args.install and args.remove: + print('Only -i/--install OR -r/--remove may be specified. Not both.') + sys.exit(1) + elif args.install and args.uuid: + install_po(args.uuid) + elif args.remove and args.uuid: + remove_po(args.uuid) + elif args.uuid: + make_pot(args.uuid) + else: + parser.print_help() +def install_po(uuid: str, _all: bool = False): + """ + Install translation files locally from the po directory of the UUID + """ + uuid_path = f'{uuid}/files/{uuid}' + try: + contents = os.listdir(uuid_path) + except FileNotFoundError: + print(f'Translations not found for: {uuid}') + if not _all: + sys.exit(1) + home = os.path.expanduser("~") + locale_inst = f'{home}/.local/share/locale' + if 'po' in contents: + po_dir = f'{uuid_path}/po' + for file in os.listdir(po_dir): + if file.endswith('.po'): + lang = file.split(".")[0] + locale_dir = os.path.join(locale_inst, lang, 'LC_MESSAGES') + os.makedirs(locale_dir, mode=0o755, exist_ok=True) + subprocess.run(['msgfmt', '-c', os.path.join(po_dir, file), + '-o', os.path.join(locale_dir, f'{uuid}.mo')], + check=True) -if [ $# -eq 1 ]; then - # print help - if [ $1 == "-h" ] || [ $1 == "--help" ]; then - usage - exit 1 - fi - # if given parameter is 'cinnamon-spices', update .pot files for all xlets - if [ $1 == "cinnamon-spices" ]; then - for uuid in *; do - if [ -d $uuid ]; then - makePotFile $uuid doNotCreateNewPotFiles - fi - done - exit 1 - # if given parameter is 'spices-without-pot', print spices, which have no .pot file - elif [ $1 == "spices-without-pot" ]; then - for uuid in *; do - if [ -d $uuid ]; then - makePotFile $uuid doNotUpdatePotFiles - fi - done - exit 1 - fi -fi -# install/remove .po files -if [ $# -eq 2 ]; then - if [ -d $1 ]; then - if [ $2 == "-i" ] || [ $2 == "--install" ] || [ $2 == "-r" ] || [ $2 == "--remove" ]; then - # change directory to UUID/files/UUID - cd $1/files/$1 - cinnamon-json-makepot $2 - exit 1 - else - echo "Available options: --install | -i, --remove | -r" - echo "More infos:" - echo "" - echo "./cinnamon-spices-makepot --help" - exit 1 - fi - else - echo "UUID $1 does not exist!" - fi -fi +def remove_po(uuid: str, _all: bool = False): + """ + Remove local translation files for the UUID + """ + home = os.path.expanduser("~") + locale_inst = f'{home}/.local/share/locale' + uuid_mo_list = glob(f'{locale_inst}/**/{uuid}.mo', recursive=True) + if not uuid_mo_list: + print(f'No translation files found for: {uuid}') + if not _all: + sys.exit(1) + for uuid_mo_file in uuid_mo_list: + os.remove(uuid_mo_file) -# update .pot file of given xlet UUID -if [ $# -eq 1 ]; then - if [ -d $1 ]; then - makePotFile $1 createNewPotFile - else - echo "Spice with UUID »$1« does not exist!" - fi - exit 1 -else - usage -fi + +def make_pot(uuid: str, _all: bool = False): + """ + Make the translation template file for the UUID + """ + _pwd = sys.argv[1] if not _all else f'{os.getcwd()}/{uuid}' + _return_pwd = '../../..' + po_dir = f'{_pwd}/files/{uuid}/po' + uuid_dir = f'{_pwd}/files/{uuid}' + pot_file = uuid + '.pot' + outfile = os.path.join(po_dir, pot_file) + if os.path.exists(outfile): + os.remove(outfile) + elif not os.path.exists(po_dir): + os.mkdir(po_dir) + subprocess.run(["cinnamon-xlet-makepot", "-o", outfile, _pwd], + check=True) + os.chdir(uuid_dir) + pot_path = f'po/{pot_file}' + glade_list = glob('**/*.glade', recursive=True) + for glade_file in glade_list: + subprocess.run(["xgettext", "-jL", "Glade", "-o", pot_path, + glade_file], check=True) + shell_list = glob('**/*.sh', recursive=True) + for shell_file in shell_list: + subprocess.run(["xgettext", "-jL", "Shell", "-o", pot_path, + shell_file], stderr=subprocess.DEVNULL, check=True) + if not _all: + os.chdir(f'{_return_pwd}') + metadata_file = 'metadata.json' if _all else f'{uuid}/files/{uuid}/metadata.json' + try: + with open(metadata_file, encoding='utf-8') as meta: + metadata = json.load(meta) + version = str(metadata['version']) + except (FileNotFoundError, KeyError): + print(f"{uuid}: metadata.json or version not found") + version = "1.0" + address = 'https://github.com/linuxmint/cinnamon-spices-extensions/issues' + subprocess.run(["xgettext", "--no-wrap", "--package-name", uuid, + "--foreign-user", "--msgid-bugs-address", address, + "--package-version", version, "-o", outfile, outfile], + check=True) + glob_path = 'po/*.po' if _all else f'{uuid}/**/*.po' + po_list = glob(glob_path, recursive=True) + for po_file in po_list: + *po_dir_list, po_ext = po_file.split('/') + po_dir_str = '/'.join(po_dir_list) + if not os.getcwd().endswith(po_dir_str): + os.chdir(po_dir_str) + po_lang = po_ext.split('.')[0] + subprocess.run(["intltool-update", "-g", uuid, "-d", po_lang], + check=True) + subprocess.run(["msgattrib", "--no-obsolete", "--no-wrap", "-o", + po_ext, po_ext], + check=True) + if po_list: + _return_pwd += '/..' + if _all: + os.chdir(_return_pwd) + + +if __name__ == "__main__": + parse_args()