Softcatala / translation-memory-tools

A set of tools to build, maintain and use translation memories
https://www.softcatala.org/recursos/memories/
29 stars 17 forks source link

Permetre especificar noms de projectes amb espais i altres caràcters #314

Closed pereorga closed 1 year ago

pereorga commented 1 year ago

Depenent de com es configuri un projecte, el fet que el nom del projecte contingui espais o altres caràcters (com la cometa simple) fa que el procés falli. Això és un problema, ja que el nom del projecte s'hauria de poder especificar literalment.

Reportat abans a https://github.com/Softcatala/translation-memory-tools/pull/313 i https://github.com/Softcatala/translation-memory-tools/pull/307.

Per exemple, això falla:

{
    "project": "Andor's Trail",
    "license" : "GPL-2.0-only",
    "projectweb": "https://hosted.weblate.org/projects/andors-trail/-/ca/",
    "fileset": {
        "Andors Trail": {
            "url": "https://hosted.weblate.org/download/andors-trail/-/ca/?format=zip",
            "type": "compressed",
            "target": "ca.zip"
        }
    }
}

Això també em falla:

{
    "project": "OBS Studio",
    "license" : "GPL-2.0-or-later",
    "projectweb": "https://crowdin.com/project/obs-studio",
    "fileset": {
        "OBSStudio": {
            "url": "https://github.com/obsproject/obs-studio.git",
            "type": "git"
        }
    }
}

En Bash això és un problema típic quan, per exemple, s'incorpora una variable sense rodejar-la de cometes. Suposo que abans de fer servir el nom del projecte, es podria "sanititzar" en python (només és un exemple, no sé com s'hauria d'aplicar al codi):

import string

def sanitize_filename(filename):
    """
    Sanitize a string to be used as a filename.
    Remove characters that are not safe for file systems and replace them with underscores.
    """

    # Define characters that are valid
    valid_chars = "-_.()%s%s" % (string.ascii_letters, string.digits)

    # Replace invalid characters with underscores
    sanitized = ''.join(c if c in valid_chars else '_' for c in filename)

    # To further prevent edge cases, ensure the resulting name doesn't start with a dot
    if sanitized.startswith('.'):
        sanitized = '_' + sanitized[1:]

    return sanitized

# Test
filename = "my:invalid//file name?.txt"
print(sanitize_filename(filename))  # Expected output: "my_invalid__file_name_.txt"
jordimas commented 1 year ago

Ho miro, per informar d'error no ho facis en les PR perquè sinó quan es fa merge es perd. Millor informes d'error com aquest.

jordimas commented 1 year ago

Bé Git ha tancat això sol amb el commit. Si veus que no funciona torna'l a obrir si us plau.