Skip to content

Commit d31f9fc

Browse files
authored
fix(xcstrings): ordering of keys to match that of Xcode (#461)
1 parent 33d6849 commit d31f9fc

5 files changed

Lines changed: 107 additions & 6 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"lingo.dev": patch
3+
---
4+
5+
ordering of keys in xcstrings file to match that of Xcode

packages/cli/src/cli/cmd/i18n.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ export default new Command()
101101
for (const bucket of buckets) {
102102
cacheOra.info(`Processing bucket: ${bucket.type}`);
103103
for (const bucketConfig of bucket.config) {
104-
const bucketOra = ora.info(`Processing path: ${bucketConfig.pathPattern}`);
104+
const bucketOra = Ora({ indent: 4 });
105+
bucketOra.info(`Processing path: ${bucketConfig.pathPattern}`);
105106

106107
const sourceLocale = resolveOverridenLocale(i18nConfig!.locale.source, bucketConfig.delimiter);
107108
const bucketLoader = createBucketLoader(bucket.type, bucketConfig.pathPattern);
@@ -228,12 +229,12 @@ export default new Command()
228229

229230
const progressLog = `[${sourceLocale} -> ${targetLocale}] [${Object.keys(processableData).length} entries] (${progress}%) AI localization in progress...`;
230231
if (flags.verbose) {
231-
ora.info(progressLog);
232-
ora.info(
233-
`Caching chunk ${JSON.stringify(sourceChunk, null, 2)} -> ${JSON.stringify(processedChunk, null, 2)}`,
232+
bucketOra.info(progressLog);
233+
bucketOra.info(
234+
`(${progress}%) Caching chunk ${JSON.stringify(sourceChunk, null, 2)} -> ${JSON.stringify(processedChunk, null, 2)}`,
234235
);
235236
} else {
236-
ora.text = progressLog;
237+
bucketOra.text = progressLog;
237238
}
238239
},
239240
);

packages/cli/src/cli/loaders/index.spec.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,28 @@ user.password=Contraseña
782782
},
783783
}
784784
},
785+
"2a" : {
786+
"extractionState" : "manual",
787+
"localizations" : {
788+
"en" : {
789+
"stringUnit" : {
790+
"state" : "translated",
791+
"value" : "2a"
792+
}
793+
}
794+
}
795+
},
796+
"3x" : {
797+
"extractionState" : "manual",
798+
"localizations" : {
799+
"en" : {
800+
"stringUnit" : {
801+
"state" : "translated",
802+
"value" : "3x"
803+
}
804+
}
805+
}
806+
},
785807
"25" : {
786808
"extractionState" : "manual",
787809
"localizations" : {
@@ -842,6 +864,40 @@ user.password=Contraseña
842864
}
843865
}
844866
},
867+
"2a" : {
868+
"extractionState" : "manual",
869+
"localizations" : {
870+
"ar" : {
871+
"stringUnit" : {
872+
"state" : "translated",
873+
"value" : "2a"
874+
}
875+
},
876+
"en" : {
877+
"stringUnit" : {
878+
"state" : "translated",
879+
"value" : "2a"
880+
}
881+
}
882+
}
883+
},
884+
"3x" : {
885+
"extractionState" : "manual",
886+
"localizations" : {
887+
"ar" : {
888+
"stringUnit" : {
889+
"state" : "translated",
890+
"value" : "3x"
891+
}
892+
},
893+
"en" : {
894+
"stringUnit" : {
895+
"state" : "translated",
896+
"value" : "3x"
897+
}
898+
}
899+
}
900+
},
845901
"25" : {
846902
"extractionState" : "manual",
847903
"localizations" : {

packages/cli/src/cli/utils/plutil-formatter.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,43 @@ describe("plutil-formatter", () => {
100100
const result = formatPlutilStyle(input);
101101
expect(result).toBe(expected);
102102
});
103+
104+
it("should order keys correctly", () => {
105+
const input = {
106+
"2x": {},
107+
"3ABC": {},
108+
"3x": {},
109+
"4K": {},
110+
"7 min": {},
111+
"25": {},
112+
"30": {},
113+
};
114+
115+
const expected = `{
116+
"2x" : {
117+
118+
},
119+
"3ABC" : {
120+
121+
},
122+
"3x" : {
123+
124+
},
125+
"4K" : {
126+
127+
},
128+
"7 min" : {
129+
130+
},
131+
"25" : {
132+
133+
},
134+
"30" : {
135+
136+
}
137+
}`;
138+
139+
const result = formatPlutilStyle(input);
140+
expect(result).toBe(expected);
141+
});
103142
});

packages/cli/src/cli/utils/plutil-formatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function formatPlutilStyle(jsonData: any, existingJson?: string): string
2929

3030
if (aIsWhitespace && !bIsWhitespace) return -1;
3131
if (!aIsWhitespace && bIsWhitespace) return 1;
32-
return a.localeCompare(b, undefined, { numeric: false });
32+
return a.localeCompare(b, undefined, { numeric: true });
3333
});
3434

3535
const items = sortedKeys.map((key) => {

0 commit comments

Comments
 (0)