From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../bug_1828767_sanitize_dialog_native_size.py | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 python/l10n/fluent_migrations/bug_1828767_sanitize_dialog_native_size.py (limited to 'python/l10n/fluent_migrations/bug_1828767_sanitize_dialog_native_size.py') diff --git a/python/l10n/fluent_migrations/bug_1828767_sanitize_dialog_native_size.py b/python/l10n/fluent_migrations/bug_1828767_sanitize_dialog_native_size.py new file mode 100644 index 0000000000..9d311c3fae --- /dev/null +++ b/python/l10n/fluent_migrations/bug_1828767_sanitize_dialog_native_size.py @@ -0,0 +1,77 @@ +from fluent.migrate import COPY_PATTERN +from fluent.migrate.transforms import TransformPattern, REPLACE_IN_TEXT +from fluent.migrate.helpers import MESSAGE_REFERENCE +import fluent.syntax.ast as FTL + +# Any copyright is dedicated to the Public Domain. +# http://creativecommons.org/publicdomain/zero/1.0/ + + +class REPLACE_PATTERN(TransformPattern): + """Hacky custom transform that works.""" + + def __init__(self, ctx, path, key, replacements, **kwargs): + super(REPLACE_PATTERN, self).__init__(path, key, **kwargs) + self.ctx = ctx + self.replacements = replacements + + def visit_Pattern(self, source): + source = self.generic_visit(source) + target = FTL.Pattern([]) + for element in source.elements: + if isinstance(element, FTL.TextElement): + pattern = REPLACE_IN_TEXT(element, self.replacements)(self.ctx) + target.elements += pattern.elements + else: + target.elements += [element] + return target + + +def replace_with_min_size_transform(ctx, file, identifier, to_identifier=None): + if to_identifier is None: + to_identifier = identifier + "2" + attributes = [ + FTL.Attribute( + id=FTL.Identifier("title"), + value=COPY_PATTERN(file, "{}.title".format(identifier)), + ), + FTL.Attribute( + id=FTL.Identifier("style"), + value=REPLACE_PATTERN( + ctx, + file, + "{}.style".format(identifier), + { + "width:": FTL.TextElement("min-width:"), + "height:": FTL.TextElement("min-height:"), + }, + ), + ), + ] + + return FTL.Message( + id=FTL.Identifier(to_identifier), + attributes=attributes, + ) + + +def migrate(ctx): + """Bug 1828767 - Migrate sanitize dialog to use min-width, part {index}.""" + ctx.add_transforms( + "browser/browser/sanitize.ftl", + "browser/browser/sanitize.ftl", + [ + replace_with_min_size_transform( + ctx, + "browser/browser/sanitize.ftl", + "dialog-title", + "sanitize-dialog-title", + ), + replace_with_min_size_transform( + ctx, + "browser/browser/sanitize.ftl", + "dialog-title-everything", + "sanitize-dialog-title-everything", + ), + ], + ) -- cgit v1.2.3