diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /python/l10n/fluent_migrations/bug_1828767_sanitize_dialog_native_size.py | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'python/l10n/fluent_migrations/bug_1828767_sanitize_dialog_native_size.py')
-rw-r--r-- | python/l10n/fluent_migrations/bug_1828767_sanitize_dialog_native_size.py | 77 |
1 files changed, 77 insertions, 0 deletions
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", + ), + ], + ) |