Add Spanish (LatAm) and improve how we count language coverage (Z#23200505) (#5308)

* Add Spanish (LatAm) and improve how we count language coverage

* Apply suggestions from code review

Co-authored-by: Richard Schreiber <schreiber@rami.io>

* Fix license header

---------

Co-authored-by: Richard Schreiber <schreiber@rami.io>
This commit is contained in:
Raphael Michel
2025-07-17 17:06:25 +02:00
committed by GitHub
parent 3ddf759a1b
commit e2ae553c69
6 changed files with 31525 additions and 11 deletions

View File

@@ -115,6 +115,7 @@ ALL_LANGUAGES = [
('sk', _('Slovak')),
('sv', _('Swedish')),
('es', _('Spanish')),
('es-419', _('Spanish (Latin America)')),
('tr', _('Turkish')),
('uk', _('Ukrainian')),
]
@@ -172,6 +173,12 @@ EXTRA_LANG_INFO = {
'name': 'Norwegian Bokmal',
'name_local': 'norsk (bokmål)',
},
'es-419': {
'bidi': False,
'code': 'es-419',
'name': 'Spanish (Latin America)',
'name_local': 'Español',
},
}
django.conf.locale.LANG_INFO.update(EXTRA_LANG_INFO)

View File

@@ -0,0 +1,35 @@
#
# This file is part of pretix (Community Edition).
#
# Copyright (C) 2014-2020 Raphael Michel and contributors
# Copyright (C) 2020-2021 rami.io GmbH and contributors
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General
# Public License as published by the Free Software Foundation in version 3 of the License.
#
# ADDITIONAL TERMS APPLY: Pursuant to Section 7 of the GNU Affero General Public License, additional terms are
# applicable granting you additional permissions and placing additional restrictions on your usage of this software.
# Please refer to the pretix LICENSE file to obtain the full terms applicable to this work. If you did not receive
# this file, see <https://pretix.eu/about/en/license>.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along with this program. If not, see
# <https://www.gnu.org/licenses/>.
#
import re
from django.core.management.commands import makemessages
def is_valid_locale(locale):
return re.match(r"^[a-z]+$", locale) or re.match(r"^[a-z]+_[A-Z0-9].*$", locale)
makemessages.is_valid_locale = is_valid_locale
class Command(makemessages.Command):
pass

View File

@@ -32,7 +32,6 @@ from django.conf import settings
from django.utils import translation
from django.utils.formats import get_format
from django.utils.translation import to_locale
from django.utils.translation.trans_real import TranslationCatalog
date_conversion_to_moment = {
'%a': 'ddd',
@@ -175,7 +174,7 @@ def get_language_score(locale):
Note that there is no valid score for "en", since it's technically not "translated".
"""
catalog = None
catalog = {}
app_configs = reversed(apps.get_app_configs())
for app in app_configs:
@@ -198,10 +197,15 @@ def get_language_score(locale):
)
except:
continue
if catalog is None:
catalog = TranslationCatalog(translation)
else:
catalog.update(translation)
catalog.update(translation._catalog.copy())
# Also add fallback catalog (e.g. es for es-419, de for de-informal, …)
while translation._fallback:
if not locale.startswith(translation._fallback.info().get("language", "XX")):
break
translation = translation._fallback
catalog.update(translation._catalog.copy())
# Add pretix' main translation folder as well as installation-specific translation folders
for localedir in reversed(settings.LOCALE_PATHS):
@@ -214,10 +218,13 @@ def get_language_score(locale):
)
except:
continue
if catalog is None:
catalog = TranslationCatalog(translation)
else:
catalog.update(translation)
catalog.update(translation._catalog.copy())
while translation._fallback:
if not locale.startswith(translation._fallback.info().get("language", "XX")):
break
translation = translation._fallback
catalog.update(translation._catalog.copy())
if not catalog:
score = 1

File diff suppressed because it is too large Load Diff

View File

@@ -126,6 +126,7 @@ pre[lang=eg], input[lang=eg], textarea[lang=eg], div[lang=eg] { background-image
pre[lang=eh], input[lang=eh], textarea[lang=eh], div[lang=eh] { background-image: url(static('pretixbase/img/flags/eh.png')); }
pre[lang=er], input[lang=er], textarea[lang=er], div[lang=er] { background-image: url(static('pretixbase/img/flags/er.png')); }
pre[lang=es], input[lang=es], textarea[lang=es], div[lang=es] { background-image: url(static('pretixbase/img/flags/es.png')); }
pre[lang=es-419], input[lang=es-419], textarea[lang=es-419], div[lang=es-419] { background-image: url(static('pretixbase/img/flags/es.png')); }
pre[lang=et], input[lang=et], textarea[lang=et], div[lang=et] { background-image: url(static('pretixbase/img/flags/et.png')); }
pre[lang=fi], input[lang=fi], textarea[lang=fi], div[lang=fi] { background-image: url(static('pretixbase/img/flags/fi.png')); }
pre[lang=fj], input[lang=fj], textarea[lang=fj], div[lang=fj] { background-image: url(static('pretixbase/img/flags/fj.png')); }

View File

@@ -53,7 +53,7 @@ base_patterns = [
name='healthcheck'),
re_path(r'^redirect/$', redirect.redir_view, name='redirect'),
re_path(r'^site.webmanifest$', webmanifest.webmanifest, name='site.webmanifest'),
re_path(r'^jsi18n/(?P<lang>[a-zA-Z-_]+)/$', js_catalog.js_catalog, name='javascript-catalog'),
re_path(r'^jsi18n/(?P<lang>[a-zA-Z0-9_-]+)/$', js_catalog.js_catalog, name='javascript-catalog'),
re_path(r'^metrics$', metrics.serve_metrics,
name='metrics'),
re_path(r'^csp_report/$', csp.csp_report, name='csp.report'),