Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Davila <rdavila84@gmail.com>2017-04-26 21:02:07 +0300
committerRuben Davila <rdavila84@gmail.com>2017-04-26 21:02:07 +0300
commit82e967bc3ebc6b884651ddcadff2142332c365a5 (patch)
tree5f213fd015cd6d2cc0ebe15c578fd71755be37dd /config/initializers/gettext_rails_i18n_patch.rb
parentc159727894d399152bc04914ef7b936417d6e1bb (diff)
Adjust the patch for the gettext_i18n_rails and gettext_i18n_rails_js gems.
This is more simple now given we're using the recommended code to annotate content to be translated.
Diffstat (limited to 'config/initializers/gettext_rails_i18n_patch.rb')
-rw-r--r--config/initializers/gettext_rails_i18n_patch.rb27
1 files changed, 3 insertions, 24 deletions
diff --git a/config/initializers/gettext_rails_i18n_patch.rb b/config/initializers/gettext_rails_i18n_patch.rb
index d74c1f597fe..6785f361eda 100644
--- a/config/initializers/gettext_rails_i18n_patch.rb
+++ b/config/initializers/gettext_rails_i18n_patch.rb
@@ -1,8 +1,7 @@
require 'gettext_i18n_rails/haml_parser'
require 'gettext_i18n_rails_js/parser/javascript'
-VUE_TRANSLATE_REGEX = /{{ ([^{]*)( \| translate) }}/
-VUE_TRANSLATE_PLURAL_REGEX = /{{ ([^{]*)( \| translate-plural\((.*), (.*)\)) }}/
+VUE_TRANSLATE_REGEX = /{{ (N|n|s)?__\((.*)\) }}/
module GettextI18nRails
class HamlParser
@@ -10,17 +9,13 @@ module GettextI18nRails
# We need to convert text in Mustache format
# to a format that can be parsed by Gettext scripts.
- # If we found a content like "{{ 'Stage' | translate }}"
+ # If we found a content like "{{ __('Stage') }}"
# 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')
- text.gsub!(VUE_TRANSLATE_REGEX, "= _(\\1)")
-
- # {{ 'user' | translate-plural('users', users.size) }} => = n_('user', 'users', users.size)
- text.gsub!(VUE_TRANSLATE_PLURAL_REGEX, "= n_(\\1, \\3, \\4)")
+ text.gsub!(VUE_TRANSLATE_REGEX, "= \\1_(\\2)")
old_convert_to_code(text)
end
@@ -43,22 +38,6 @@ module GettextI18nRailsJs
".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
- def collect_for(value)
- ::File.open(value) do |f|
- f.each_line.each_with_index.collect do |line, idx|
- line.gsub!(VUE_TRANSLATE_REGEX, "__(\\1)")
- line.gsub!(VUE_TRANSLATE_PLURAL_REGEX, "n__(\\1, \\3, \\4)")
-
- line.scan(invoke_regex).collect do |function, arguments|
- yield(function, arguments, idx + 1)
- end
- end.inject([], :+).compact
- end
- end
end
end
end