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

I18n::Tasks::Scanners::PatternMapper is undefined when loading config file #204

Closed
smaximov opened this issue Sep 28, 2016 · 3 comments
Closed
Labels
Milestone

Comments

@smaximov
Copy link

I'm talking about the following snippet from the default config file:

## Sometimes, it isn't possible for i18n-tasks to match the key correctly,
## e.g. in case of a relative key defined in a helper method.
## In these cases you can use the built-in PatternMapper to map patterns to keys, e.g.:
#
# <%# I18n::Tasks.add_scanner 'I18n::Tasks::Scanners::PatternMapper',
#       only: %w(*.html.haml *.html.slim),
#       patterns: [['= title\b', '.page_title']] %>
#
# The PatternMapper can also match key literals via a special %{key} interpolation, e.g.:
#
# <%# I18n::Tasks.add_scanner 'I18n::Tasks::Scanners::PatternMapper',

I wanted to map = change_locale_link(%{key}) in slim templates to keys in the form shared.locale.%{key}. Using the examples from the snippet, I have come with the following code:

<%
I18n::Tasks.add_scanner 'I18n::Tasks::Scanners::PatternMapper',
     only: %w(*.slim),
     patterns: [['= change_locale_link[( ]\s*%{key}', 'shared.locale.%{key}']]
%>

This results in the NameError uninitialized constant I18n::Tasks::Scanners::PatternMapper when invoking any i18n-tasks command or running the spec. As a temporal solution, loading the file which contains PatternMapper worked for me:

<%

require 'i18n/tasks/scanners/pattern_mapper'

I18n::Tasks.add_scanner 'I18n::Tasks::Scanners::PatternMapper',
                        only: %w(*.slim),
                        patterns: [['= change_locale_link[( ]\s*%{key}', 'shared.locale.%{key}']]
%>

ruby v2.3.1, i18n-tasks v0.9.5.

@kimroen
Copy link

kimroen commented Oct 5, 2016

The title of this issue states the name of the constant to be I18n::Tasks::Scanner::PatternMapper, but then everywhere else you say it is I18n::Tasks::Scanners::PatternMapper (Scanner vs Scanners), which is the right one. Could you confirm that the right one is in use in the case where you get an error?

@smaximov smaximov changed the title I18n::Tasks::Scanner::PatternMapper is undefined when loading config file I18n::Tasks::Scanners::PatternMapper is undefined when loading config file Oct 5, 2016
@smaximov
Copy link
Author

smaximov commented Oct 5, 2016

@kimroen, thanks, the one in the title was a typo (my bad), the right one is I18n::Tasks::Scanners::PatternMapper. I've updated the title.

@jtomaszewski
Copy link

jtomaszewski commented Nov 19, 2016

Same problem here, I just freshly installed recent i18n-tasks release version.

Quick fix for now - just add <% require('i18n/tasks/scanners/pattern_mapper') %> line to the yml config file.

@glebm glebm closed this as completed in d9a7726 Dec 27, 2016
@glebm glebm added this to the v0.9.7 milestone Dec 27, 2016
@glebm glebm added the bug label Dec 27, 2016
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

4 participants