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):
"""Bug 2093948 - Add navigation, bookmark, Picture-in-Picture, screenshot and sidebar tooltips without the shortcut, part {index}."""
browser = "browser/browser/browser.ftl"
ctx.add_transforms(
browser,
browser,
[
FTL.Message(
id=FTL.Identifier("urlbar-star-edit-bookmark-without-shortcut"),
attributes=[
FTL.Attribute(
FTL.Identifier("tooltiptext"),
REMOVE_SHORTCUT(
browser, "urlbar-star-edit-bookmark.tooltiptext"
),
),
],
),
FTL.Message(
id=FTL.Identifier("urlbar-star-add-bookmark-without-shortcut"),
attributes=[
FTL.Attribute(
FTL.Identifier("tooltiptext"),
REMOVE_SHORTCUT(
browser, "urlbar-star-add-bookmark.tooltiptext"
),
),
],
),
FTL.Message(
id=FTL.Identifier(
"picture-in-picture-urlbar-button-open-without-shortcut"
),
attributes=[
FTL.Attribute(
FTL.Identifier("tooltiptext"),
REMOVE_SHORTCUT(
browser, "picture-in-picture-urlbar-button-open.tooltiptext"
),
),
],
),
FTL.Message(
id=FTL.Identifier(
"picture-in-picture-urlbar-button-close-without-shortcut"
),
attributes=[
FTL.Attribute(
FTL.Identifier("tooltiptext"),
REMOVE_SHORTCUT(
browser,
"picture-in-picture-urlbar-button-close.tooltiptext",
),
),
],
),
],
)
browser_context = "browser/browser/browserContext.ftl"
ctx.add_transforms(
browser_context,
browser_context,
[
FTL.Message(
id=FTL.Identifier("main-context-menu-back-without-shortcut"),
attributes=[
FTL.Attribute(
FTL.Identifier("tooltiptext"),
REMOVE_SHORTCUT(
browser_context, "main-context-menu-back-3.tooltiptext"
),
),
FTL.Attribute(
FTL.Identifier("aria-label"),
COPY_PATTERN(
browser_context, "main-context-menu-back-3.aria-label"
),
),
],
),
FTL.Message(
id=FTL.Identifier("navbar-tooltip-back-without-shortcut"),
attributes=[
FTL.Attribute(
FTL.Identifier("value"),
REMOVE_SHORTCUT(browser_context, "navbar-tooltip-back-3.value"),
),
],
),
FTL.Message(
id=FTL.Identifier("main-context-menu-forward-without-shortcut"),
attributes=[
FTL.Attribute(
FTL.Identifier("tooltiptext"),
REMOVE_SHORTCUT(
browser_context, "main-context-menu-forward-3.tooltiptext"
),
),
FTL.Attribute(
FTL.Identifier("aria-label"),
COPY_PATTERN(
browser_context, "main-context-menu-forward-3.aria-label"
),
),
],
),
FTL.Message(
id=FTL.Identifier("navbar-tooltip-forward-without-shortcut"),
attributes=[
FTL.Attribute(
FTL.Identifier("value"),
REMOVE_SHORTCUT(
browser_context, "navbar-tooltip-forward-3.value"
),
),
],
),
],
)
screenshots = "browser/browser/screenshots.ftl"
ctx.add_transforms(
screenshots,
screenshots,
[
FTL.Message(
id=FTL.Identifier("screenshot-toolbar-button-without-shortcut"),
attributes=[
FTL.Attribute(
FTL.Identifier("label"),
COPY_PATTERN(screenshots, "screenshot-toolbar-button.label"),
),
FTL.Attribute(
FTL.Identifier("tooltiptext"),
REMOVE_SHORTCUT(
screenshots, "screenshot-toolbar-button.tooltiptext"
),
),
],
),
],
)
sidebar = "browser/browser/sidebar.ftl"
ctx.add_transforms(
sidebar,
sidebar,
[
FTL.Message(
id=FTL.Identifier("sidebar-widget-expand-sidebar-without-shortcut"),
attributes=[
FTL.Attribute(
FTL.Identifier("tooltiptext"),
REMOVE_SHORTCUT(
sidebar, "sidebar-widget-expand-sidebar2.tooltiptext"
),
),
FTL.Attribute(
FTL.Identifier("label"),
COPY_PATTERN(sidebar, "sidebar-widget-expand-sidebar2.label"),
),
],
),
FTL.Message(
id=FTL.Identifier("sidebar-widget-collapse-sidebar-without-shortcut"),
attributes=[
FTL.Attribute(
FTL.Identifier("tooltiptext"),
REMOVE_SHORTCUT(
sidebar, "sidebar-widget-collapse-sidebar2.tooltiptext"
),
),
FTL.Attribute(
FTL.Identifier("label"),
COPY_PATTERN(sidebar, "sidebar-widget-collapse-sidebar2.label"),
),
],
),
FTL.Message(
id=FTL.Identifier("sidebar-widget-show-sidebar-without-shortcut"),
attributes=[
FTL.Attribute(
FTL.Identifier("tooltiptext"),
REMOVE_SHORTCUT(
sidebar, "sidebar-widget-show-sidebar2.tooltiptext"
),
),
FTL.Attribute(
FTL.Identifier("label"),
COPY_PATTERN(sidebar, "sidebar-widget-show-sidebar2.label"),
),
],
),
FTL.Message(
id=FTL.Identifier("sidebar-widget-hide-sidebar-without-shortcut"),
attributes=[
FTL.Attribute(
FTL.Identifier("tooltiptext"),
REMOVE_SHORTCUT(
sidebar, "sidebar-widget-hide-sidebar2.tooltiptext"
),
),
FTL.Attribute(
FTL.Identifier("label"),
COPY_PATTERN(sidebar, "sidebar-widget-hide-sidebar2.label"),
),
],
),
],
)