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

[proposal] plug an i18n engine to EJS #613

Open
UrielCh opened this issue Jul 1, 2021 · 1 comment
Open

[proposal] plug an i18n engine to EJS #613

UrielCh opened this issue Jul 1, 2021 · 1 comment

Comments

@UrielCh
Copy link

UrielCh commented Jul 1, 2021

Hi,

I would like to port the i18n engine I wrote for tomcat/JSP (15 years ago) to EJS.

The implementation is pretty simple.

Right now a common way to add translation is to use code like that:

<%=__('TRANSLATION_KEY {1} AND {2}', variable1, variable2)%>
// or
<%-__('TRANSLATION_KEY {1} AND {2}', variable1, variable2)%>

the start tag is 7 char long (can be reduced to 6 with a single-letter translate function)
the ending tag is 3 char long

With my i18n style the same code will be converted to:

<%=`TRANSLATION_KEY ${variable1} AND ${variable2}`%>
// or
<%-`TRANSLATION_KEY ${variable1} AND ${variable2}`%>

the start tag is 4 char long
the ending tag is 3 char long

This version is much shorter and uses Template literals.

under the hood, a context variable should contain:

  • the lang.
  • the translate function.

A default empty translation function can be added by default, so all previous code will still be compatible.

In the first place, I was thinking about supporting a new tag <%`TEXT ${var}`%> but I do not know if the content should be protected or not by default.

Please give me some feedback.

@UrielCh
Copy link
Author

UrielCh commented Jul 1, 2021

A test version is available here: here

some tests had been added too.

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

No branches or pull requests

1 participant