Commit 0ffa7f8b authored by henry's avatar henry Committed by Pier Angelo Vendrame
Browse files

Tor Browser localization migration scripts.

parent df7087f8
Loading
Loading
Loading
Loading
+672 −0

File added.

Preview size limit exceeded, changes collapsed.

+0 −0

Empty file added.

+24 −0
Original line number Diff line number Diff line
from fluent.migrate.helpers import transforms_from


def migrate(ctx):
    ctx.add_transforms(
        "tor-browser.ftl",
        "tor-browser.ftl",
        transforms_from(
            """
menu-open-tor-manual =
    .label = { COPY(path, "aboutTor.torbrowser_user_manual.label") }
    .accesskey = { COPY(path, "aboutTor.torbrowser_user_manual.accesskey") }

tor-browser-home-heading-stable = { COPY(path, "aboutTor.ready.label") }
tor-browser-home-heading-testing = { COPY(path, "aboutTor.alpha.ready.label") }

tor-browser-home-duck-duck-go-input =
    .placeholder = { COPY(path, "aboutTor.search.label") }

tor-browser-home-message-introduction = { COPY(path, "aboutTor.ready2.label") }
""",
            path="aboutTor.dtd",
        ),
    )
+21 −0
Original line number Diff line number Diff line
from fluent.migrate.helpers import transforms_from


def migrate(ctx):
    ctx.add_transforms(
        "tor-browser.ftl",
        "tor-browser.ftl",
        transforms_from(
            """
onion-neterror-not-found-description = { COPY(path, "onionServices.descNotFound") }
onion-neterror-unreachable-description = { COPY(path, "onionServices.descInvalid") }
onion-neterror-disconnected-description = { COPY(path, "onionServices.introFailed") }
onion-neterror-connection-failed-description = { COPY(path, "onionServices.rendezvousFailed") }
onion-neterror-missing-authentication-description = { COPY(path, "onionServices.clientAuthMissing") }
onion-neterror-incorrect-authetication-description = { COPY(path, "onionServices.clientAuthIncorrect") }
onion-neterror-invalid-address-description = { COPY(path, "onionServices.badAddress") }
onion-neterror-timed-out-description = { COPY(path, "onionServices.introTimedOut") }
""",
            path="torbutton.properties",
        ),
    )
+67 −0
Original line number Diff line number Diff line
import re

import fluent.syntax.ast as FTL
from fluent.migrate.transforms import COPY_PATTERN, FluentSource
from fluent.syntax.visitor import Visitor


class RemoveAnchorVisitor(Visitor):
    """Class to remove <a> and </a> wrappers from a Fluent TextElement."""

    def __init__(self):
        # Good enough regex for our needs that will match starting and ending
        # tags.
        self._anchor_regex = re.compile(r"<\/?[aA](| [^>]*)>")
        super().__init__()

    def visit_TextElement(self, node):
        node.value = self._anchor_regex.sub("", node.value)


class RemoveAnchorTransform(FluentSource):
    """Class to remove <a> and </a> wrappers from a Fluent source."""

    def __call__(self, ctx):
        pattern = ctx.get_fluent_source_pattern(self.path, self.key).clone()
        # Visit every node in the pattern, replacing each TextElement's content.
        RemoveAnchorVisitor().visit(pattern)
        return pattern


def migrate(ctx):
    # Convert
    #
    # downloads-tor-warning-title = A
    # downloads-tor-warning-description = B<a data-l10n-name="tails-link">C</a>D
    #
    # to
    #
    # downloads-tor-warning-message-bar =
    #   .heading = A
    #   .message = BCD
    ctx.add_transforms(
        "tor-browser.ftl",
        "tor-browser.ftl",
        [
            FTL.Message(
                id=FTL.Identifier("downloads-tor-warning-message-bar"),
                value=None,
                attributes=[
                    FTL.Attribute(
                        id=FTL.Identifier("heading"),
                        value=COPY_PATTERN(
                            "tor-browser.ftl",
                            "downloads-tor-warning-title",
                        ),
                    ),
                    FTL.Attribute(
                        id=FTL.Identifier("message"),
                        value=RemoveAnchorTransform(
                            "tor-browser.ftl",
                            "downloads-tor-warning-description",
                        ),
                    ),
                ],
            ),
        ],
    )
Loading