| 1 |
# Any copyright is dedicated to the Public Domain. |
| 2 |
# http://creativecommons.org/publicdomain/zero/1.0/ |
| 3 |
|
| 4 |
import fluent.syntax.ast as FTL |
| 5 |
from fluent.migrate.helpers import VARIABLE_REFERENCE |
| 6 |
from fluent.migrate.transforms import COPY, REPLACE |
| 7 |
|
| 8 |
|
| 9 |
def migrate(ctx): |
| 10 |
"""Bug 1959147 - Migrate XSLT errors to Fluent, part {index}.""" |
| 11 |
|
| 12 |
xslt_source = "dom/chrome/xslt/xslt.properties" |
| 13 |
global_strres_source = "dom/chrome/global-strres.properties" |
| 14 |
target = "dom/dom/xslt.ftl" |
| 15 |
|
| 16 |
xslt_errors = { |
| 17 |
"xslt-parse-failure": "1", |
| 18 |
"xpath-parse-failure": "2", |
| 19 |
# 3 (NS_ERROR_XSLT_ALREADY_SET) is empty in xslt.properties. |
| 20 |
# It seems it is always replaced with NS_ERROR_XSLT_VAR_ALREADY_SET. |
| 21 |
"xslt-execution-failure": "4", |
| 22 |
"xpath-unknown-function": "5", |
| 23 |
"xslt-bad-recursion": "6", |
| 24 |
"xslt-bad-value": "7", |
| 25 |
"xslt-nodeset-expected": "8", |
| 26 |
"xslt-aborted": "9", |
| 27 |
"xslt-network-error": "10", |
| 28 |
"xslt-wrong-mime-type": "11", |
| 29 |
"xslt-load-recursion": "12", |
| 30 |
"xpath-bad-argument-count": "13", |
| 31 |
"xpath-bad-extension-function": "14", |
| 32 |
"xpath-paren-expected": "15", |
| 33 |
"xpath-invalid-axis": "16", |
| 34 |
"xpath-no-node-type-test": "17", |
| 35 |
"xpath-bracket-expected": "18", |
| 36 |
"xpath-invalid-var-name": "19", |
| 37 |
"xpath-unexpected-end": "20", |
| 38 |
"xpath-operator-expected": "21", |
| 39 |
"xpath-unclosed-literal": "22", |
| 40 |
"xpath-bad-colon": "23", |
| 41 |
"xpath-bad-bang": "24", |
| 42 |
"xpath-illegal-char": "25", |
| 43 |
"xpath-binary-expected": "26", |
| 44 |
"xslt-load-blocked-error": "27", |
| 45 |
"xpath-invalid-expression-evaluated": "28", |
| 46 |
"xpath-unbalanced-curly-brace": "29", |
| 47 |
"xslt-bad-node-name": "30", |
| 48 |
"xslt-var-already-set": "31", |
| 49 |
"xslt-call-to-key-not-allowed": "32", |
| 50 |
} |
| 51 |
ctx.add_transforms( |
| 52 |
target, |
| 53 |
target, |
| 54 |
[ |
| 55 |
FTL.Message(id=FTL.Identifier(ftl_id), value=COPY(xslt_source, prop_id)) |
| 56 |
for ftl_id, prop_id in xslt_errors.items() |
| 57 |
], |
| 58 |
) |
| 59 |
|
| 60 |
ctx.add_transforms( |
| 61 |
target, |
| 62 |
target, |
| 63 |
[ |
| 64 |
FTL.Message( |
| 65 |
id=FTL.Identifier("xslt-unknown-error"), |
| 66 |
value=REPLACE( |
| 67 |
global_strres_source, |
| 68 |
"16389", |
| 69 |
{"%1$S": VARIABLE_REFERENCE("errorCode")}, |
| 70 |
), |
| 71 |
), |
| 72 |
FTL.Message( |
| 73 |
id=FTL.Identifier("xslt-loading-error"), |
| 74 |
value=REPLACE( |
| 75 |
xslt_source, "LoadingError", {"%1$S": VARIABLE_REFERENCE("error")} |
| 76 |
), |
| 77 |
), |
| 78 |
FTL.Message( |
| 79 |
id=FTL.Identifier("xslt-transform-error"), |
| 80 |
value=REPLACE( |
| 81 |
xslt_source, "TransformError", {"%1$S": VARIABLE_REFERENCE("error")} |
| 82 |
), |
| 83 |
), |
| 84 |
], |
| 85 |
) |