Add ability to parse *.vue files through the ruby gettext:find
script
This commit is contained in:
parent
422c48baa7
commit
d8f7674459
2 changed files with 48 additions and 0 deletions
|
@ -13,6 +13,7 @@ module GettextI18nRails
|
|||
# If we found a content like "{{ 'Stage' | translate }}"
|
||||
# in a HAML file we convert it to "= _('Stage')", that way
|
||||
# it can be processed by the "rake gettext:find" script.
|
||||
#
|
||||
# Overwrites: https://github.com/grosser/gettext_i18n_rails/blob/8396387a431e0f8ead72fc1cd425cad2fa4992f2/lib/gettext_i18n_rails/haml_parser.rb#L9
|
||||
def self.convert_to_code(text)
|
||||
# {{ 'Stage' | translate }} => = _('Stage')
|
||||
|
@ -29,6 +30,20 @@ end
|
|||
module GettextI18nRailsJs
|
||||
module Parser
|
||||
module Javascript
|
||||
|
||||
# This is required to tell the `rake gettext:find` script to use the Javascript
|
||||
# parser for *.vue files.
|
||||
#
|
||||
# Overwrites: https://github.com/webhippie/gettext_i18n_rails_js/blob/46c58db6d2053a4f5f36a0eb024ea706ff5707cb/lib/gettext_i18n_rails_js/parser/javascript.rb#L36
|
||||
def target?(file)
|
||||
[
|
||||
".js",
|
||||
".jsx",
|
||||
".coffee",
|
||||
".vue"
|
||||
].include? ::File.extname(file)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Overwrites: https://github.com/webhippie/gettext_i18n_rails_js/blob/46c58db6d2053a4f5f36a0eb024ea706ff5707cb/lib/gettext_i18n_rails_js/parser/javascript.rb#L46
|
||||
|
|
33
lib/tasks/gettext.rake
Normal file
33
lib/tasks/gettext.rake
Normal file
|
@ -0,0 +1,33 @@
|
|||
require "gettext_i18n_rails/tasks"
|
||||
|
||||
namespace :gettext do
|
||||
# Customize list of translatable files
|
||||
# See: https://github.com/grosser/gettext_i18n_rails#customizing-list-of-translatable-files
|
||||
def files_to_translate
|
||||
folders = [
|
||||
"app",
|
||||
"lib",
|
||||
"config",
|
||||
locale_path
|
||||
].join(",")
|
||||
|
||||
exts = [
|
||||
"rb",
|
||||
"erb",
|
||||
"haml",
|
||||
"slim",
|
||||
"rhtml",
|
||||
"js",
|
||||
"jsx",
|
||||
"vue",
|
||||
"coffee",
|
||||
"handlebars",
|
||||
"hbs",
|
||||
"mustache"
|
||||
].join(",")
|
||||
|
||||
Dir.glob(
|
||||
"{#{folders}}/**/*.{#{exts}}"
|
||||
)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue