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

It would be useful to have a way to ignore the text portion of it interpolations #361

Closed
zofrex opened this issue Nov 20, 2020 · 2 comments

Comments

@zofrex
Copy link

zofrex commented Nov 20, 2020

For example, this translation:

en:
  step_2: Once that's done, %{collection_link:go get your collection code here} and copy it.
pl:
  step_2: Kiedy to się skończy, %{collection_link:weź swój kod kolekcji} i skopiuj go.

Fails the inconsistent interpolations check:

Inconsistent interpolations (1) | i18n-tasks v0.9.31
+--------+--------------------+------------------------------------------------------------------------------+
| Locale | Key                | Value                                                                        |
+--------+--------------------+------------------------------------------------------------------------------+
|   pl   | static.home.step_2 | Kiedy to się skończy, %{collection_link:weź swój kod kolekcji} i skopiuj go. |
+--------+--------------------+------------------------------------------------------------------------------+

This is because everything between %{ and } is being considered part of the interpolation variable name, but in this case it's only everything up to the :, because I'm using it.

I'm currently working around this by redefining the regex that recognises interpolation variables:

require 'warning'
Warning.ignore(/already initialized constant I18n::Tasks::Interpolations::VARIABLE_REGEX/)
Warning.ignore(/previous definition of VARIABLE_REGEX was here/, %r{.*/i18n-tasks-[0-9.]+/lib/i18n/tasks/interpolations.rb})
module I18n::Tasks
  module Interpolations
    VARIABLE_REGEX = /%{[^}:]+[}:]/
  end
end

But it would be nice if there was a less hacky way to do this.

Perhaps the regex could be configurable?

Or maybe it would be OK for it to terminate at a : out of the box, as I don't think that character can occur in an interpolation variable name anyway?

I would be up for implementing the change, if you agree that it's a good idea and how it should be done.

@glebm
Copy link
Owner

glebm commented Mar 8, 2021

Let's make this an attribute on the Interpolations metaclass.

The it gem support is already configured with code, so we can then add this to the snippet in the "it" article (https://github.com/glebm/i18n-tasks/wiki/The-%22it%22-gem-support):

I18n::Tasks::Interpolations.variable_regex = /%{[^}:]+[}:]/

glebm added a commit that referenced this issue Mar 25, 2022
For better `it` gem support. Refs #361
@glebm
Copy link
Owner

glebm commented Mar 25, 2022

Released v1.0.4, wiki article updated

https://github.com/glebm/i18n-tasks/wiki/The-%22it%22-gem-support

@glebm glebm closed this as completed Mar 25, 2022
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

2 participants