Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
422c48ba
Commit
422c48ba
authored
Apr 25, 2017
by
Ruben Davila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Parse translate filters from JS files.
parent
80d7f416
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
2 deletions
+29
-2
config/initializers/gettext_rails_i18n_patch.rb
config/initializers/gettext_rails_i18n_patch.rb
+29
-2
No files found.
config/initializers/gettext_rails_i18n_patch.rb
View file @
422c48ba
require
'gettext_i18n_rails/haml_parser'
require
'gettext_i18n_rails/haml_parser'
require
'gettext_i18n_rails_js/parser/javascript'
VUE_TRANSLATE_REGEX
=
/{{ ([^{]*)( \| translate) }}/
VUE_TRANSLATE_PLURAL_REGEX
=
/{{ ([^{]*)( \| translate-plural\((.*), (.*)\)) }}/
module
GettextI18nRails
module
GettextI18nRails
class
HamlParser
class
HamlParser
...
@@ -9,14 +13,37 @@ module GettextI18nRails
...
@@ -9,14 +13,37 @@ module GettextI18nRails
# If we found a content like "{{ 'Stage' | translate }}"
# If we found a content like "{{ 'Stage' | translate }}"
# in a HAML file we convert it to "= _('Stage')", that way
# in a HAML file we convert it to "= _('Stage')", that way
# it can be processed by the "rake gettext:find" script.
# 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
)
def
self
.
convert_to_code
(
text
)
# {{ 'Stage' | translate }} => = _('Stage')
# {{ 'Stage' | translate }} => = _('Stage')
text
.
gsub!
(
/{{ (.*)( \| translate) }}/
,
"= _(
\\
1)"
)
text
.
gsub!
(
VUE_TRANSLATE_REGEX
,
"= _(
\\
1)"
)
# {{ 'user' | translate-plural('users', users.size) }} => = n_('user', 'users', users.size)
# {{ 'user' | translate-plural('users', users.size) }} => = n_('user', 'users', users.size)
text
.
gsub!
(
/{{ (.*)( \| translate-plural\((.*), (.*)\)) }}/
,
"= n_(
\\
1,
\\
3,
\\
4)"
)
text
.
gsub!
(
VUE_TRANSLATE_PLURAL_REGEX
,
"= n_(
\\
1,
\\
3,
\\
4)"
)
old_convert_to_code
(
text
)
old_convert_to_code
(
text
)
end
end
end
end
end
end
module
GettextI18nRailsJs
module
Parser
module
Javascript
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment