Skip to content

Commit 546722b

Browse files
authored
Merge pull request #1640 from UlrichB22/translations_99
Translations: use .format() in string formatting
2 parents 98ef7e7 + b30e1aa commit 546722b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3231
-3751
lines changed

src/moin/apps/admin/views.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Copyright: 2009 MoinMoin:EugeneSyromyatnikov
55
# Copyright: 2010 MoinMoin:DiogenesAugusto
66
# Copyright: 2010 MoinMoin:ReimarBauer
7+
# Copyright: 2024 MoinMoin:UlrichB
78
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
89

910
"""
@@ -119,7 +120,7 @@ def register_new_user():
119120
flash(_("This email already belongs to somebody else."), 'error')
120121
if not (users or emails):
121122
user_profile.save()
122-
flash(_("Account for %(username)s created", username=username), "info")
123+
flash(_("Account for {username} created").format(username=username), "info")
123124
form = FormClass.from_defaults()
124125

125126
u = user.User(auth_username=username)
@@ -128,9 +129,9 @@ def register_new_user():
128129
if not is_ok:
129130
flash(msg, "error")
130131
else:
131-
flash(L_("%(username)s has been sent a password recovery email.", username=username), "info")
132+
flash(L_("{username} has been sent a password recovery email.").format(username=username), "info")
132133
else:
133-
flash(_("%(username)s is an invalid user, no email has been sent.", username=username), "error")
134+
flash(_("{username} is an invalid user, no email has been sent.").format(username=username), "error")
134135

135136
return render_template('admin/register_new_user.html',
136137
title_name=title_name,
@@ -177,7 +178,7 @@ def userprofile(user_name):
177178
"""
178179
u = user.User(auth_username=user_name)
179180
if request.method == 'GET':
180-
return _("User profile of %(username)s: %(email)s %(disabled)s", username=user_name,
181+
return _("User profile of {username}: {email} {disabled}").format(username=user_name,
181182
email=u.email, disabled=u.disabled)
182183

183184
if request.method == 'POST':
@@ -548,12 +549,12 @@ def modify_acl(item_name):
548549
item._save(meta=meta)
549550
except AccessDenied:
550551
# superuser viewed item acl report and tried to change acl but lacked admin permission
551-
flash(L_("Failed! Not authorized.<br>Item: %(item_name)s<br>ACL: %(acl_rule)s",
552-
item_name=fqname.fullname, acl_rule=old_acl), "error")
552+
flash(L_("Failed! Not authorized.<br>Item: {item_name}<br>ACL: {acl_rule}"
553+
).format(item_name=fqname.fullname, acl_rule=old_acl), "error")
553554
return redirect(url_for('.item_acl_report'))
554-
flash(L_("Success! ACL saved.<br>Item: %(item_name)s<br>ACL: %(acl_rule)s",
555-
item_name=fqname.fullname, acl_rule=new_acl), "info")
555+
flash(L_("Success! ACL saved.<br>Item: {item_name}<br>ACL: {acl_rule}"
556+
).format(item_name=fqname.fullname, acl_rule=new_acl), "info")
556557
else:
557-
flash(L_("Nothing changed, invalid ACL.<br>Item: %(item_name)s<br>ACL: %(acl_rule)s",
558-
item_name=fqname.fullname, acl_rule=new_acl), "error")
558+
flash(L_("Nothing changed, invalid ACL.<br>Item: {item_name}<br>ACL: {acl_rule}"
559+
).format(item_name=fqname.fullname, acl_rule=new_acl), "error")
559560
return redirect(url_for('.item_acl_report'))

src/moin/apps/frontend/views.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Copyright: 2010 MoinMoin:DiogenesAugusto
77
# Copyright: 2001 Richard Jones <[email protected]>
88
# Copyright: 2001 Juergen Hermann <[email protected]>
9-
# Copyright: 2023 MoinMoin project
9+
# Copyright: 2023-2024 MoinMoin:UlrichB
1010
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
1111

1212
"""
@@ -445,15 +445,15 @@ def search(item_name):
445445
results = searcher.search(q, filter=_filter, limit=100, terms=True, sortedby=facets)
446446
# this may be an ajax transaction, search.js will handle a full page response
447447
except QueryError:
448-
flash(_("""QueryError: invalid search term: %(search_term)s""", search_term=q), "error")
448+
flash(_("""QueryError: invalid search term: {search_term}""").format(search_term=q), "error")
449449
return render_template('search.html',
450450
query=query,
451451
medium_search_form=search_form,
452452
item_name=item_name,
453453
)
454454
except TermNotFound:
455455
# name:'moin has bugs'
456-
flash(_("""TermNotFound: field is not indexed: %(search_term)s""", search_term=q), "error")
456+
flash(_("""TermNotFound: field is not indexed: {search_term}""").format(search_term=q), "error")
457457
return render_template('search.html',
458458
query=query,
459459
medium_search_form=search_form,
@@ -577,7 +577,7 @@ def show_item(item_name, rev):
577577
for rev in revs:
578578
fq_names.extend(rev.fqnames)
579579
return render_template("link_list_no_item_panel.html",
580-
headline=_("Items with %(field)s %(value)s", field=fqname.field, value=fqname.value),
580+
headline=_("Items with {field} {value}").format(field=fqname.field, value=fqname.value),
581581
fqname=fqname,
582582
fq_names=fq_names,
583583
item_is_deleted=item_is_deleted,
@@ -1027,7 +1027,7 @@ def ajaxdestroy(item_name, req='destroy'):
10271027
if isinstance(item, NonExistent):
10281028
# we should not try to destroy a nonexistent item,
10291029
# user probably checked a subitem and checked do subitems
1030-
response["messages"].append(_("Item '%(bad_name)s' does not exist.", bad_name=item.name))
1030+
response["messages"].append(_("Item '{bad_name}' does not exist.").format(bad_name=item.name))
10311031
continue
10321032
if req == 'destroy':
10331033
subitem_names = []
@@ -1044,13 +1044,13 @@ def ajaxdestroy(item_name, req='destroy'):
10441044
messages, subitem_names = item.delete(comment, do_subitems=do_subitems, ajax=True)
10451045
except AccessDenied:
10461046
# some deletes may have succeeded, one failed, there may be unprocessed items
1047-
msg = _("Access denied for a subitem of %(bad_name)s, check History for status.",
1048-
bad_name=itemname)
1047+
msg = _("Access denied for a subitem of {bad_name}, check History for status."
1048+
).format(bad_name=itemname)
10491049
response["messages"].append(msg)
10501050
response["messages"] += messages
10511051
response["itemnames"] += subitem_names + itemnames
10521052
except AccessDenied:
1053-
response["messages"].append(_("Access denied processing '%(bad_name)s'.", bad_name=itemname))
1053+
response["messages"].append(_("Access denied processing '{bad_name}'.").format(bad_name=itemname))
10541054
response["itemnames"] = [url_for_item(x) for x in response["itemnames"]]
10551055
return jsonify(response)
10561056

@@ -1239,17 +1239,17 @@ def jfu_server(item_name):
12391239
base_file_name = os.path.basename(data_file.filename)
12401240
file_name = secure_filename(base_file_name)
12411241
if not file_name == base_file_name:
1242-
msg = _("File Successfully uploaded and renamed from %(bad_name)s to %(good_name)s. ",
1243-
bad_name=base_file_name, good_name=file_name)
1242+
msg = _("File Successfully uploaded and renamed from {bad_name} to {good_name}. "
1243+
).format(bad_name=base_file_name, good_name=file_name)
12441244
subitem_name = file_name
12451245
data = data_file.stream
12461246
mt = mime_type.MimeType(filename=file_name)
12471247
contenttype = mt.content_type(charset='utf-8')
12481248
small_meta = {CONTENTTYPE: contenttype}
12491249
valid = validate_data(small_meta, data)
12501250
if not valid:
1251-
msg = _("UnicodeDecodeError, upload failed, not a text file, nothing saved: '%(file_name)s'. "
1252-
"Try changing the name.", file_name=file_name)
1251+
msg = _("UnicodeDecodeError, upload failed, not a text file, nothing saved: '{file_name}'. "
1252+
"Try changing the name.").format(file_name=file_name)
12531253
ret = make_response(jsonify({"name": subitem_name,
12541254
"files": [item_name],
12551255
"message": msg,
@@ -1267,13 +1267,13 @@ def jfu_server(item_name):
12671267
try:
12681268
item = Item.create(item_name)
12691269
if not isinstance(item, NonExistent):
1270-
msg += _("File Successfully uploaded, existing file overwritten: '%(file_name)s'.", file_name=file_name)
1270+
msg += _("File Successfully uploaded, existing file overwritten: '{file_name}'.").format(file_name=file_name)
12711271
revid, size = item.modify({'itemtype': ITEMTYPE_DEFAULT, }, data, contenttype_guessed=contenttype)
12721272
jfu_server_lock.release()
12731273
except AccessDenied:
12741274
# return 200 status with error message
12751275
jfu_server_lock.release()
1276-
msg = _("Permission denied, upload failed: '%(file_name)s'.", file_name=file_name)
1276+
msg = _("Permission denied, upload failed: '{file_name}'.").format(file_name=file_name)
12771277
ret = make_response(jsonify({"name": subitem_name,
12781278
"files": [item_name],
12791279
"message": msg,
@@ -1285,7 +1285,7 @@ def jfu_server(item_name):
12851285
data_file.close()
12861286
item_modified.send(app, fqname=item.fqname, action=ACTION_SAVE, new_meta=item.meta)
12871287
if not msg:
1288-
msg = _("File Successfully uploaded: '%(item_name)s'.", item_name=item_name)
1288+
msg = _("File Successfully uploaded: '{item_name}'.").format(item_name=item_name)
12891289
ret = make_response(jsonify(name=subitem_name,
12901290
files=[item_name],
12911291
message=msg,
@@ -1384,13 +1384,13 @@ def name_initial(files, uppercase=False, lowercase=False):
13841384
if item.fqname.value == NAMESPACE_ALL:
13851385
title = _("Global Index of All Namespaces")
13861386
elif item.meta['namespace']:
1387-
what = _("Namespace '%(name)s' ", name=item.meta['namespace'])
1387+
what = _("Namespace '{name}' ").format(name=item.meta['namespace'])
13881388
subitem = item_name[ns_len:]
13891389
if subitem:
1390-
what = what + _("subitems '%(item_name)s'", item_name=subitem)
1391-
title = _("Index of %(what)s", what=what)
1390+
what = what + _("subitems '{item_name}'").format(item_name=subitem)
1391+
title = _("Index of {what}").format(what=what)
13921392
else:
1393-
title = _("Index of subitems '%(item_name)s'", item_name=item_name)
1393+
title = _("Index of subitems '{item_name}'").format(item_name=item_name)
13941394
else:
13951395
title = _("Global Index")
13961396
close_file(item.rev.data)
@@ -1493,8 +1493,8 @@ def forwardrefs(item_name):
14931493
return render_template('link_list_item_panel.html',
14941494
item_name=item_name,
14951495
fqname=split_fqname(item_name),
1496-
headline=_("Items that are referred by '%(item_name)s'",
1497-
item_name=shorten_item_id(item_name)),
1496+
headline=_("Items that are referred by '{item_name}'"
1497+
).format(item_name=shorten_item_id(item_name)),
14981498
fq_names=split_fqname_list(refs),
14991499
)
15001500

@@ -1536,7 +1536,7 @@ def backrefs(item_name):
15361536
item=item,
15371537
item_name=item_name,
15381538
fqname=split_fqname(item_name),
1539-
headline=_("Items which refer to '%(item_name)s'", item_name=shorten_item_id(item_name)),
1539+
headline=_("Items which refer to '{item_name}'").format(item_name=shorten_item_id(item_name)),
15401540
fq_names=refs_here,
15411541
)
15421542

@@ -1700,7 +1700,7 @@ def global_history(namespace):
17001700
if namespace == NAMESPACE_ALL:
17011701
title = _("Global History of All Namespaces")
17021702
elif namespace:
1703-
title = _("History of Namespace '%(namespace)s'", namespace=namespace)
1703+
title = _("History of Namespace '{namespace}'").format(namespace=namespace)
17041704
else:
17051705
title = _("Global History")
17061706
current_timestamp = int(time.time())
@@ -1798,7 +1798,7 @@ def quicklink_item(item_name):
17981798
u = flaskg.user
17991799
msg = None
18001800
if not u.valid:
1801-
msg = _("You must login to use this action: %(action)s.", action="quicklink/quickunlink"), "error"
1801+
msg = _("You must login to use this action: {action}.").format(action="quicklink/quickunlink"), "error"
18021802
elif not flaskg.user.is_quicklinked_to([item_name]):
18031803
if not u.quicklink(item_name):
18041804
msg = _('A quicklink to this page could not be added for you.'), "error"
@@ -1822,7 +1822,7 @@ def subscribe_item(item_name):
18221822
if isinstance(item, NonExistent):
18231823
abort(404, item_name)
18241824
if not u.valid:
1825-
msg = _("You must login to use this action: %(action)s.", action="subscribe/unsubscribe"), "error"
1825+
msg = _("You must login to use this action: {action}.").format(action="subscribe/unsubscribe"), "error"
18261826
elif not u.may.read(item_name):
18271827
msg = _("You are not allowed to subscribe to an item you may not read."), "error"
18281828
elif u.is_subscribed_to(item):
@@ -1918,9 +1918,9 @@ def register():
19181918
if is_ok:
19191919
flash(_('Account verification required, please see the email we sent to your address.'), "info")
19201920
else:
1921-
flash(_('An error occurred while sending the verification email: "%(message)s" '
1922-
'Please contact an administrator to activate your account.',
1923-
message=msg), "error")
1921+
flash(_('An error occurred while sending the verification email: "{message}" '
1922+
'Please contact an administrator to activate your account.'
1923+
).format(message=msg), "error")
19241924
else:
19251925
flash(_('Account created, please log in now.'), "info")
19261926
return redirect(url_for('.show_root'))
@@ -2363,7 +2363,7 @@ class UserSettingsUIForm(Form):
23632363
if user.search_users(**{NAME_EXACT: name}):
23642364
# duplicate name
23652365
response['flash'].append(
2366-
(_("The username '%(name)s' is already in use.", name=name), "error")
2366+
(_("The username '{name}' is already in use.").format(name=name), "error")
23672367
)
23682368
success = False
23692369
if part == 'notification':
@@ -2682,8 +2682,8 @@ def similar_names(item_name):
26822682
if rank == wanted_rank:
26832683
fq_names.append(fqname)
26842684
return render_template("link_list_item_panel.html",
2685-
headline=_("Items with similar names to '%(item_name)s'",
2686-
item_name=shorten_item_id(item_name)),
2685+
headline=_("Items with similar names to '{item_name}'"
2686+
).format(item_name=shorten_item_id(item_name)),
26872687
item=item,
26882688
item_name=item_name, # XXX no item
26892689
fqname=split_fqname(item_name),
@@ -2790,7 +2790,7 @@ def global_tags(namespace):
27902790
elif namespace == NAMESPACE_ALL:
27912791
headline = _("Global Tags in All Namespaces")
27922792
else:
2793-
headline = _("Tags in Namespace '%(namespace)s'", namespace=namespace)
2793+
headline = _("Tags in Namespace '{namespace}'").format(namespace=namespace)
27942794
metas = flaskg.storage.search_meta(query, idx_name=LATEST_REVS, sortedby=[NAME], limit=None)
27952795
tags_counts = {}
27962796
for meta in metas:
@@ -2838,7 +2838,7 @@ def tagged_items(tag, namespace):
28382838
fq_names = [gen_fqnames(meta) for meta in metas]
28392839
fq_names = [fqn for sublist in fq_names for fqn in sublist]
28402840
return render_template("link_list_no_item_panel.html",
2841-
headline=_("Items tagged with %(tag)s", tag=tag),
2841+
headline=_("Items tagged with {tag}").format(tag=tag),
28422842
item_name=tag,
28432843
fq_names=fq_names)
28442844

src/moin/auth/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Copyright: MoinMoin:FrankieChow, MoinMoin:NirSoffer
44
# Copyright: 2005-2012 MoinMoin:ThomasWaldmann
55
# Copyright: 2007 MoinMoin:JohannesBerg
6-
# Copyright: 2023 MoinMoin project
6+
# Copyright: 2023-2024 MoinMoin:UlrichB
77
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
88

99
"""
@@ -271,10 +271,9 @@ def login_hint(self):
271271
if app.cfg.registration_only_by_superuser:
272272
msg = app.cfg.registration_hint + ' '
273273
else:
274-
msg = _('If you do not have an account, <a href="%(register_url)s">you can create one now</a>. ',
275-
register_url=url_for('frontend.register'))
276-
msg += _('<a href="%(recover_url)s">Forgot your password?</a>',
277-
recover_url=url_for('frontend.lostpass'))
274+
msg = _('If you do not have an account, <a href="{register_url}">you can create one now</a>. '
275+
).format(register_url=url_for('frontend.register'))
276+
msg += _('<a href="{recover_url}">Forgot your password?</a>').format(recover_url=url_for('frontend.lostpass'))
278277
return Markup(msg)
279278

280279

src/moin/auth/ldap_login.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright: 2006-2008 MoinMoin:ThomasWaldmann
22
# Copyright: 2006 Nick Phillips
3+
# Copyright: 2024 MoinMoin:UlrichB
34
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
45

56
"""
@@ -266,7 +267,7 @@ def login(self, user_obj, **kw):
266267
# method).
267268
logging.error("LDAP server {0} failed ({1!s}). "
268269
"Trying to authenticate with next auth list entry.".format(server, err))
269-
return ContinueLogin(user_obj, _("LDAP server %(server)s failed.", server=server))
270+
return ContinueLogin(user_obj, _("LDAP server {server} failed.").format(server=server))
270271

271272
except: # noqa
272273
logging.exception("caught an exception, traceback follows...")

0 commit comments

Comments
 (0)