Skip to content

Commit acb8859

Browse files
committed
feat: shoudTranslate
1 parent 40137d0 commit acb8859

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,7 @@ user.password=Contraseña
10701070
it("should respect shouldTranslate: false flag", async () => {
10711071
setupFileMocks();
10721072

1073+
// Create input with a key that has shouldTranslate: false
10731074
const input = `{
10741075
"sourceLanguage": "en",
10751076
"strings": {
@@ -1103,11 +1104,13 @@ user.password=Contraseña
11031104
const xcodeXcstringsLoader = createBucketLoader("xcode-xcstrings", "i18n/[locale].xcstrings", { isCacheRestore: false, defaultLocale: "en" });
11041105
xcodeXcstringsLoader.setDefaultLocale("en");
11051106

1107+
// Pull data and verify that the shouldTranslate: false entry is skipped
11061108
const data = await xcodeXcstringsLoader.pull("en");
11071109

11081110
expect(data).toHaveProperty("normal_key", "This should be translated");
11091111
expect(data).not.toHaveProperty("do_not_translate");
11101112

1113+
// Now push a translation for the normal key
11111114
const payload = {
11121115
"normal_key": "Ceci devrait être traduit"
11131116
};
@@ -1118,15 +1121,22 @@ user.password=Contraseña
11181121
const writeFileCall = (fs.writeFile as any).mock.calls[0];
11191122
const writtenContent = JSON.parse(writeFileCall[1]);
11201123

1124+
// Verify that the normal key was translated
11211125
expect(writtenContent.strings.normal_key.localizations.fr.stringUnit.value).toBe("Ceci devrait être traduit");
1126+
1127+
// Verify that the do_not_translate key was preserved with its shouldTranslate: false flag
11221128
expect(writtenContent.strings.do_not_translate).toHaveProperty("shouldTranslate", false);
1129+
1130+
// Check that the do_not_translate key has no localizations for the target language
11231131
expect(writtenContent.strings.do_not_translate.localizations).not.toHaveProperty("fr");
11241132

1133+
// Now also test pushing with empty {} content to verify the flag is still preserved
11251134
await xcodeXcstringsLoader.push("fr", {});
11261135

11271136
const secondWriteFileCall = (fs.writeFile as any).mock.calls[1];
11281137
const secondWrittenContent = JSON.parse(secondWriteFileCall[1]);
11291138

1139+
// Verify the flag is still there
11301140
expect(secondWrittenContent.strings.do_not_translate).toHaveProperty("shouldTranslate", false);
11311141
});
11321142
});

0 commit comments

Comments
 (0)