Skip to content

Commit

Permalink
Minor changes. Updated config template and configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Backist committed Oct 8, 2024
1 parent dcf3800 commit 26d6103
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 28 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Version 0.1.0

- [x]
- [x]
- [x]
- [x]
- [x]
16 changes: 8 additions & 8 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@


## En version 0.2.0:
- [] Sistema de calidad de traducciones automaticas usando BLEU, GLEU, etc..
- [] Implementar widget QComboBox en Pyside6 y Qt (C++) para integracción directa en aplicaciones.
- [] Compatibilidad con versiones anteriores de QT -> (Qt5, Qt4) (Que tienen modificaciones en los TS y el sistema de traducción..)
- [] Elección de API para la traducción automatica, no solo GoogleTranslator.
- [] Poder especificar directorios NO EXISTENTES en translations, translatables en .qal_config (por ahora solo puedes pasar directorios y que existan.)
- [ ] Sistema de calidad de traducciones automaticas usando BLEU, GLEU, etc..
- [ ] Implementar widget QComboBox en Pyside6 y Qt (C++) para integracción directa en aplicaciones.
- [ ] Compatibilidad con versiones anteriores de QT -> (Qt5, Qt4) (Que tienen modificaciones en los TS y el sistema de traducción..)
- [ ] Elección de API para la traducción automatica, no solo GoogleTranslator.
- [ ] Poder especificar directorios NO EXISTENTES en translations, translatables en .qal_config (por ahora solo puedes pasar directorios y que existan.)


## En version 0.3.0:
- [] Retrocompatiblidad con gettext; Posibilidad de usar otras funciones de busqueda en vez de self.tr y QCoreAplicacion.Translate.
- [] Implementar widget QComboBox en Pyside6 y Qt (C++) para integracción directa en aplicaciones.
- [] Timer o una progress_bar para ver el proceso de las traducciones, SOLO si no se desea DEBUG y VERBOSE (porque muestran mensajes).
- [ ] Retrocompatiblidad con ``gettext``; Posibilidad de usar otras funciones de busqueda en vez de self.tr y QCoreAplicacion.Translate.
- [ ] Implementar widget QComboBox en Pyside6 y Qt (C++) para integracción directa en aplicaciones.
- [ ] Timer o una progress_bar para ver el proceso de las traducciones, SOLO si no se desea DEBUG y VERBOSE (porque muestran mensajes).



Expand Down
File renamed without changes.
File renamed without changes.
29 changes: 19 additions & 10 deletions qautolinguist/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
from qautolinguist.config_template import INI_FILE_TEMPLATE
from ast import literal_eval # para convertir listas y otras estructuras de datos de str a su tipo original
from pathlib import Path
from typing import Dict, Any, Tuple, Optional, Union
from typing import Dict, Any, Tuple, List, Optional, Union

try:
import importlib.resources as import_resources
except ModuleNotFoundError:
import importlib_resources


__all__: list[str] = ["Config"]
__all__: List[str] = ["Config"]


class Config:
Expand All @@ -38,15 +38,15 @@ def _process_dict_data(self) -> Dict[str, Tuple[str, str]]:


with import_resources.open_text(consts.PARAM_DECLS_RESOURCE[0], consts.PARAM_DECLS_RESOURCE[1], encoding="utf-8") as fp:
self.params = json.load(fp)
params = json.load(fp)
# -- Importamos el diccionario estatico que contiene los comentarios, es de la forma dict[param: (comment, default)] --
# -- default es el valor por defecto que da QAutoLinguist.
return {
param: (
helpers.stringfy(param_info['default']),
helpers.fit_string(param_info['comment'], split_size=75, preffix="#"),
)
for param, param_info in self.params.items()
for param, param_info in params.items()
}

def _format_dict_data(self) -> Dict[str, str]:
Expand Down Expand Up @@ -134,8 +134,13 @@ def _process_read(self) -> Dict[str, Any]:
- ``ConfigWrongParamFormat``: If some value in configuration file was not able to convert to its original type.
- ``UncompletedConfig``: If some parameter in ``Required`` section is missing.
"""
with open(consts.PARAM_DECLS_PATH) as fp:
original_params = json.load(fp)

# -- Using import_resources module to access resources
# -- once the project has been compiled into an executable.
# -- This modele will search the resources path considering
# -- package root via __init__ modules.
with import_resources.open_text(consts.PARAM_DECLS_RESOURCE[0], consts.PARAM_DECLS_RESOURCE[1], encoding="utf-8") as fp:
params = json.load(fp)

raw_data = self._get_dict_from_load() # dict[section: {option1:value, option2:value, ...}]
d = {}
Expand All @@ -145,11 +150,9 @@ def _process_read(self) -> Dict[str, Any]:
for section, options in raw_data.items():
for key,value in options.items():
try:
d[key] = self._conv_value_type(value, original_params[key]["default"]) # value, type(original value), since raw values were converted to str.
d[key] = self._conv_value_type(value, params[key]["default"]) # value, type(original value), since raw values were converted to str.
except exceptions.ConfigWrongParamFormat as e:
raise exceptions.ConfigWrongParamFormat(
f"Wrong param format in section '{section}' key: '{key}'. Detailed error: {e}"
) from None
raise e from None
return d

def _get_dict_from_load(self) -> Dict[str, Dict[str, str]]:
Expand Down Expand Up @@ -182,6 +185,12 @@ def create(self, loc: Union[str, Path], overwrite: bool = False) -> Path:

if self.config_path.suffix != ".ini":
self.config_path = self.config_path.with_suffix(".ini")

# -- Initialize the configuration
if self.config_path.is_file():
self.config_path.touch()
else:
self.config_path.mkdir()

processed_template = self._process_template() #creamos una instancia con los valores vacios y procesamos el template con esos
with self.config_path.open("w", encoding="utf-8") as file_:
Expand Down
2 changes: 1 addition & 1 deletion qautolinguist/config_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#! that we need to pass to QAutoLinguist.
INI_FILE_TEMPLATE = """
# ============================= QAutoLinguist Configuration File =====================================
# This file is auto-generated by qautolinguist.Config .
# This file is auto-generated by qautolinguist.Config.
# If you are not very familiar with the configuration file format,
# just fill in the fields in the "Required" section.
# Be cautious when placing values.
Expand Down
9 changes: 0 additions & 9 deletions qautolinguist/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@
PARAM_DECLS_RESOURCE = "qautolinguist.static", "config_decls.json" # tupla que contiene el paquete donde se contiene el recurso y el archivo


TRANSLATABLE_HEADER_DEFINITION: str = (
"This file is auto-generated by TsfComposer. "
"It contains the translation sources of the .ts files (translation files); "
"each line is a unique translation. "
"Please, if you are going to review or modify its content, do it with caution, "
"any unwanted modification will affect the creation of the binaries.\n\n"
)


# lrelease options (version: 6.5.3):
# -idbased
# Use IDs instead of source strings for message keying
Expand Down
Empty file.

0 comments on commit 26d6103

Please sign in to comment.