2017-04-24 23:36:14 -04:00
|
|
|
require 'gettext_i18n_rails/haml_parser'
|
2017-04-25 01:01:59 -04:00
|
|
|
require 'gettext_i18n_rails_js/parser/javascript'
|
|
|
|
|
2017-04-27 12:51:04 -04:00
|
|
|
VUE_TRANSLATE_REGEX = /((%[\w.-]+)(?:\s))?{{ (N|n|s)?__\((.*)\) }}/
|
2017-04-24 23:36:14 -04:00
|
|
|
|
|
|
|
module GettextI18nRails
|
|
|
|
class HamlParser
|
|
|
|
singleton_class.send(:alias_method, :old_convert_to_code, :convert_to_code)
|
|
|
|
|
|
|
|
# We need to convert text in Mustache format
|
|
|
|
# to a format that can be parsed by Gettext scripts.
|
2017-04-26 14:02:07 -04:00
|
|
|
# If we found a content like "{{ __('Stage') }}"
|
2017-04-24 23:36:14 -04:00
|
|
|
# in a HAML file we convert it to "= _('Stage')", that way
|
|
|
|
# it can be processed by the "rake gettext:find" script.
|
2017-04-25 22:47:49 -04:00
|
|
|
#
|
2017-04-25 01:01:59 -04:00
|
|
|
# Overwrites: https://github.com/grosser/gettext_i18n_rails/blob/8396387a431e0f8ead72fc1cd425cad2fa4992f2/lib/gettext_i18n_rails/haml_parser.rb#L9
|
2017-04-24 23:36:14 -04:00
|
|
|
def self.convert_to_code(text)
|
2017-04-27 12:51:04 -04:00
|
|
|
text.gsub!(VUE_TRANSLATE_REGEX, "\\2= \\3_(\\4)")
|
2017-04-25 00:03:38 -04:00
|
|
|
|
2017-04-24 23:36:14 -04:00
|
|
|
old_convert_to_code(text)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-04-25 01:01:59 -04:00
|
|
|
|
|
|
|
module GettextI18nRailsJs
|
|
|
|
module Parser
|
|
|
|
module Javascript
|
2017-04-25 22:47:49 -04:00
|
|
|
# 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",
|
|
|
|
".vue"
|
|
|
|
].include? ::File.extname(file)
|
|
|
|
end
|
2017-04-25 01:01:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|