# 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 COPY def platform_selector(mac_value, other_value): return FTL.Pattern( elements=[ FTL.Placeable( expression=FTL.SelectExpression( selector=FTL.FunctionReference( id=FTL.Identifier("PLATFORM"), arguments=FTL.CallArguments() ), variants=[ FTL.Variant(key=FTL.Identifier("macos"), value=mac_value), FTL.Variant( key=FTL.Identifier("other"), value=other_value, default=True, ), ], ) ) ] ) def migrate(ctx): """Bug 1733493 - Migrate keys.properties and platformKeys.properties to Fluent, part {index}.""" keys = "toolkit/chrome/global/keys.properties" mac = "toolkit/chrome/global-platform/mac/platformKeys.properties" win = "toolkit/chrome/global-platform/win/platformKeys.properties" target = "toolkit/toolkit/global/keys.ftl" def message(l10n_id, value): return FTL.Message(id=FTL.Identifier(l10n_id), value=value) platform_keys = [ ("keyboard-key-shift", "VK_SHIFT"), ("keyboard-key-command-or-win", "VK_COMMAND_OR_WIN"), ("keyboard-key-alt", "VK_ALT"), ("keyboard-key-control", "VK_CONTROL"), ] other_keys = [ ("keyboard-key-up", "VK_UP"), ("keyboard-key-down", "VK_DOWN"), ("keyboard-key-left", "VK_LEFT"), ("keyboard-key-right", "VK_RIGHT"), ("keyboard-key-page-up", "VK_PAGE_UP"), ("keyboard-key-page-down", "VK_PAGE_DOWN"), ("keyboard-key-home", "VK_HOME"), ("keyboard-key-end", "VK_END"), ("keyboard-key-tab", "VK_TAB"), ("keyboard-key-backspace", "VK_BACK"), ("keyboard-key-delete", "VK_DELETE"), ("keyboard-key-escape", "VK_ESCAPE"), ("keyboard-key-insert", "VK_INSERT"), ] ctx.add_transforms( target, target, [ message(l10n_id, platform_selector(COPY(mac, key), COPY(win, key))) for l10n_id, key in platform_keys ] + [message("keyboard-key-modifier-separator", COPY(win, "MODIFIER_SEPARATOR"))] + [message(l10n_id, COPY(keys, key)) for l10n_id, key in other_keys] + [ message( "keyboard-key-return", platform_selector(COPY(mac, "VK_RETURN"), COPY(win, "VK_RETURN")), ), ], )