From d8f767445933f41a7629a7637ba962bdbc461c9a Mon Sep 17 00:00:00 2001
From: Ruben Davila <rdavila84@gmail.com>
Date: Tue, 25 Apr 2017 21:47:49 -0500
Subject: [PATCH] Add ability to parse *.vue files through the `ruby
 gettext:find` script

---
 .../initializers/gettext_rails_i18n_patch.rb  | 15 +++++++++
 lib/tasks/gettext.rake                        | 33 +++++++++++++++++++
 2 files changed, 48 insertions(+)
 create mode 100644 lib/tasks/gettext.rake

diff --git a/config/initializers/gettext_rails_i18n_patch.rb b/config/initializers/gettext_rails_i18n_patch.rb
index 5570b7e31e9..d74c1f597fe 100644
--- a/config/initializers/gettext_rails_i18n_patch.rb
+++ b/config/initializers/gettext_rails_i18n_patch.rb
@@ -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
diff --git a/lib/tasks/gettext.rake b/lib/tasks/gettext.rake
new file mode 100644
index 00000000000..cc18616d2a7
--- /dev/null
+++ b/lib/tasks/gettext.rake
@@ -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
-- 
GitLab