Source code
Revision control
Copy as Markdown
Other Tools
# Any copyright is dedicated to the Public Domain.
import re
import fluent.syntax.ast as FTL
from fluent.migrate.transforms import COPY_PATTERN, TransformPattern
class REMOVE_SHORTCUT(TransformPattern):
"""Reuse the existing translation, removing the { $shortcut } placeable, the
parentheses (ASCII or fullwidth) around it and any whitespace left at the end."""
def visit_Pattern(self, node):
node = super().visit_Pattern(node)
elements = []
for element in node.elements:
if isinstance(element, FTL.Placeable) and isinstance(
element.expression, FTL.VariableReference
):
if element.expression.id.name == "shortcut":
continue
elif isinstance(element, FTL.TextElement):
element.value = re.sub(r"[()()]", "", element.value)
if not element.value:
continue
elements.append(element)
if elements and isinstance(elements[-1], FTL.TextElement):
elements[-1].value = elements[-1].value.rstrip()
node.elements = elements
return node
def migrate(ctx):
path = "browser/browser/browser.ftl"
ctx.add_transforms(
path,
path,
[
FTL.Message(
id=FTL.Identifier("toolbar-button-save-page-without-shortcut"),
attributes=[
FTL.Attribute(
FTL.Identifier("label"),
COPY_PATTERN(path, "toolbar-button-save-page.label"),
),
FTL.Attribute(
FTL.Identifier("tooltiptext"),
REMOVE_SHORTCUT(path, "toolbar-button-save-page.tooltiptext"),
),
],
),
FTL.Message(
id=FTL.Identifier("toolbar-button-open-file-without-shortcut"),
attributes=[
FTL.Attribute(
FTL.Identifier("label"),
COPY_PATTERN(path, "toolbar-button-open-file.label"),
),
FTL.Attribute(
FTL.Identifier("tooltiptext"),
REMOVE_SHORTCUT(path, "toolbar-button-open-file.tooltiptext"),
),
],
),
FTL.Message(
id=FTL.Identifier("toolbar-button-new-private-window-without-shortcut"),
attributes=[
FTL.Attribute(
FTL.Identifier("label"),
COPY_PATTERN(path, "toolbar-button-new-private-window.label"),
),
FTL.Attribute(
FTL.Identifier("tooltiptext"),
REMOVE_SHORTCUT(
path, "toolbar-button-new-private-window.tooltiptext"
),
),
],
),
FTL.Message(
id=FTL.Identifier("toolbar-button-history-without-shortcut"),
attributes=[
FTL.Attribute(
FTL.Identifier("label"),
COPY_PATTERN(path, "toolbar-button-history.label"),
),
FTL.Attribute(
FTL.Identifier("tooltiptext"),
REMOVE_SHORTCUT(path, "toolbar-button-history.tooltiptext"),
),
],
),
FTL.Message(
id=FTL.Identifier("toolbar-button-find-without-shortcut"),
attributes=[
FTL.Attribute(
FTL.Identifier("label"),
COPY_PATTERN(path, "toolbar-button-find.label"),
),
FTL.Attribute(
FTL.Identifier("tooltiptext"),
REMOVE_SHORTCUT(path, "toolbar-button-find.tooltiptext"),
),
],
),
FTL.Message(
id=FTL.Identifier("toolbar-button-developer-without-shortcut"),
attributes=[
FTL.Attribute(
FTL.Identifier("label"),
COPY_PATTERN(path, "toolbar-button-developer.label"),
),
FTL.Attribute(
FTL.Identifier("tooltiptext"),
REMOVE_SHORTCUT(path, "toolbar-button-developer.tooltiptext"),
),
],
),
FTL.Message(
id=FTL.Identifier("toolbar-button-zoom-out-without-shortcut"),
attributes=[
FTL.Attribute(
FTL.Identifier("label"),
COPY_PATTERN(path, "toolbar-button-zoom-out.label"),
),
FTL.Attribute(
FTL.Identifier("tooltiptext"),
COPY_PATTERN(path, "toolbar-button-zoom-out.label"),
),
],
),
FTL.Message(
id=FTL.Identifier("toolbar-button-zoom-in-without-shortcut"),
attributes=[
FTL.Attribute(
FTL.Identifier("label"),
COPY_PATTERN(path, "toolbar-button-zoom-in.label"),
),
FTL.Attribute(
FTL.Identifier("tooltiptext"),
COPY_PATTERN(path, "toolbar-button-zoom-in.label"),
),
],
),
FTL.Message(
id=FTL.Identifier("navbar-print-without-shortcut"),
attributes=[
FTL.Attribute(
FTL.Identifier("label"),
COPY_PATTERN(path, "navbar-print.label"),
),
FTL.Attribute(
FTL.Identifier("tooltiptext"),
REMOVE_SHORTCUT(path, "navbar-print.tooltiptext"),
),
],
),
FTL.Message(
id=FTL.Identifier("toolbar-button-zoom-reset-without-shortcut-tooltip"),
value=REMOVE_SHORTCUT(path, "toolbar-button-zoom-reset-tooltip"),
),
],
)