-
Notifications
You must be signed in to change notification settings - Fork 264
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
Support i18n-tasks-use hints within JavaScript comment lines #322
Comments
i18n-tasks/lib/i18n/tasks/scanners/pattern_scanner.rb Lines 16 to 22 in e2ffb33
PR welcome |
Note that magic comments are actually supported but the call must match the following pattern:
|
Thanks for the tip. Because the IGNORE_LINES is frozen, i cannot modify IGNORE_LINES directly, but have to inherit from PatternScanner and reset it in an initializer. class JsScanner < I18n::Tasks::Scanners::PatternScanner
IGNORE_LINES = I18n::Tasks::Scanners::PatternScanner::IGNORE_LINES.merge(
'js' => re=%r{^\s*// *(?!\si18n-tasks-use)},
'ts' => re
)
def initialize(**args)
super
@ignore_lines_res = (config[:ignore_lines] || IGNORE_LINES).each_with_object({}) do |(ext, re), h|
h[ext.to_s] = Regexp.new(re)
end
end
end
I18n::Tasks.add_scanner 'JsScanner', only: %w(*.js *.ts) To make globs work in the use, one cannot use "*" but must simulate ruby in the comment: // i18n-tasks-use t("js.feedback.behavior.options.#{key}")
$t("...") |
i18n-tasks does not pick up i18n-tasks-use hints written in JavaScript, e.g.:
The reason for this lies in RubyAstScanner's
MAGIC_COMMENT_PREFIX
, which looks as follows:/\A.\s*i18n-tasks-use\s+/
.The first dot is assuming a single comment character, so the line does not get picked up.
The text was updated successfully, but these errors were encountered: