mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-06-02 22:00:12 +02:00
use constant for default locale
This commit is contained in:
parent
d5a1439457
commit
c2bc52dd85
|
@ -77,6 +77,9 @@ from . import apksigcopier, common
|
|||
# The path to this fdroidserver distribution
|
||||
FDROID_PATH = os.path.realpath(os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
# There needs to be a default, and this is the most common for software.
|
||||
DEFAULT_LOCALE = 'en-US'
|
||||
|
||||
# this is the build-tools version, aapt has a separate version that
|
||||
# has to be manually set in test_aapt_version()
|
||||
MINIMUM_AAPT_BUILD_TOOLS_VERSION = '26.0.0'
|
||||
|
@ -507,7 +510,7 @@ def load_localized_config(name, repodir):
|
|||
for f in Path().glob("config/**/{name}.yml".format(name=name)):
|
||||
locale = f.parts[1]
|
||||
if len(f.parts) == 2:
|
||||
locale = "en-US"
|
||||
locale = DEFAULT_LOCALE
|
||||
with open(f, encoding="utf-8") as fp:
|
||||
elem = yaml.safe_load(fp)
|
||||
for afname, field_dict in elem.items():
|
||||
|
@ -3912,7 +3915,7 @@ def get_app_display_name(app):
|
|||
if app.get('Name'):
|
||||
return app['Name']
|
||||
if app.get('localized'):
|
||||
localized = app['localized'].get('en-US')
|
||||
localized = app['localized'].get(DEFAULT_LOCALE)
|
||||
if not localized:
|
||||
for v in app['localized'].values():
|
||||
localized = v
|
||||
|
|
|
@ -42,7 +42,7 @@ from . import common
|
|||
from . import metadata
|
||||
from . import net
|
||||
from . import signindex
|
||||
from fdroidserver.common import FDroidPopen, FDroidPopenBytes, load_stats_fdroid_signing_key_fingerprints
|
||||
from fdroidserver.common import DEFAULT_LOCALE, FDroidPopen, FDroidPopenBytes, load_stats_fdroid_signing_key_fingerprints
|
||||
from fdroidserver.exception import FDroidException, VerificationException
|
||||
|
||||
|
||||
|
@ -518,14 +518,14 @@ def package_metadata(app, repodir):
|
|||
):
|
||||
element_new = element[:1].lower() + element[1:]
|
||||
if element in app and app[element]:
|
||||
meta[element_new] = {"en-US": convert_datetime(app[element])}
|
||||
meta[element_new] = {DEFAULT_LOCALE: convert_datetime(app[element])}
|
||||
elif "localized" in app:
|
||||
localized = {k: v[element_new] for k, v in app["localized"].items() if element_new in v}
|
||||
if localized:
|
||||
meta[element_new] = localized
|
||||
|
||||
if "name" not in meta and app["AutoName"]:
|
||||
meta["name"] = {"en-US": app["AutoName"]}
|
||||
meta["name"] = {DEFAULT_LOCALE: app["AutoName"]}
|
||||
|
||||
# fdroidserver/metadata.py App default
|
||||
if meta["license"] == "Unknown":
|
||||
|
@ -536,9 +536,8 @@ def package_metadata(app, repodir):
|
|||
|
||||
# TODO handle different resolutions
|
||||
if app.get("icon"):
|
||||
meta["icon"] = {
|
||||
"en-US": common.file_entry(os.path.join(repodir, "icons", app["icon"]))
|
||||
}
|
||||
icon_path = os.path.join(repodir, "icons", app["icon"])
|
||||
meta["icon"] = {DEFAULT_LOCALE: common.file_entry(icon_path)}
|
||||
|
||||
if "iconv2" in app:
|
||||
meta["icon"] = app["iconv2"]
|
||||
|
@ -654,10 +653,10 @@ def convert_version(version, app, repodir):
|
|||
def v2_repo(repodict, repodir, archive):
|
||||
repo = {}
|
||||
|
||||
repo["name"] = {"en-US": repodict["name"]}
|
||||
repo["description"] = {"en-US": repodict["description"]}
|
||||
repo["name"] = {DEFAULT_LOCALE: repodict["name"]}
|
||||
repo["description"] = {DEFAULT_LOCALE: repodict["description"]}
|
||||
repo["icon"] = {
|
||||
"en-US": common.file_entry("{}/icons/{}".format(repodir, repodict["icon"]))
|
||||
DEFAULT_LOCALE: common.file_entry("%s/icons/%s" % (repodir, repodict["icon"]))
|
||||
}
|
||||
|
||||
config = common.load_localized_config("config", repodir)
|
||||
|
@ -1022,7 +1021,7 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing
|
|||
lkey = key[:1].lower() + key[1:]
|
||||
localized = app.get('localized')
|
||||
if not value and localized:
|
||||
for lang in ['en-US'] + [x for x in localized.keys()]:
|
||||
for lang in [DEFAULT_LOCALE] + [x for x in localized.keys()]:
|
||||
if not lang.startswith('en'):
|
||||
continue
|
||||
if lang in localized:
|
||||
|
@ -1266,7 +1265,7 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing
|
|||
namefield = common.config['current_version_name_source']
|
||||
name = app.get(namefield)
|
||||
if not name and namefield == 'Name':
|
||||
name = app.get('localized', {}).get('en-US', {}).get('name')
|
||||
name = app.get('localized', {}).get(DEFAULT_LOCALE, {}).get('name')
|
||||
if not name:
|
||||
name = app.id
|
||||
sanitized_name = re.sub(b'''[ '"&%?+=/]''', b'', str(name).encode('utf-8'))
|
||||
|
|
|
@ -51,6 +51,7 @@ from . import _
|
|||
from . import common
|
||||
from . import index
|
||||
from . import metadata
|
||||
from .common import DEFAULT_LOCALE
|
||||
from .exception import BuildException, FDroidException, VerificationException
|
||||
|
||||
from PIL import Image, PngImagePlugin
|
||||
|
@ -2034,7 +2035,7 @@ def insert_missing_app_names_from_apks(apps, apks):
|
|||
|
||||
The name from the APK is set as the default name for the app if
|
||||
there is no other default set, e.g. app['Name'] or
|
||||
app['localized']['en-US']['name']. The en-US locale is defined in
|
||||
app['localized'][DEFAULT_LOCALE]['name']. The default is defined in
|
||||
the F-Droid ecosystem as the locale of last resort, as in the one
|
||||
that should always be present. en-US is used since it is the
|
||||
locale of the source strings.
|
||||
|
@ -2050,7 +2051,7 @@ def insert_missing_app_names_from_apks(apps, apks):
|
|||
for appid, app in apps.items():
|
||||
if app.get('Name') is not None:
|
||||
continue
|
||||
if app.get('localized', {}).get('en-US', {}).get('name') is not None:
|
||||
if app.get('localized', {}).get(DEFAULT_LOCALE, {}).get('name') is not None:
|
||||
continue
|
||||
|
||||
bestver = UNSET_VERSION_CODE
|
||||
|
@ -2063,9 +2064,9 @@ def insert_missing_app_names_from_apks(apps, apks):
|
|||
if bestver != UNSET_VERSION_CODE:
|
||||
if 'localized' not in app:
|
||||
app['localized'] = {}
|
||||
if 'en-US' not in app['localized']:
|
||||
app['localized']['en-US'] = {}
|
||||
app['localized']['en-US']['name'] = bestapk.get('name')
|
||||
if DEFAULT_LOCALE not in app['localized']:
|
||||
app['localized'][DEFAULT_LOCALE] = {}
|
||||
app['localized'][DEFAULT_LOCALE]['name'] = bestapk.get('name')
|
||||
|
||||
|
||||
def get_apps_with_packages(apps, apks):
|
||||
|
|
Loading…
Reference in New Issue
Block a user