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

Parsing error when using [ and " inside interpolation #520

Open
seballot opened this issue Aug 31, 2023 · 2 comments
Open

Parsing error when using [ and " inside interpolation #520

seballot opened this issue Aug 31, 2023 · 2 comments
Labels

Comments

@seballot
Copy link

Dear team,

Thank you so much for this amazing tool

A small issue I have run into, with this kind of code

I18n.t("my.translation.#{mapping["key"]}")

The presence of both [ + " make this kind of error to be displayed when I run I18n-tasks unused

/usr/local/bundle/gems/i18n-tasks-1.0.12/lib/i18n/tasks/key_pattern_matching.rb:28:in `compile_key_pattern': premature end of char-class: /\\A(my\\.translation\\.mapping[)\\z/ (RegexpError)

If I use single quote it works

I18n.t("my.translation.#{mapping['key']}")

Best regards,
Sebastian

@davidwessman
Copy link
Collaborator

davidwessman commented Sep 24, 2023

In what kind of a file did you get this error? 🙂
Could you also add your config/i18n-tasks.yml?

@carlosmedrano97
Copy link

carlosmedrano97 commented Oct 17, 2023

I'm having the same issue, I'm using the default i18n-tasks.yml file, with ruby 2.7.6 and rails 6.0.6.1

The following does not fail with an html.erb

<% [{"key" => 0},{"key" => 1}, {"key" => 2}, {"key" => 3}].each do |n| %>
  <p> <%=I18n.t("test.N#{n["key"]}")%></p>
<%end%>

But the same fails with an html.haml

- [{"key" => 0},{"key" => 1}, {"key" => 2}, {"key" => 3}].each do |n|
  %p= I18n.t("test.N#{n["key"]}")

The translation file is really simple:

en:
  test:
    N0: Test 0
    N1: Test 1
    N2: Test 2
    N3: Test 3

And this is the error that is throwing:

Error:
I18nTest#test_no_unused_keys:
RegexpError: premature end of char-class: /\A(test\.Nn[)\z/
    test/i18n_test.rb:17:in `test_no_unused_keys'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants