Skip to content

Commit

Permalink
chore: use f-string insted of % formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed May 7, 2024
1 parent b22df8c commit 8f93d67
Show file tree
Hide file tree
Showing 87 changed files with 281 additions and 288 deletions.
11 changes: 5 additions & 6 deletions translate/convert/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ def add_duplicates_option(self, default="msgctxt"):
default=default,
type="choice",
choices=["msgctxt", "merge"],
help="what to do with duplicate strings (identical source text): merge, msgctxt (default: '%s')"
% default,
help=f"what to do with duplicate strings (identical source text): merge, msgctxt (default: '{default}')",
metavar="DUPLICATESTYLE",
)
self.passthrough.append("duplicatestyle")
Expand Down Expand Up @@ -410,7 +409,7 @@ def opentemplatefile(self, options, fulltemplatepath):
# TODO: deal with different names in input/template archives
if fulltemplatepath in self.templatearchive:
return self.templatearchive.openinputfile(fulltemplatepath)
self.warning("missing template file %s" % fulltemplatepath)
self.warning(f"missing template file {fulltemplatepath}")
return super().opentemplatefile(options, fulltemplatepath)

def getfulltemplatepath(self, options, templatepath):
Expand Down Expand Up @@ -452,8 +451,8 @@ def openoutputfile(self, options, fulloutputpath):
outputstream = self.outputarchive.openoutputfile(fulloutputpath)
if outputstream is None:
self.warning(
"Could not find where to put %s in output "
"archive; writing to tmp" % fulloutputpath
f"Could not find where to put {fulloutputpath} in output "
"archive; writing to tmp"
)
return BytesIO()
return outputstream
Expand All @@ -464,7 +463,7 @@ def recursiveprocess(self, options):
if hasattr(options, "multifilestyle"):
self.archiveoptions = {"multifilestyle": options.multifilestyle}
for filetype in ("input", "output", "template"):
allowoption = "allowrecursive%s" % filetype
allowoption = f"allowrecursive{filetype}"
if options.multifilestyle == "onefile" and getattr(
options, allowoption, True
):
Expand Down
2 changes: 1 addition & 1 deletion translate/convert/csv2po.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def convertstore(self, thecsvfile):
)
else:
targetheader = self.pofile.makeheader(charset="UTF-8", encoding="8bit")
targetheader.addnote("extracted from %s" % self.csvfile.filename, "developer")
targetheader.addnote(f"extracted from {self.csvfile.filename}", "developer")
mightbeheader = True
for csvunit in self.csvfile.units:
# if self.charset is not None:
Expand Down
2 changes: 1 addition & 1 deletion translate/convert/dtd2po.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def convertstore(self, dtd_store):
x_accelerator_marker="&",
x_merge_on="location",
)
targetheader.addnote("extracted from %s" % dtd_store.filename, "developer")
targetheader.addnote(f"extracted from {dtd_store.filename}", "developer")

dtd_store.makeindex()
self.mixedentities = self.mixer.match_entities(dtd_store.id_index)
Expand Down
4 changes: 2 additions & 2 deletions translate/convert/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, afile):
self.file = afile

def __str__(self):
return "Unable to find extension for file: %s" % (self.file)
return f"Unable to find extension for file: {self.file}"


class UnsupportedConversionError(Exception):
Expand All @@ -53,7 +53,7 @@ def __init__(self, in_ext=None, out_ext=None, templ_ext=None):
def __str__(self):
msg = f"Unsupported conversion from {self.in_ext} to {self.out_ext}"
if self.templ_ext:
msg += " with template %s" % (self.templ_ext)
msg += f" with template {self.templ_ext}"
return msg


Expand Down
2 changes: 1 addition & 1 deletion translate/convert/ical2po.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def convert_unit(self, unit):

def convert_store(self):
"""Convert a single source format file to a target format file."""
self.extraction_msg = "extracted from %s" % self.source_store.filename
self.extraction_msg = f"extracted from {self.source_store.filename}"

for source_unit in self.source_store.units:
self.target_store.addunit(self.convert_unit(source_unit))
Expand Down
2 changes: 1 addition & 1 deletion translate/convert/ini2po.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def convert_unit(self, unit):

def convert_store(self):
"""Convert a single source format file to a target format file."""
self.extraction_msg = "extracted from %s" % self.source_store.filename
self.extraction_msg = f"extracted from {self.source_store.filename}"

for source_unit in self.source_store.units:
self.target_store.addunit(self.convert_unit(source_unit))
Expand Down
2 changes: 1 addition & 1 deletion translate/convert/json2po.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def convert_store(self, input_store, duplicatestyle="msgctxt"):
"""Converts a JSON file to a PO file."""
output_store = po.pofile()
output_header = output_store.header()
output_header.addnote("extracted from %s" % input_store.filename, "developer")
output_header.addnote(f"extracted from {input_store.filename}", "developer")
for input_unit in input_store.units:
output_unit = self.convert_unit(input_unit, "developer")
if output_unit is not None:
Expand Down
2 changes: 1 addition & 1 deletion translate/convert/mozlang2po.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def convert_unit(self, unit):

def convert_store(self):
"""Convert a single source format file to a target format file."""
self.extraction_msg = "extracted from %s" % self.source_store.filename
self.extraction_msg = f"extracted from {self.source_store.filename}"

for source_unit in self.source_store.units:
self.target_store.addunit(self.convert_unit(source_unit))
Expand Down
20 changes: 11 additions & 9 deletions translate/convert/oo2po.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,23 @@ def convertstore(self, theoofile, duplicatestyle="msgctxt"):
"""Converts an entire oo file to a base class format (.po or XLIFF)."""
thetargetfile = po.pofile()
# create a header for the file
bug_url = "http://qa.openoffice.org/issues/enter_bug.cgi?%s" % parse.urlencode(
{
"subcomponent": "ui",
"comment": "",
"short_desc": "Localization issue in file: %s" % theoofile.filename,
"component": "l10n",
"form_name": "enter_issue",
}
bug_url = "http://qa.openoffice.org/issues/enter_bug.cgi?{}".format(
parse.urlencode(
{
"subcomponent": "ui",
"comment": "",
"short_desc": f"Localization issue in file: {theoofile.filename}",
"component": "l10n",
"form_name": "enter_issue",
}
)
)
targetheader = thetargetfile.init_headers(
x_accelerator_marker="~",
x_merge_on="location",
report_msgid_bugs_to=bug_url,
)
targetheader.addnote("extracted from %s" % theoofile.filename, "developer")
targetheader.addnote(f"extracted from {theoofile.filename}", "developer")
thetargetfile.setsourcelanguage(self.sourcelanguage)
thetargetfile.settargetlanguage(self.targetlanguage)
# go through the oo and convert each element
Expand Down
2 changes: 1 addition & 1 deletion translate/convert/php2po.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def convert_unit(self, unit):

def convert_store(self):
"""Convert a single source format file to a target format file."""
self.extraction_msg = "extracted from %s" % self.source_store.filename
self.extraction_msg = f"extracted from {self.source_store.filename}"

for source_unit in self.source_store.units:
self.target_store.addunit(self.convert_unit(source_unit))
Expand Down
4 changes: 2 additions & 2 deletions translate/convert/po2dtd.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@


def dtdwarning(message, category, filename, lineno, line=None):
return "Warning: %s\n" % message
return f"Warning: {message}\n"


warnings.formatwarning = dtdwarning
Expand All @@ -56,7 +56,7 @@ def applytranslation(entity, dtdunit, inputunit, mixedentities):
if entity in mixedentities:
label, unquotedstr = accesskey.extract(unquotedstr)
if not unquotedstr:
warnings.warn("Could not find accesskey for %s" % entity)
warnings.warn(f"Could not find accesskey for {entity}")
# Use the source language accesskey
label, unquotedstr = accesskey.extract(inputunit.source)
else:
Expand Down
6 changes: 3 additions & 3 deletions translate/convert/po2prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def applytranslation(key, propunit, inunit, mixedkeys):
if key.endswith(akeysuffix) and key in mixedkeys:
label, value = accesskey.extract(value)
if not value:
warnings.warn("Could not find accesskey for %s" % key)
warnings.warn(f"Could not find accesskey for {key}")
# Use the source language accesskey
label, value = accesskey.extract(inunit.source)
else:
Expand Down Expand Up @@ -166,7 +166,7 @@ def _explode_gwt_plurals(self):
if category != "":
new_location = f"{location}[{category}]"
else:
new_location = "%s" % (location)
new_location = f"{location}"
new_unit.addlocation(new_location)
new_unit.target = text
self.inputstore.locationindex[new_location] = new_unit
Expand All @@ -191,7 +191,7 @@ def convertline(self, line):
self.inmultilinemsgid = True
if delimiter_pos == -1:
key = self.personality.key_strip(line)
delimiter = " %s " % self.personality.delimiters[0]
delimiter = f" {self.personality.delimiters[0]} "
else:
key = self.personality.key_strip(line[:delimiter_pos])
# Calculate space around the equal sign
Expand Down
4 changes: 2 additions & 2 deletions translate/convert/po2rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def main(argv=None):
"--charset",
dest="charset",
default=defaultcharset,
help="charset to use to decode the RC files (default: %s)" % defaultcharset,
help=f"charset to use to decode the RC files (default: {defaultcharset})",
metavar="CHARSET",
)
parser.add_option(
Expand All @@ -402,7 +402,7 @@ def main(argv=None):
"--sublang",
dest="sublang",
default=defaultsublang,
help="SUBLANG entry (default: %s)" % defaultsublang,
help=f"SUBLANG entry (default: {defaultsublang})",
metavar="SUBLANG",
)
parser.passthrough.append("charset")
Expand Down
6 changes: 3 additions & 3 deletions translate/convert/po2symb.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
def escape(text):
for key, val in po_escape_map.items():
text = text.replace(key, val)
return '"%s"' % text
return f'"{text}"'


def replace_header_items(ps, replacments):
Expand All @@ -52,7 +52,7 @@ def replace_header_items(ps, replacments):
key = match.groupdict()["key"]
if key in replacments:
ps.current_line = match.expand(
"\\g<key>\\g<space>%s\n" % replacments[key]
f"\\g<key>\\g<space>{replacments[key]}\n"
)
ps.read_line()

Expand All @@ -71,7 +71,7 @@ def parse(ps, header_replacements, body_replacements):
body_replacements[key].target or body_replacements[key].source
)
ps.current_line = match.expand(
"\\g<start>\\g<id>\\g<space>%s\n" % escape(value)
f"\\g<start>\\g<id>\\g<space>{escape(value)}\n"
)
ps.read_line()
except StopIteration:
Expand Down
8 changes: 4 additions & 4 deletions translate/convert/pot2po.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def convert_stores(
def _prepare_merge(input_store, output_store, template_store, **kwargs):
"""Prepare stores & TM matchers before merging."""
# Dispatch to format specific functions
prepare_merge_hook = "_prepare_merge_%s" % input_store.__class__.__name__
prepare_merge_hook = f"_prepare_merge_{input_store.__class__.__name__}"
if prepare_merge_hook in globals():
globals()[prepare_merge_hook](
input_store, output_store, template_store, **kwargs
Expand All @@ -159,7 +159,7 @@ def _store_pre_merge(input_store, output_store, template_store, **kwargs):
output_store.header = input_store.header

# Dispatch to format specific functions
store_pre_merge_hook = "_store_pre_merge_%s" % input_store.__class__.__name__
store_pre_merge_hook = f"_store_pre_merge_{input_store.__class__.__name__}"
if store_pre_merge_hook in globals():
globals()[store_pre_merge_hook](
input_store, output_store, template_store, **kwargs
Expand All @@ -172,7 +172,7 @@ def _store_post_merge(input_store, output_store, template_store, **kwargs):
obsolete messages and similar wrapup tasks.
"""
# Dispatch to format specific functions
store_post_merge_hook = "_store_post_merge_%s" % input_store.__class__.__name__
store_post_merge_hook = f"_store_post_merge_{input_store.__class__.__name__}"
if store_post_merge_hook in globals():
globals()[store_post_merge_hook](
input_store, output_store, template_store, **kwargs
Expand All @@ -185,7 +185,7 @@ def _unit_post_merge(input_unit, input_store, output_store, template_store, **kw
function.
"""
# dispatch to format specific functions
unit_post_merge_hook = "_unit_post_merge_%s" % input_unit.__class__.__name__
unit_post_merge_hook = f"_unit_post_merge_{input_unit.__class__.__name__}"
if unit_post_merge_hook in globals():
globals()[unit_post_merge_hook](
input_unit, input_store, output_store, template_store, **kwargs
Expand Down
6 changes: 3 additions & 3 deletions translate/convert/prop2po.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def convertstore(self, thepropfile):
)
else:
targetheader = thetargetfile.header()
targetheader.addnote("extracted from %s" % thepropfile.filename, "developer")
targetheader.addnote(f"extracted from {thepropfile.filename}", "developer")

thepropfile.makeindex()
self.mixedkeys = self.mixer.match_entities(thepropfile.id_index)
Expand Down Expand Up @@ -228,7 +228,7 @@ def __init__(self, unit):

# Some sanity checks
if not variant:
raise ValueError("Variant invalid: %s" % (old_variant))
raise ValueError(f"Variant invalid: {old_variant}")
if variant in plurals[key].variants:
logger.warning(
"Override %s[%s]: %s by %s",
Expand All @@ -245,7 +245,7 @@ def __init__(self, unit):
for key, plural in plurals.items():
# We should have at least "other" (no variant in GWT)
if "other" not in plural.variants:
raise ValueError("Should have property %s without any variant" % (key))
raise ValueError(f"Should have property {key} without any variant")
units = []
for name in names:
if name in plural.variants:
Expand Down
6 changes: 3 additions & 3 deletions translate/convert/rc2po.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def convert_store(self, input_store, duplicatestyle="msgctxt"):
x_accelerator_marker="&",
x_merge_on="location",
)
output_header.addnote("extracted from %s" % input_store.filename, "developer")
output_header.addnote(f"extracted from {input_store.filename}", "developer")
for input_unit in input_store.units:
output_unit = self.convert_unit(input_unit, "developer")
if output_unit is not None:
Expand Down Expand Up @@ -153,7 +153,7 @@ def main(argv=None):
"--lang",
dest="lang",
default=DEFAULTLANG,
help="LANG entry (default: %s)" % DEFAULTLANG,
help=f"LANG entry (default: {DEFAULTLANG})",
metavar="LANG",
)
DEFAULTSUBLANG = None
Expand All @@ -162,7 +162,7 @@ def main(argv=None):
"--sublang",
dest="sublang",
default=DEFAULTSUBLANG,
help="SUBLANG entry (default: %s)" % DEFAULTSUBLANG,
help=f"SUBLANG entry (default: {DEFAULTSUBLANG})",
metavar="SUBLANG",
)
parser.add_duplicates_option()
Expand Down
2 changes: 1 addition & 1 deletion translate/convert/resx2po.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def convert_store(self, input_store, duplicatestyle="msgctxt"):
output_header = output_store.init_headers(
charset="UTF-8", encoding="8bit", x_accelerator_marker="&"
)
output_header.addnote("extracted from %s" % input_store.filename, "developer")
output_header.addnote(f"extracted from {input_store.filename}", "developer")
for input_unit in input_store.units:
if input_unit.istranslatable():
output_unit = self.convert_unit(input_unit, "developer")
Expand Down
2 changes: 1 addition & 1 deletion translate/convert/sub2po.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def convert_store(input_store, duplicatestyle="msgctxt"):
"""Converts a subtitle file to a .po file..."""
output_store = po.pofile()
output_header = output_store.header()
output_header.addnote("extracted from %s" % input_store.filename, "developer")
output_header.addnote(f"extracted from {input_store.filename}", "developer")

for input_unit in input_store.units:
output_unit = convert_unit(input_unit, "developer")
Expand Down
4 changes: 3 additions & 1 deletion translate/convert/tbx2po.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def convertfile(self, tbxfile):
term.source = tbxunit.source
term.target = tbxunit.target
term.setcontext(tbxunit.getnotes("definition"))
term.addnote("Part of speech: %s" % tbxunit.getnotes("pos"), "developer")
term.addnote(
"Part of speech: {}".format(tbxunit.getnotes("pos")), "developer"
)
self.pofile.addunit(term)
self.pofile.removeduplicates()
return self.pofile
Expand Down
2 changes: 1 addition & 1 deletion translate/convert/txt2po.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(

def convert_store(self):
"""Convert a single source format file to a target format file."""
self.extraction_msg = "extracted from %s" % self.source_store.filename
self.extraction_msg = f"extracted from {self.source_store.filename}"

for source_unit in self.source_store.units:
target_unit = self.target_store.addsourceunit(source_unit.source)
Expand Down
2 changes: 1 addition & 1 deletion translate/convert/yaml2po.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def convert_unit(self, unit):

def convert_store(self):
"""Convert a single source format file to a target format file."""
self.extraction_msg = "extracted from %s" % self.source_store.filename
self.extraction_msg = f"extracted from {self.source_store.filename}"

for source_unit in self.source_store.units:
self.target_store.addunit(self.convert_unit(source_unit))
Expand Down
Loading

0 comments on commit 8f93d67

Please sign in to comment.