1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-09-04 03:30:13 +02:00

metadata: make all strings translatable

This commit is contained in:
Hans-Christoph Steiner 2017-10-24 16:47:53 +02:00
parent ac69d5b17d
commit 230d8971ba

View File

@ -380,8 +380,8 @@ class FieldValidator():
values = [v] values = [v]
for v in values: for v in values:
if not self.compiled.match(v): if not self.compiled.match(v):
warn_or_exception("'%s' is not a valid %s in %s. Regex pattern: %s" warn_or_exception(_("'{value}' is not a valid {field} in {appid}. Regex pattern: {pattern}")
% (v, self.name, appid, self.matching)) .format(value=v, field=self.name, appid=appid, pattern=self.matching))
# Generic value types # Generic value types
@ -534,7 +534,7 @@ class DescriptionFormatter:
if txt.startswith("[["): if txt.startswith("[["):
index = txt.find("]]") index = txt.find("]]")
if index == -1: if index == -1:
warn_or_exception("Unterminated ]]") warn_or_exception(_("Unterminated ]]"))
url = txt[2:index] url = txt[2:index]
if self.linkResolver: if self.linkResolver:
url, urltext = self.linkResolver(url) url, urltext = self.linkResolver(url)
@ -546,7 +546,7 @@ class DescriptionFormatter:
else: else:
index = txt.find("]") index = txt.find("]")
if index == -1: if index == -1:
warn_or_exception("Unterminated ]") warn_or_exception(_("Unterminated ]"))
url = txt[1:index] url = txt[1:index]
index2 = url.find(' ') index2 = url.find(' ')
if index2 == -1: if index2 == -1:
@ -555,7 +555,7 @@ class DescriptionFormatter:
urltxt = url[index2 + 1:] urltxt = url[index2 + 1:]
url = url[:index2] url = url[:index2]
if url == urltxt: if url == urltxt:
warn_or_exception("Url title is just the URL - use [url]") warn_or_exception(_("URL title is just the URL, use brackets: [URL]"))
res_html += '<a href="' + url + '">' + html.escape(urltxt, quote=False) + '</a>' res_html += '<a href="' + url + '">' + html.escape(urltxt, quote=False) + '</a>'
res_plain += urltxt res_plain += urltxt
if urltxt != url: if urltxt != url:
@ -664,7 +664,7 @@ def parse_srclib(metadatapath):
try: try:
f, v = line.split(':', 1) f, v = line.split(':', 1)
except ValueError: except ValueError:
warn_or_exception("Invalid metadata in %s:%d" % (line, n)) warn_or_exception(_("Invalid metadata in %s:%d") % (line, n))
if f == "Subdir": if f == "Subdir":
thisinfo[f] = v.split(',') thisinfo[f] = v.split(',')
@ -734,7 +734,8 @@ def read_metadata(xref=True, check_vcs=[]):
+ glob.glob('.fdroid.yml')): + glob.glob('.fdroid.yml')):
packageName, _ignored = fdroidserver.common.get_extension(os.path.basename(metadatapath)) packageName, _ignored = fdroidserver.common.get_extension(os.path.basename(metadatapath))
if packageName in apps: if packageName in apps:
warn_or_exception("Found multiple metadata files for " + packageName) warn_or_exception(_("Found multiple metadata files for {appid}")
.format(path=packageName))
app = parse_metadata(metadatapath, packageName in check_vcs) app = parse_metadata(metadatapath, packageName in check_vcs)
check_metadata(app) check_metadata(app)
apps[app.id] = app apps[app.id] = app
@ -745,14 +746,14 @@ def read_metadata(xref=True, check_vcs=[]):
def linkres(appid): def linkres(appid):
if appid in apps: if appid in apps:
return ("fdroid.app:" + appid, "Dummy name - don't know yet") return ("fdroid.app:" + appid, "Dummy name - don't know yet")
warn_or_exception("Cannot resolve app id " + appid) warn_or_exception(_("Cannot resolve app id {appid}").format(appid=appid))
for appid, app in apps.items(): for appid, app in apps.items():
try: try:
description_html(app.Description, linkres) description_html(app.Description, linkres)
except MetaDataException as e: except MetaDataException as e:
warn_or_exception("Problem with description of " + appid + warn_or_exception(_("Problem with description of {appid}: {error}")
" - " + str(e)) .format(appid=appid, error=str(e)))
return apps return apps
@ -795,7 +796,8 @@ def get_default_app_info(metadatapath=None):
manifestroot = fdroidserver.common.parse_xml(os.path.join(root, 'AndroidManifest.xml')) manifestroot = fdroidserver.common.parse_xml(os.path.join(root, 'AndroidManifest.xml'))
break break
if manifestroot is None: if manifestroot is None:
warn_or_exception("Cannot find a packageName for {0}!".format(metadatapath)) warn_or_exception(_("Cannot find a packageName for {path}!")
.format(path=metadatapath))
appid = manifestroot.attrib['package'] appid = manifestroot.attrib['package']
app = App() app = App()
@ -915,7 +917,7 @@ def _decode_bool(s):
return True return True
if bool_false.match(s): if bool_false.match(s):
return False return False
warn_or_exception("Invalid bool '%s'" % s) warn_or_exception(_("Invalid boolean '%s'") % s)
def parse_metadata(metadatapath, check_vcs=False): def parse_metadata(metadatapath, check_vcs=False):
@ -924,8 +926,8 @@ def parse_metadata(metadatapath, check_vcs=False):
_ignored, ext = fdroidserver.common.get_extension(metadatapath) _ignored, ext = fdroidserver.common.get_extension(metadatapath)
accepted = fdroidserver.common.config['accepted_formats'] accepted = fdroidserver.common.config['accepted_formats']
if ext not in accepted: if ext not in accepted:
warn_or_exception('"%s" is not an accepted format, convert to: %s' % ( warn_or_exception(_('"{path}" is not an accepted format, convert to: {formats}')
metadatapath, ', '.join(accepted))) .format(path=metadatapath, formats=', '.join(accepted)))
app = App() app = App()
app.metadatapath = metadatapath app.metadatapath = metadatapath
@ -943,7 +945,8 @@ def parse_metadata(metadatapath, check_vcs=False):
elif ext == 'yml': elif ext == 'yml':
parse_yaml_metadata(mf, app) parse_yaml_metadata(mf, app)
else: else:
warn_or_exception('Unknown metadata format: %s' % metadatapath) warn_or_exception(_('Unknown metadata format: {path}')
.format(path=metadatapath))
if check_vcs and app.Repo: if check_vcs and app.Repo:
build_dir = fdroidserver.common.get_build_dir(app) build_dir = fdroidserver.common.get_build_dir(app)
@ -1162,12 +1165,12 @@ def parse_txt_metadata(mf, app):
def add_buildflag(p, build): def add_buildflag(p, build):
if not p.strip(): if not p.strip():
warn_or_exception("Empty build flag at {1}" warn_or_exception(_("Empty build flag at {linedesc}")
.format(buildlines[0], linedesc)) .format(linedesc=linedesc))
bv = p.split('=', 1) bv = p.split('=', 1)
if len(bv) != 2: if len(bv) != 2:
warn_or_exception("Invalid build flag at {0} in {1}" warn_or_exception(_("Invalid build flag at {line} in {linedesc}")
.format(buildlines[0], linedesc)) .format(line=buildlines[0], linedesc=linedesc))
pk, pv = bv pk, pv = bv
pk = pk.lstrip() pk = pk.lstrip()
@ -1186,7 +1189,8 @@ def parse_txt_metadata(mf, app):
v = "".join(lines) v = "".join(lines)
parts = [p.replace("\\,", ",") for p in re.split(build_line_sep, v)] parts = [p.replace("\\,", ",") for p in re.split(build_line_sep, v)]
if len(parts) < 3: if len(parts) < 3:
warn_or_exception("Invalid build format: " + v + " in " + mf.name) warn_or_exception(_("Invalid build format: {value} in {name}")
.format(value=v, name=mf.name))
build = Build() build = Build()
build.versionName = parts[0] build.versionName = parts[0]
build.versionCode = parts[1] build.versionCode = parts[1]
@ -1214,7 +1218,8 @@ def parse_txt_metadata(mf, app):
try: try:
int(versionCode) int(versionCode)
except ValueError: except ValueError:
warn_or_exception('Invalid versionCode: "' + versionCode + '" is not an integer!') warn_or_exception(_('Invalid versionCode: "{versionCode}" is not an integer!')
.format(versionCode=versionCode))
def add_comments(key): def add_comments(key):
if not curcomments: if not curcomments:
@ -1247,8 +1252,8 @@ def parse_txt_metadata(mf, app):
del buildlines[:] del buildlines[:]
else: else:
if not build.commit and not build.disable: if not build.commit and not build.disable:
warn_or_exception("No commit specified for {0} in {1}" warn_or_exception(_("No commit specified for {versionName} in {linedesc}")
.format(build.versionName, linedesc)) .format(versionName=build.versionName, linedesc=linedesc))
app.builds.append(build) app.builds.append(build)
add_comments('build:' + build.versionCode) add_comments('build:' + build.versionCode)
@ -1263,10 +1268,10 @@ def parse_txt_metadata(mf, app):
try: try:
f, v = line.split(':', 1) f, v = line.split(':', 1)
except ValueError: except ValueError:
warn_or_exception("Invalid metadata in " + linedesc) warn_or_exception(_("Invalid metadata in: ") + linedesc)
if f not in app_fields: if f not in app_fields:
warn_or_exception('Unrecognised app field: ' + f) warn_or_exception(_('Unrecognised app field: ') + f)
# Translate obsolete fields... # Translate obsolete fields...
if f == 'Market Version': if f == 'Market Version':
@ -1282,8 +1287,8 @@ def parse_txt_metadata(mf, app):
if ftype == TYPE_MULTILINE: if ftype == TYPE_MULTILINE:
mode = 1 mode = 1
if v: if v:
warn_or_exception("Unexpected text on same line as " warn_or_exception(_("Unexpected text on same line as {field} in {linedesc}")
+ f + " in " + linedesc) .format(field=f, linedesc=linedesc))
elif ftype == TYPE_STRING: elif ftype == TYPE_STRING:
app[f] = v app[f] = v
elif ftype == TYPE_LIST: elif ftype == TYPE_LIST:
@ -1300,24 +1305,26 @@ def parse_txt_metadata(mf, app):
elif ftype == TYPE_BUILD_V2: elif ftype == TYPE_BUILD_V2:
vv = v.split(',') vv = v.split(',')
if len(vv) != 2: if len(vv) != 2:
warn_or_exception('Build should have comma-separated', warn_or_exception(_('Build should have comma-separated '
'versionName and versionCode,', 'versionName and versionCode, '
'not "{0}", in {1}'.format(v, linedesc)) 'not "{value}", in {linedesc}')
.format(value=v, linedesc=linedesc))
build = Build() build = Build()
build.versionName = vv[0] build.versionName = vv[0]
build.versionCode = vv[1] build.versionCode = vv[1]
check_versionCode(build.versionCode) check_versionCode(build.versionCode)
if build.versionCode in vc_seen: if build.versionCode in vc_seen:
warn_or_exception('Duplicate build recipe found for versionCode %s in %s' warn_or_exception(_('Duplicate build recipe found for versionCode {versionCode} in {linedesc}')
% (build.versionCode, linedesc)) .format(versionCode=build.versionCode, linedesc=linedesc))
vc_seen.add(build.versionCode) vc_seen.add(build.versionCode)
del buildlines[:] del buildlines[:]
mode = 3 mode = 3
elif ftype == TYPE_OBSOLETE: elif ftype == TYPE_OBSOLETE:
pass # Just throw it away! pass # Just throw it away!
else: else:
warn_or_exception("Unrecognised field '" + f + "' in " + linedesc) warn_or_exception(_("Unrecognised field '{field}' in {linedesc}")
.format(field=f, linedesc=linedesc))
elif mode == 1: # Multiline field elif mode == 1: # Multiline field
if line == '.': if line == '.':
mode = 0 mode = 0
@ -1338,11 +1345,14 @@ def parse_txt_metadata(mf, app):
# Mode at end of file should always be 0 # Mode at end of file should always be 0
if mode == 1: if mode == 1:
warn_or_exception(f + " not terminated in " + mf.name) warn_or_exception(_("{field} not terminated in {name}")
.format(field=f, name=mf.name))
if mode == 2: if mode == 2:
warn_or_exception("Unterminated continuation in " + mf.name) warn_or_exception(_("Unterminated continuation in {name}")
.format(name=mf.name))
if mode == 3: if mode == 3:
warn_or_exception("Unterminated build in " + mf.name) warn_or_exception(_("Unterminated build in {name}")
.format(name=mf.name))
return app return app
@ -1501,8 +1511,8 @@ def write_metadata(metadatapath, app):
_ignored, ext = fdroidserver.common.get_extension(metadatapath) _ignored, ext = fdroidserver.common.get_extension(metadatapath)
accepted = fdroidserver.common.config['accepted_formats'] accepted = fdroidserver.common.config['accepted_formats']
if ext not in accepted: if ext not in accepted:
warn_or_exception('Cannot write "%s", not an accepted format, use: %s' warn_or_exception(_('Cannot write "{path}", not an accepted format, use: {formats}')
% (metadatapath, ', '.join(accepted))) .format(path=metadatapath, formats=', '.join(accepted)))
try: try:
with open(metadatapath, 'w', encoding='utf8') as mf: with open(metadatapath, 'w', encoding='utf8') as mf:
@ -1514,7 +1524,7 @@ def write_metadata(metadatapath, app):
os.remove(metadatapath) os.remove(metadatapath)
raise e raise e
warn_or_exception('Unknown metadata format: %s' % metadatapath) warn_or_exception(_('Unknown metadata format: %s') % metadatapath)
def add_metadata_arguments(parser): def add_metadata_arguments(parser):