# Any copyright is dedicated to the Public Domain. # http://creativecommons.org/publicdomain/zero/1.0/ import fluent.syntax.ast as FTL from fluent.migrate.transforms import TransformPattern class FIX_NUMBER_OPTION(TransformPattern): """Reuse the existing translation, replacing the invalid NUMBER() option maxFractionalUnits with maximumFractionDigits.""" def visit_NamedArgument(self, node): node = self.generic_visit(node) if node.name.name == "maxFractionalUnits": node.name = FTL.Identifier("maximumFractionDigits") return node class FIX_DATETIME_OPTION(TransformPattern): """Reuse the existing translation, replacing the invalid DATETIME() option hour12 with hourCycle.""" def visit_NamedArgument(self, node): node = self.generic_visit(node) if node.name.name == "hour12": node.name = FTL.Identifier("hourCycle") node.value = FTL.StringLiteral( "h12" if getattr(node.value, "value", "") == "true" else "h23" ) return node def migrate(ctx): """Bug 2101482 - Replace invalid NUMBER() and DATETIME() options, part {index}.""" path = "devtools/client/perftools.ftl" ids = ["perftools-range-interval-milliseconds"] + [ f"perftools-memory-unit-{unit}" for unit in ["b", "kib", "mib", "gib", "tib", "pib", "eib", "zib", "yib"] ] ctx.add_transforms( path, path, [ FTL.Message( id=FTL.Identifier(f"{l10n_id}2"), value=FIX_NUMBER_OPTION(path, l10n_id), ) for l10n_id in ids ], ) path = "browser/browser/aboutUnloads.ftl" ctx.add_transforms( path, path, [ FTL.Message( id=FTL.Identifier("about-unloads-memory-in-mb2"), value=FIX_NUMBER_OPTION(path, "about-unloads-memory-in-mb"), ), FTL.Message( id=FTL.Identifier("about-unloads-memory-in-mb-tooltip2"), attributes=[ FTL.Attribute( FTL.Identifier("title"), FIX_NUMBER_OPTION( path, "about-unloads-memory-in-mb-tooltip.title" ), ) ], ), ] + [ FTL.Message( id=FTL.Identifier(f"{l10n_id}2"), value=FIX_DATETIME_OPTION(path, l10n_id), ) for l10n_id in [ "about-unloads-last-updated", "about-unloads-last-accessed", ] ], )