# Any copyright is dedicated to the Public Domain. # http://creativecommons.org/publicdomain/zero/1.0/ import re import fluent.syntax.ast as FTL from fluent.migrate.transforms import TransformPattern ICON_RE = re.compile(r'(\s*)]*data-l10n-name\s*=\s*"icon"[^>]*>(\s*)') def _replace_icon(match): before, after = match.groups() if before: return before start = match.start() if after and start > 0 and match.string[start - 1].isalnum(): return after return "" class STRIP_ICON(TransformPattern): """Drop the element, keeping the whitespace before it, or the whitespace after it if the element follows a word.""" def visit_TextElement(self, node): node.value = ICON_RE.sub(_replace_icon, node.value) return node def visit_Pattern(self, node): node = self.generic_visit(node) elements = node.elements if elements and isinstance(elements[0], FTL.TextElement): elements[0].value = elements[0].value.lstrip() if elements and isinstance(elements[-1], FTL.TextElement): elements[-1].value = elements[-1].value.rstrip() return self.pattern_of(*elements) def migrate(ctx): """Bug 2034567 - Add extension-controlled strings without the icon for Settings, part {index}.""" path = "browser/browser/preferences/preferences.ftl" ctx.add_transforms( path, path, [ FTL.Message( id=FTL.Identifier(f"extension-controlling-{name}-noicon"), value=STRIP_ICON(path, f"extension-controlling-{name}"), ) for name in ( "password-saving", "privacy-containers", "websites-content-blocking-all-trackers", "proxy-config", "doh", ) ], )