Skip to content

Commit c0d801e

Browse files
committed
feat: retain custom inlineCode values
1 parent d05e809 commit c0d801e

3 files changed

Lines changed: 31 additions & 5 deletions

File tree

.changeset/olive-games-smile.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+
retain custom inlinde code values

packages/cli/src/cli/loaders/mdx2/code-placeholder.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,5 +307,22 @@ describe("MDX Code Placeholder Loader", () => {
307307
const pushed = await loader.push("es", pulled);
308308
expect(pushed).toBe(md);
309309
});
310+
311+
it("retains custom inline code in target locale when it differs from source", async () => {
312+
const enMd = "Use `foo` function.";
313+
const ruMd = "Используйте `бар` функцию.";
314+
315+
// Pull English source to establish originalInput in loader state
316+
await loader.pull("en", enMd);
317+
318+
// Pull Russian content (with its own inline code value)
319+
const ruPulled = await loader.pull("ru", ruMd);
320+
// Simulate translator editing surrounding text but keeping placeholder intact
321+
const ruTranslated = ruPulled.replace("Используйте", "Примените");
322+
323+
// Push back to Russian locale and ensure inline code is preserved
324+
const ruPushed = await loader.push("ru", ruTranslated);
325+
expect(ruPushed).toBe("Примените `бар` функцию.");
326+
});
310327
});
311328
});

packages/cli/src/cli/loaders/mdx2/code-placeholder.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,17 @@ export default function createMdxCodePlaceholderLoader(): ILoader<
9191
return response.content;
9292
},
9393

94-
async push(locale, data, originalInput) {
95-
const response = extractCodePlaceholders(originalInput ?? "");
94+
async push(locale, data, originalInput, originalLocale, pullInput) {
95+
const sourceInfo = extractCodePlaceholders(originalInput ?? "");
96+
const currentInfo = extractCodePlaceholders(pullInput ?? "");
97+
98+
const codePlaceholders = _.merge(
99+
sourceInfo.codePlaceholders,
100+
currentInfo.codePlaceholders,
101+
);
96102

97103
let result = data;
98-
for (const [placeholder, original] of Object.entries(
99-
response.codePlaceholders,
100-
)) {
104+
for (const [placeholder, original] of Object.entries(codePlaceholders)) {
101105
const replacement = original.startsWith(">")
102106
? _.trimStart(original, "> ")
103107
: original;

0 commit comments

Comments
 (0)