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 TransformPattern
class STRIP_TRAILING_STOP(TransformPattern):
"""Drop a trailing full stop (Latin, ideographic or danda) or exclamation mark from each pattern."""
def visit_Pattern(self, node):
node = super().visit_Pattern(node)
if node.elements and isinstance(node.elements[-1], FTL.TextElement):
last = node.elements[-1]
last.value = re.sub(r"[.。।!]$", "", last.value)
return node
def migrate(ctx):
path = "browser/browser/newtab/onboarding.ftl"
ctx.add_transforms(
path,
path,
[
FTL.Message(
id=FTL.Identifier("hnt-card-mobile-primary-button2"),
value=STRIP_TRAILING_STOP(path, "hnt-card-mobile-primary-button"),
),
],
)