Merge pull request #292 from YunoHost/actions/black

Format Python code with Black
This commit is contained in:
Alexandre Aubin 2021-09-03 16:44:21 +02:00 committed by GitHub
commit d0687b204b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 19 deletions

View file

@ -27,11 +27,17 @@ def fix_locale(locale_file):
# should also be in the translated string, otherwise the .format # should also be in the translated string, otherwise the .format
# will trigger an exception! # will trigger an exception!
subkeys_in_ref = [k[0] for k in re.findall(r"{(\w+)(:\w)?}", string)] subkeys_in_ref = [k[0] for k in re.findall(r"{(\w+)(:\w)?}", string)]
subkeys_in_this_locale = [k[0] for k in re.findall(r"{(\w+)(:\w)?}", this_locale[key])] subkeys_in_this_locale = [
k[0] for k in re.findall(r"{(\w+)(:\w)?}", this_locale[key])
]
if set(subkeys_in_ref) != set(subkeys_in_this_locale) and (len(subkeys_in_ref) == len(subkeys_in_this_locale)): if set(subkeys_in_ref) != set(subkeys_in_this_locale) and (
len(subkeys_in_ref) == len(subkeys_in_this_locale)
):
for i, subkey in enumerate(subkeys_in_ref): for i, subkey in enumerate(subkeys_in_ref):
this_locale[key] = this_locale[key].replace('{%s}' % subkeys_in_this_locale[i], '{%s}' % subkey) this_locale[key] = this_locale[key].replace(
"{%s}" % subkeys_in_this_locale[i], "{%s}" % subkey
)
fixed_stuff = True fixed_stuff = True
if fixed_stuff: if fixed_stuff:

View file

@ -1,5 +1,6 @@
import re import re
def reformat(lang, transformations): def reformat(lang, transformations):
locale = open(f"locales/{lang}.json").read() locale = open(f"locales/{lang}.json").read()
@ -8,21 +9,41 @@ def reformat(lang, transformations):
open(f"locales/{lang}.json", "w").write(locale) open(f"locales/{lang}.json", "w").write(locale)
###################################################### ######################################################
godamn_spaces_of_hell = ["\u00a0", "\u2000", "\u2001", "\u2002", "\u2003", "\u2004", "\u2005", "\u2006", "\u2007", "\u2008", "\u2009", "\u200A", "\u202f", "\u202F", "\u3000"] godamn_spaces_of_hell = [
"\u00a0",
"\u2000",
"\u2001",
"\u2002",
"\u2003",
"\u2004",
"\u2005",
"\u2006",
"\u2007",
"\u2008",
"\u2009",
"\u200A",
"\u202f",
"\u202F",
"\u3000",
]
transformations = {s: " " for s in godamn_spaces_of_hell} transformations = {s: " " for s in godamn_spaces_of_hell}
transformations.update({ transformations.update(
{
"": "...", "": "...",
}) }
)
reformat("en", transformations) reformat("en", transformations)
###################################################### ######################################################
transformations.update({ transformations.update(
{
"courriel": "email", "courriel": "email",
"e-mail": "email", "e-mail": "email",
"Courriel": "Email", "Courriel": "Email",
@ -33,6 +54,7 @@ transformations.update({
"»": "'", "»": "'",
"": "'", "": "'",
# r"$(\w{1,2})'|( \w{1,2})'": r"\1\2", # r"$(\w{1,2})'|( \w{1,2})'": r"\1\2",
}) }
)
reformat("fr", transformations) reformat("fr", transformations)