Skip to content

Commit 9aaca5e

Browse files
author
Lukáš Horák
committed
♻️ Consider line without a translation empty
1 parent 9347e1a commit 9aaca5e

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

packages/lokse/src/core/__tests__/line.test.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,28 @@ describe("Line.getComment", () => {
2626
});
2727

2828
describe("Line.isEmpty", () => {
29-
const line1 = new Line(null, null);
29+
it("returns true if key is missing", () => {
30+
const line = new Line(null, 'Translation with missing key');
31+
32+
expect(line.isEmpty()).toEqual(true);
33+
expect(line.isComment()).toEqual(false);
34+
35+
});
36+
37+
it("returns true if translation is missing", () => {
38+
const line = new Line('missing.translation.key', null);
39+
40+
expect(line.isEmpty()).toEqual(true);
41+
expect(line.isComment()).toEqual(false);
3042

31-
expect(line1.isEmpty()).toEqual(true);
32-
expect(line1.isComment()).toEqual(false);
43+
});
44+
45+
it("returns true if both key and translation are missing", () => {
46+
const line = new Line(null, null);
47+
48+
expect(line.isEmpty()).toEqual(true);
49+
expect(line.isComment()).toEqual(false);
50+
});
3351
});
3452

3553
describe("Line", () => {

packages/lokse/src/core/line.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Line {
8686
}
8787

8888
isEmpty() {
89-
return !this.isComment() && !this.key;
89+
return !this.isComment() && !(this.key && this.value);
9090
}
9191

9292
isComment() {

packages/lokse/src/core/reader/__tests__/spreadsheet-reader.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ describe("SpreadsheetReader", () => {
122122
});
123123
});
124124

125-
it("should omit sheet in map lines when extracting from any fail", async () => {
125+
it("should omit sheet in map lines when extracting fail from any reason", async () => {
126126
expect.assertions(4);
127127

128128
const sheetsList = [

packages/lokse/src/core/writer.ts

+13-12
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class FileWriter {
2323

2424
fileContent = fileContent.toString();
2525
} catch {
26-
// file doesnt exist
26+
// file doesnt exist yet
2727
}
2828

2929
const valueToInsert = this.getTransformedLines(lines, transformer);
@@ -43,21 +43,22 @@ export class FileWriter {
4343
const line = lines[i];
4444
const isLastLine = i === lines.length - 1;
4545

46-
if (!line.isEmpty()) {
47-
if (line.isComment()) {
48-
valueToInsert += transformer.transformComment(line.getComment());
49-
} else if (line.isPlural()) {
50-
if (!plurals[line.key]) {
51-
plurals[line.key] = [];
52-
}
53-
plurals[line.key].push(line);
54-
} else {
55-
valueToInsert += transformer.transformKeyValue(line.key, line.value);
46+
if (line.isEmpty()) {
47+
continue;
48+
}
49+
50+
if (line.isComment()) {
51+
valueToInsert += transformer.transformComment(line.getComment());
52+
} else if (line.isPlural()) {
53+
if (!plurals[line.key]) {
54+
plurals[line.key] = [];
5655
}
56+
plurals[line.key].push(line);
57+
} else {
58+
valueToInsert += transformer.transformKeyValue(line.key, line.value);
5759
}
5860

5961
if (
60-
line.key !== "" &&
6162
!line.isPlural() &&
6263
(!isLastLine || Object.keys(plurals).length > 0)
6364
) {

0 commit comments

Comments
 (0)