1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
import fluent.syntax.ast as FTL
from fluent.migrate.helpers import transforms_from, VARIABLE_REFERENCE, TERM_REFERENCE
from fluent.migrate.transforms import (
CONCAT,
REPLACE,
REPLACE_IN_TEXT,
LegacySource,
Transform,
)
class SPLIT_AND_REPLACE(LegacySource):
"""Split sentence on '\n\n', return a specific segment, and perform replacements if needed"""
def __init__(self, path, key, index, replacements=None, **kwargs):
super(SPLIT_AND_REPLACE, self).__init__(path, key, **kwargs)
self.index = index
self.replacements = replacements
def __call__(self, ctx):
element = super(SPLIT_AND_REPLACE, self).__call__(ctx)
segments = element.value.split(r"\n\n")
element.value = segments[self.index]
if self.replacements is None:
return Transform.pattern_of(element)
else:
return REPLACE_IN_TEXT(element, self.replacements)(ctx)
def migrate(ctx):
"""Bug 1759175 - Migrate Crash Reporter to Fluent, part {index}."""
target_file = "toolkit/crashreporter/crashreporter.ftl"
source_file = "toolkit/crashreporter/crashreporter.ini"
ctx.add_transforms(
target_file,
target_file,
transforms_from(
"""
crashreporter-title = { COPY(from_path, "CrashReporterTitle") }
crashreporter-no-run-message = { COPY(from_path, "CrashReporterDefault") }
crashreporter-button-details = { COPY(from_path, "Details") }
crashreporter-view-report-title = { COPY(from_path, "ViewReportTitle") }
crashreporter-comment-prompt = { COPY(from_path, "CommentGrayText") }
crashreporter-report-info = { COPY(from_path, "ExtraReportInfo") }
crashreporter-submit-status = { COPY(from_path, "ReportPreSubmit2") }
crashreporter-submit-in-progress = { COPY(from_path, "ReportDuringSubmit2") }
crashreporter-submit-success = { COPY(from_path, "ReportSubmitSuccess") }
crashreporter-submit-failure = { COPY(from_path, "ReportSubmitFailed") }
crashreporter-resubmit-status = { COPY(from_path, "ReportResubmit") }
crashreporter-button-ok = { COPY(from_path, "Ok") }
crashreporter-button-close = { COPY(from_path, "Close") }
""",
from_path=source_file,
),
)
ctx.add_transforms(
target_file,
target_file,
[
FTL.Message(
id=FTL.Identifier("crashreporter-crash-message"),
value=SPLIT_AND_REPLACE(
source_file,
"CrashReporterDescriptionText2",
index=0,
replacements={
"%s": TERM_REFERENCE("brand-short-name"),
},
),
),
FTL.Message(
id=FTL.Identifier("crashreporter-plea"),
value=SPLIT_AND_REPLACE(
source_file,
"CrashReporterDescriptionText2",
index=1,
),
),
FTL.Message(
id=FTL.Identifier("crashreporter-error-details"),
value=SPLIT_AND_REPLACE(
source_file,
"CrashReporterProductErrorText2",
index=2,
replacements={
"%s": VARIABLE_REFERENCE("details"),
},
),
),
FTL.Message(
id=FTL.Identifier("crashreporter-button-quit"),
value=REPLACE(
source_file,
"Quit2",
{
"%s": TERM_REFERENCE("brand-short-name"),
},
),
),
FTL.Message(
id=FTL.Identifier("crashreporter-button-restart"),
value=REPLACE(
source_file,
"Restart",
{
"%s": TERM_REFERENCE("brand-short-name"),
},
),
),
FTL.Message(
id=FTL.Identifier("crashreporter-crash-identifier"),
value=REPLACE(
source_file,
"CrashID",
{
"%s": VARIABLE_REFERENCE("id"),
},
),
),
],
)
|