Skip to content

Commit b0ac42a

Browse files
authored
feat: add support for stringSet to xcode-xcstrings and v2 (#1617)
* feat: add support for stringSet to xcode-xcstrings and xcode-xcstrings-v2 * chore: add changeset
1 parent d2e582b commit b0ac42a

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

.changeset/tidy-pumpkins-switch.md

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+
support for stringSet to xcode-xcstrings and v2

packages/cli/src/cli/loaders/xcode-xcstrings.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,35 @@ describe("loaders/xcode-xcstrings", () => {
303303
});
304304
});
305305

306+
describe("stringSet support", () => {
307+
it("should pull and push stringSet.values as array", async () => {
308+
const input = {
309+
sourceLanguage: "en",
310+
strings: {
311+
"app.shortcut": {
312+
extractionState: "extracted_with_value",
313+
localizations: {
314+
en: { stringSet: { state: "new", values: ["Open", "Launch"] } },
315+
},
316+
},
317+
},
318+
version: "1.0",
319+
};
320+
321+
const loader = createXcodeXcstringsLoader(defaultLocale);
322+
loader.setDefaultLocale(defaultLocale);
323+
await loader.pull(defaultLocale, input);
324+
const pulled = await loader.pull("en", input);
325+
326+
expect(pulled["app.shortcut"]).toEqual(["Open", "Launch"]);
327+
328+
const pushed = await loader.push("es", { "app.shortcut": ["Abrir"] }, input);
329+
expect(pushed!.strings["app.shortcut"].localizations.es).toEqual({
330+
stringSet: { state: "translated", values: ["Abrir"] },
331+
});
332+
});
333+
});
334+
306335
describe("_removeLocale", () => {
307336
it("should remove the locale from the input", () => {
308337
const input = {

packages/cli/src/cli/loaders/xcode-xcstrings.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export default function createXcodeXcstringsLoader(
2525
if (langTranslationEntity) {
2626
if ("stringUnit" in langTranslationEntity) {
2727
resultData[translationKey] = langTranslationEntity.stringUnit.value;
28+
} else if ("stringSet" in langTranslationEntity) {
29+
const values = langTranslationEntity.stringSet.values;
30+
if (Array.isArray(values) && values.length > 0) {
31+
resultData[translationKey] = values;
32+
}
2833
} else if ("variations" in langTranslationEntity) {
2934
if ("plural" in langTranslationEntity.variations) {
3035
resultData[translationKey] = {};
@@ -77,6 +82,22 @@ export default function createXcodeXcstringsLoader(
7782
},
7883
};
7984

85+
if (hasDoNotTranslateFlag) {
86+
langDataToMerge.strings[key].shouldTranslate = false;
87+
}
88+
} else if (Array.isArray(value)) {
89+
langDataToMerge.strings[key] = {
90+
extractionState: originalInput?.strings?.[key]?.extractionState,
91+
localizations: {
92+
[locale]: {
93+
stringSet: {
94+
state: "translated",
95+
values: value,
96+
},
97+
},
98+
},
99+
};
100+
80101
if (hasDoNotTranslateFlag) {
81102
langDataToMerge.strings[key].shouldTranslate = false;
82103
}

0 commit comments

Comments
 (0)