Skip to content

Commit 4d2e620

Browse files
authored
Fix lf checks in gulpfile to grab missing translations (microsoft#8286)
* fix format for lfs in a few spots * add folders contain lfs that were being missed * include other folders that have lf in this in buildstrings, add escape for skipping lf extraction and off by one fix for line numbers (0 vs 1 indexed) * add to gulpfile processLf for consistency
1 parent cf52039 commit 4d2e620

7 files changed

Lines changed: 42 additions & 24 deletions

File tree

cli/cli.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,8 +1730,12 @@ function processLf(filename: string, translationStrings: pxt.Map<string>): void
17301730
fs.readFileSync(filename, { encoding: "utf8" })
17311731
.split('\n').forEach((line, idx) => {
17321732
function err(msg: string) {
1733-
console.error(`${filename}(${idx}): ${msg}`);
1733+
console.error(`${filename}(${idx + 1}): ${msg}`);
17341734
}
1735+
1736+
if (/@ignorelf@/.test(line))
1737+
return;
1738+
17351739
while (true) {
17361740
const newLine = line.replace(/\blf(_va)?\s*\(\s*(.*)/, (all, a, args) => {
17371741
const m = /^("([^"]|(\\"))+")\s*[\),]/.exec(args)
@@ -1744,7 +1748,7 @@ function processLf(filename: string, translationStrings: pxt.Map<string>): void
17441748
}
17451749
} else {
17461750
if (!/util\.ts$/.test(filename))
1747-
err("invalid format of lf() argument: " + args)
1751+
err("invalid format of lf() argument: " + args) // @ignorelf@
17481752
}
17491753
return "BLAH " + args
17501754
})
@@ -3025,7 +3029,7 @@ function installPackageNameAsync(packageName: string): Promise<void> {
30253029
return addDepAsync(sharedId, packageName, false);
30263030

30273031
// don't know
3028-
U.userError(lf(`unknown package ${packageName}`))
3032+
U.userError(lf("unknown package {0}", packageName))
30293033
return Promise.resolve();
30303034
}
30313035

@@ -6108,10 +6112,13 @@ function extractLocStringsAsync(output: string, dirs: string[]): Promise<void> {
61086112
pxt.debug(`extracting strings from${filename}`);
61096113
fs.readFileSync(filename, "utf8").split('\n').forEach((line: string, idx: number) => {
61106114
function err(msg: string) {
6111-
console.log("%s(%d): %s", filename, idx, msg);
6115+
console.log("%s(%d): %s", filename, idx + 1, msg);
61126116
errCnt++;
61136117
}
61146118

6119+
if (/@ignorelf@/.test(line))
6120+
return;
6121+
61156122
while (true) {
61166123
let newLine = line.replace(/\blf(_va)?\s*\(\s*(.*)/, (all, a, args) => {
61176124
let m = /^("([^"]|(\\"))+")\s*[\),]/.exec(args)
@@ -6124,7 +6131,7 @@ function extractLocStringsAsync(output: string, dirs: string[]): Promise<void> {
61246131
}
61256132
} else {
61266133
if (!/util\.ts$/.test(filename))
6127-
err("invalid format of lf() argument: " + args)
6134+
err("invalid format of lf() argument: " + args) // @ignorelf@
61286135
}
61296136
return "BLAH " + args
61306137
})

gulpfile.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,16 @@ function pxtcommon() {
214214

215215
// TODO: Copied from Jakefile; should be async
216216
function updatestrings() {
217-
return buildStrings("built/strings.json", ["pxtlib", "pxtblocks", "pxtblocks/fields", "webapp/src"]);
217+
return buildStrings("built/strings.json", [
218+
"cli",
219+
"pxtblocks",
220+
"pxtcompiler",
221+
"pxteditor",
222+
"pxtlib",
223+
"pxtpy",
224+
"pxtsim",
225+
"webapp/src",
226+
], true);
218227
}
219228

220229
function updateSkillMapStrings() {
@@ -231,13 +240,16 @@ function buildStrings(out, rootPaths, recursive) {
231240
if (!/\.(ts|tsx|html)$/.test(filename)) return
232241
if (/\.d\.ts$/.test(filename)) return
233242

234-
//console.log('extracting strings from %s', filename);
243+
// console.log(`extracting strings from ${filename}`);
235244
fs.readFileSync(filename, "utf8").split('\n').forEach((line, idx) => {
236245
function err(msg) {
237-
console.log("%s(%d): %s", filename, idx, msg);
246+
console.log("%s(%d): %s", filename, idx + 1, msg);
238247
errCnt++;
239248
}
240249

250+
if (/@ignorelf@/.test(line))
251+
return;
252+
241253
while (true) {
242254
let newLine = line.replace(/\blf(_va)?\s*\(\s*(.*)/, (all, a, args) => {
243255
let m = /^("([^"]|(\\"))+")\s*[\),]/.exec(args)
@@ -249,8 +261,7 @@ function buildStrings(out, rootPaths, recursive) {
249261
err("cannot JSON-parse " + m[1])
250262
}
251263
} else {
252-
if (!/util\.ts$/.test(filename))
253-
err("invalid format of lf() argument: " + args)
264+
err("invalid format of lf() argument: " + args) // @ignorelf@
254265
}
255266
return "BLAH " + args
256267
})

pxtlib/commonutil.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ namespace ts.pxtc.Util {
190190
}
191191

192192
let sForPlural = true;
193-
export function lf_va(format: string, args: any[]): string {
193+
export function lf_va(format: string, args: any[]): string { // @ignorelf@
194194
if (!format) return format;
195195

196196
locStats[format] = (locStats[format] || 0) + 1;
@@ -205,14 +205,14 @@ namespace ts.pxtc.Util {
205205
return fmt_va(lfmt, args);
206206
}
207207

208-
export function lf(format: string, ...args: any[]): string {
209-
return lf_va(format, args);
208+
export function lf(format: string, ...args: any[]): string { // @ignorelf@
209+
return lf_va(format, args); // @ignorelf@
210210
}
211211
/**
212212
* Similar to lf but the string do not get extracted into the loc file.
213213
*/
214214
export function rlf(format: string, ...args: any[]): string {
215-
return lf_va(format, args);
215+
return lf_va(format, args); // @ignorelf@
216216
}
217217

218218
export function lookup<T>(m: pxt.Map<T>, key: string): T {

pxtlib/emitter/assembler.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace ts.pxtc.assembler {
2525
labelName?: string;
2626
}
2727

28-
export function lf(fmt: string, ...args: any[]) {
28+
export function lf(fmt: string, ...args: any[]) { // @ignorelf@
2929
return fmt.replace(/{(\d+)}/g, (match, index) => args[+index]);
3030
}
3131

@@ -100,7 +100,7 @@ namespace ts.pxtc.assembler {
100100
stack = (v / this.ei.wordSize());
101101
}
102102
} else if (enc.isRegList) {
103-
// register lists are ARM-specific - this code not used in AVR
103+
// register lists are ARM-specific - this code not used in AVR
104104
if (actual != "{") return emitErr("expecting {", actual);
105105
v = 0;
106106
while (tokens[j] != "}") {
@@ -133,7 +133,7 @@ namespace ts.pxtc.assembler {
133133
if (ln.bin.finalEmit)
134134
return emitErr("unknown label", actual)
135135
else
136-
// just need some value when we are
136+
// just need some value when we are
137137
// doing some pass other than finalEmit
138138
v = 8; // needs to be divisible by 4 etc
139139
}
@@ -187,7 +187,7 @@ namespace ts.pxtc.assembler {
187187
export class Line {
188188
public type: string;
189189
public lineNo: number;
190-
public words: string[]; // the tokens in this line
190+
public words: string[]; // the tokens in this line
191191
public scope: string;
192192
public location: number;
193193
public instruction: Instruction;
@@ -285,7 +285,7 @@ namespace ts.pxtc.assembler {
285285
return this.location() + this.baseOffset;
286286
}
287287

288-
// parsing of an "integer", well actually much more than
288+
// parsing of an "integer", well actually much more than
289289
// just that
290290
public parseOneInt(s: string): number {
291291
if (!s)
@@ -1113,7 +1113,7 @@ namespace ts.pxtc.assembler {
11131113
export interface Encoder {
11141114
name: string;
11151115
pretty: string;
1116-
// given a value, check it is the right number of bits and
1116+
// given a value, check it is the right number of bits and
11171117
// translate the value to the proper set of bits
11181118
encode: (v: number) => number;
11191119
isRegister: boolean;
@@ -1288,7 +1288,7 @@ namespace ts.pxtc.assembler {
12881288
function parseString(s: string) {
12891289
s = s.replace(/\\\\/g, "\\B") // don't get confused by double backslash
12901290
.replace(/\\(['\?])/g, (f, q) => q) // these are not valid in JSON yet valid in C
1291-
.replace(/\\[z0]/g, "\u0000") // \0 is valid in C
1291+
.replace(/\\[z0]/g, "\u0000") // \0 is valid in C
12921292
.replace(/\\x([0-9a-f][0-9a-f])/gi, (f, h) => "\\u00" + h)
12931293
.replace(/\\B/g, "\\\\") // undo anti-confusion above
12941294
try {

pxtpy/converter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2139,7 +2139,7 @@ namespace pxt.py {
21392139
}
21402140

21412141
if (!fun) {
2142-
error(n, 9508, U.lf(`can't find called function "${nm}"`))
2142+
error(n, 9508, U.lf("can't find called function '{0}'", nm))
21432143
}
21442144

21452145
let formals = fun ? fun.parameters : null

pxtsim/localization.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace pxsim.localization {
77
}
88

99
let sForPlural = true;
10-
export function lf(s: string, ...args: any[]): string {
10+
export function lf(s: string, ...args: any[]): string { // @ignorelf@
1111
let lfmt = _localizeStrings[s] || s;
1212

1313
if (!sForPlural && lfmt != s && /\d:s\}/.test(lfmt)) {

webapp/src/dialogs.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ export function showWinAppDeprecateAsync() {
699699
jsx: <div>
700700
<img className="ui medium centered image" src={pxt.appTarget.appTheme.winAppDeprImage} alt={lf("An image of a shrugging board")}/>
701701
<div>
702-
{lf(`This app is being deprecated. Text editing is only available on the MakeCode website `)}
702+
{lf("This app is being deprecated. Text editing is only available on the MakeCode website ")}
703703
{`(https://${pxt.appTarget.name}).`}
704704
</div>
705705
</div>

0 commit comments

Comments
 (0)