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

Guidance on custom key matching #110

Closed
philostler opened this issue Nov 20, 2014 · 4 comments
Closed

Guidance on custom key matching #110

philostler opened this issue Nov 20, 2014 · 4 comments

Comments

@philostler
Copy link

I'm mainly looking for guidance, but you could argue that this is an issue in itself (I can't work out how to do this from the docs).

I dynamically build keys for I18n strings in my app in the following form...

serialize_error(%i(path to key)

This then resolves to two keys...

I18n.t "path.to.key.code"
I18n.t "path.to.key.message"

Where would I even begin to start making this work so I can check on unused keys etc? I'm guessing a custom scanner...??

Thanks

@glebm glebm added the question label Nov 21, 2014
@glebm
Copy link
Owner

glebm commented Nov 21, 2014

Hi, as i18n-tasks doesn't support multiple scanners yet (#81 - help is welcome!), you could inherit from PatternScanner and override the scan_file method:

class MyScanner < I18n::Tasks::Scanners::PatternScanner
  def scan_file(path, opts = {})
    keys = ... # custom parsing
    super + keys
  end
end

The method must return an array with elements like below:

['full.key', data: {
  src_path: 'path/to/file.rb',
  pos:      51,
  line_num: 2,
  line_pos: 1,
  line:     'serialize_error(%i(full key))'
}]

Then, specify the scanner in config/i18n-tasks.yml:

<% require_relative '../lib/my_scanner.rb' %>

...

search:
  scanner: MyScanner

@glebm glebm added the docs label Nov 21, 2014
@philostler
Copy link
Author

OK thanks, I'll give this a go soon and see how that goes

@glebm
Copy link
Owner

glebm commented Nov 24, 2014

Great! Feel free to ask stuff on our Gitter chat room.

@glebm
Copy link
Owner

glebm commented Aug 8, 2015

This will be a lot easier with v0.9. Please see the example here: https://github.com/glebm/i18n-tasks/wiki/A-custom-scanner-example.

@glebm glebm closed this as completed Aug 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants