Skip to content

Commit

Permalink
fix(xcstrings): ordering of keys to match that of Xcode
Browse files Browse the repository at this point in the history
  • Loading branch information
mathio committed Feb 12, 2025
1 parent 33d6849 commit 256c08c
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 6 deletions.
11 changes: 6 additions & 5 deletions packages/cli/src/cli/cmd/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export default new Command()
for (const bucket of buckets) {
cacheOra.info(`Processing bucket: ${bucket.type}`);
for (const bucketConfig of bucket.config) {
const bucketOra = ora.info(`Processing path: ${bucketConfig.pathPattern}`);
const bucketOra = Ora({ indent: 4 });
bucketOra.info(`Processing path: ${bucketConfig.pathPattern}`);

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

const progressLog = `[${sourceLocale} -> ${targetLocale}] [${Object.keys(processableData).length} entries] (${progress}%) AI localization in progress...`;
if (flags.verbose) {
ora.info(progressLog);
ora.info(
`Caching chunk ${JSON.stringify(sourceChunk, null, 2)} -> ${JSON.stringify(processedChunk, null, 2)}`,
bucketOra.info(progressLog);
bucketOra.info(
`(${progress}%) Caching chunk ${JSON.stringify(sourceChunk, null, 2)} -> ${JSON.stringify(processedChunk, null, 2)}`,
);
} else {
ora.text = progressLog;
bucketOra.text = progressLog;
}
},
);
Expand Down
56 changes: 56 additions & 0 deletions packages/cli/src/cli/loaders/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,28 @@ user.password=Contraseña
},
}
},
"2a" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "2a"
}
}
}
},
"3x" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "3x"
}
}
}
},
"25" : {
"extractionState" : "manual",
"localizations" : {
Expand Down Expand Up @@ -842,6 +864,40 @@ user.password=Contraseña
}
}
},
"2a" : {
"extractionState" : "manual",
"localizations" : {
"ar" : {
"stringUnit" : {
"state" : "translated",
"value" : "2a"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "2a"
}
}
}
},
"3x" : {
"extractionState" : "manual",
"localizations" : {
"ar" : {
"stringUnit" : {
"state" : "translated",
"value" : "3x"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "3x"
}
}
}
},
"25" : {
"extractionState" : "manual",
"localizations" : {
Expand Down
39 changes: 39 additions & 0 deletions packages/cli/src/cli/utils/plutil-formatter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,43 @@ describe("plutil-formatter", () => {
const result = formatPlutilStyle(input);
expect(result).toBe(expected);
});

it("should order keys correctly", () => {
const input = {
"2x": {},
"3ABC": {},
"3x": {},
"4K": {},
"7 min": {},
"25": {},
"30": {},
};

const expected = `{
"2x" : {
},
"3ABC" : {
},
"3x" : {
},
"4K" : {
},
"7 min" : {
},
"25" : {
},
"30" : {
}
}`;

const result = formatPlutilStyle(input);
expect(result).toBe(expected);
});
});
2 changes: 1 addition & 1 deletion packages/cli/src/cli/utils/plutil-formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function formatPlutilStyle(jsonData: any, existingJson?: string): string

if (aIsWhitespace && !bIsWhitespace) return -1;
if (!aIsWhitespace && bIsWhitespace) return 1;
return a.localeCompare(b, undefined, { numeric: false });
return a.localeCompare(b, undefined, { numeric: true });
});

const items = sortedKeys.map((key) => {
Expand Down

0 comments on commit 256c08c

Please sign in to comment.