Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add EJS template support with handling of dynamic content #453

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

HarshDodiya1
Copy link

What kind of change does this PR introduce?

Feature - Adds EJS (Embedded JavaScript) template support to Lingo.dev's localization system.

Issue Number

Fixes [#299]

Summary

  • Implements EJS loader with support for static and dynamic content.
  • Handles EJS includes, partials, and template logic.
  • Preserves template functionality while enabling localization.
  • Added test suite for EJS functionality.
  • Updated spec package to include EJS format.

Other Information

  • Added new loader: packages/cli/src/cli/loaders/ejs.ts

  • Extended test suite: index.spec.ts

  • Updated formats: packages/spec/src/formats.ts

  • Reference: EJS Documentation

@maxprilutskiy maxprilutskiy requested a review from mathio February 12, 2025 22:07
Copy link
Collaborator

@mathio mathio left a comment

Choose a reason for hiding this comment

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

Hello @HarshDodiya1 thank you for taking time and implementing EJS template support. I left a few comments to better understand your code, please have a look 👇

Also note that we are using prettier in the project, please use it to format your code before committing.

PS: I merged main branch into your feature branch and resolved one conflict related to missing createNewLineLoader() that was deleted in the meantime.

Comment on lines +85 to +90
if (normalizedText.includes(EJS_PLACEHOLDER_PREFIX)) {
// Store original EJS expression
const placeholder = placeholders.find(p => normalizedText.includes(p.id));
if (placeholder) {
result[getPath(node)] = placeholder.content;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are you removing EJS tags (line 33) and then adding them back here? I found the generated code is the same if I removed both parts. Did I miss anything?

Same in push() method below.

Comment on lines +394 to +400
<html lang="es">
<body>
<h1>Bienvenido, <%- user.name %>!</h1>
<p>Tu saldo: <%= balance %></p>
</body>
</html>
`.trim().replace(/\s+/g, ' ').replace(/>\s+</g, '><');
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is slightly confusing, as it is not obvious what the expected output is. Can you include it as expected in the template literal here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I also noticed the tests are failing - the strings seem correct, just whitespaces seem off.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with Matej here, 100%

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.

3 participants