Skip to content

feat: add support for locked patterns in mdx loader#700

Merged
maxprilutskiy merged 8 commits intomainfrom
devin/1746209518-mdx-locked-patterns
May 2, 2025
Merged

feat: add support for locked patterns in mdx loader#700
maxprilutskiy merged 8 commits intomainfrom
devin/1746209518-mdx-locked-patterns

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

Add support for locked patterns in MDX loader

This PR adds support for preserving specific patterns in MDX files during translation, focusing on the syntax used in documentation like the Solana examples.

Implementation Details

  • Added a new loader specifically for locked patterns that preserves regex-matched content during translation
  • Implemented a new config version 1.7 with a "lockedPatterns" field that accepts an array of regex patterns
  • Added support for patterns like:
    • !params syntax
    • !! parameter_name headings
    • !type string declarations
    • !required flags
    • !values lists

Configuration

The implementation adds a new field to the bucket configuration in i18n.json:

"lockedPatterns": [
  "!params",
  "!! [\\w_]+",
  "!type [\\w<>\\[\\]\"',]+",
  "!required",
  "!values [\\s\\S]*?(?=\\n\\n|$)"
]

Testing

  • Added comprehensive unit tests for the locked patterns loader
  • Tests verify that patterns are correctly preserved during translation
  • Included real-world examples from Solana documentation
  • All tests are passing

Link to Devin run: https://app.devin.ai/sessions/e0df584394174a33ae57acca13dddba7
Requestor: Max Prilutskiy (max@lingo.dev)

Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration Bot and others added 2 commits May 2, 2025 18:22
…ontain

Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>
Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>
Comment thread packages/cli/src/cli/loaders/mdx2/locked-patterns.ts Outdated
devin-ai-integration Bot and others added 2 commits May 2, 2025 18:59
Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>
Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>
Comment on lines +59 to +78
async pull(locale, input, initCtx, originalLocale) {
const patterns = defaultPatterns || [];

const { content, lockedPlaceholders } = extractLockedPatterns(input || "", patterns);

return {
content,
lockedPlaceholders,
};
},

async push(locale, data) {
let result = data.content;
for (const [placeholder, original] of Object.entries(data.lockedPlaceholders)) {
result = result.replaceAll(placeholder, original);
}

return result;
},
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. should return string, not obkect
  2. in push, use pullInput +extractLockedPatterns again to recreate the lockedPlaceholders map

…Input

Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>
Comment on lines +62 to +80
async push(locale, data) {
const patterns = defaultPatterns || [];

const pullInput = (global as any).__pullInput || null;

if (!pullInput) {
return data;
}

const { lockedPlaceholders } = extractLockedPatterns(pullInput, patterns);

let result = data;
for (const [placeholder, original] of Object.entries(lockedPlaceholders)) {
result = result.replaceAll(placeholder, original);
}

return result;
},
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refer to the definition of createLoader to understand how to use pull input

@maxprilutskiy maxprilutskiy merged commit c5ccf81 into main May 2, 2025
2 checks passed
@maxprilutskiy maxprilutskiy deleted the devin/1746209518-mdx-locked-patterns branch May 2, 2025 19:20
mainstar123 pushed a commit to mainstar123/lingo.dev that referenced this pull request Jul 7, 2025
* feat: add support for locked patterns in mdx loader

Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>

* test: update locked patterns tests to use toBe instead of toMatch/toContain

Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>

* fix(mdx): fix locked patterns tests and improve regex patterns

Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>

* fix: make locked patterns configurable via i18n.json

Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>

* refactor: remove default patterns fallback in locked patterns loader

Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>

* refactor: update locked patterns loader to return string and use pullInput

Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>

* refactor: update locked patterns loader to properly use pullInput parameter

Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Max Prilutskiy <maks.prilutskiy@gmail.com>
Co-authored-by: Max Prilutskiy <5614659+maxprilutskiy@users.noreply.github.com>
17prateek12 pushed a commit to 17prateek12/lingo.dev that referenced this pull request Jan 23, 2026
* feat: add support for locked patterns in mdx loader

Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>

* test: update locked patterns tests to use toBe instead of toMatch/toContain

Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>

* fix(mdx): fix locked patterns tests and improve regex patterns

Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>

* fix: make locked patterns configurable via i18n.json

Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>

* refactor: remove default patterns fallback in locked patterns loader

Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>

* refactor: update locked patterns loader to return string and use pullInput

Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>

* refactor: update locked patterns loader to properly use pullInput parameter

Co-Authored-By: Max Prilutskiy <maks.prilutskiy@gmail.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Max Prilutskiy <maks.prilutskiy@gmail.com>
Co-authored-by: Max Prilutskiy <5614659+maxprilutskiy@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant