Class: ExtractI18n::Slimkeyfy::VueTransformer
Constant Summary
collapse
- BEFORE =
/(?<before>.*[\( ^])/.freeze
- HTML_ARGUMENTS =
{
placeholder: /(?<html_tag>[a-z\-]*placeholder=\s*)/,
title: /(?<html_tag>title=\s*)/,
kind_of_title: /(?<html_tag>[a-z\-]+title=\s*)/,
label: /(?<html_tag>[a-z\-]*label=\s*)/,
description: /(?<html_tag>description=\s*)/,
alt: /(?<html_tag>alt=\s*)/,
prepend: /(?<html_tag>prepend=\s*)/,
append: /(?<html_tag>append=\s*)/,
}.freeze
SlimTransformer::AFTER, SlimTransformer::EQUALS, SlimTransformer::HTML_TAGS, SlimTransformer::LINK_TO, SlimTransformer::STRING, SlimTransformer::STRING_WITHOUT_QUOTES, SlimTransformer::TRANSLATED, SlimTransformer::TRANSLATION
Instance Method Summary
collapse
#initialize, #transform
Instance Method Details
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/extract_i18n/slimkeyfy/vue_transformer.rb', line 73
def (translation)
args = {}
translation.scan(/\{\{([^}]*)\}\}/).each_with_index do |stripped_arg, index|
arg = Regexp.last_match[0]
key = .key(arg)
key = key + index.to_s if index > 0
translation = translation.gsub(arg, "{#{key}}")
args[key] = stripped_arg[0]
end
[args, translation]
end
|
#parse_html {|change| ... } ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/extract_i18n/slimkeyfy/vue_transformer.rb', line 20
def parse_html(&_block)
return @word.line if @word.line.match(TRANSLATED)
return @word.line if @word.tail.join(" ")[/^{{.*}}$/]
body = @word.tail.join(" ")
body, tagged_with_equals = ::Slimkeyfy::Whitespacer.convert_nbsp(body, @word.head)
tagged_with_equals = "|" if tagged_with_equals == "="
interpolate_arguments, body = (body)
change = ::SourceChange.new(
source_line: @word.line,
remove: body,
interpolate_arguments: interpolate_arguments,
interpolation_type: :vue,
i18n_key: "#{@file_key}.#{ExtractI18n.key(body)}",
i18n_string: body,
t_template: "#{@word.indentation}#{tagged_with_equals} {{ $t('%s'%s) }}"
)
yield(change)
end
|
#parse_html_arguments(line, token_skipped_before = nil, &block) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/extract_i18n/slimkeyfy/vue_transformer.rb', line 43
def parse_html_arguments(line, token_skipped_before = nil, &block)
final_line = line
regex_list.each do |regex|
line.scan(regex) do |m_data|
next if m_data == token_skipped_before
before = m_data[0]
if before[-1] == ":"
next
end
html_tag = m_data[1]
translation = match_string(m_data[2])
after = m_data[3]
interpolate_arguments, translation = (translation)
change = ::SourceChange.new(
source_line: final_line,
i18n_string: translation,
i18n_key: "#{@file_key}.#{ExtractI18n.key(translation)}",
remove: m_data[2],
interpolate_arguments: interpolate_arguments,
interpolation_type: :vue,
t_template: "#{before}:#{html_tag}\"$t('%s'%s)\"#{after}"
)
final_line = yield(change)
return parse_html_arguments(final_line, m_data, &block)
end
end
@word.indentation + final_line
end
|
#regex_list ⇒ Object
16
17
18
|
# File 'lib/extract_i18n/slimkeyfy/vue_transformer.rb', line 16
def regex_list
HTML_ARGUMENTS.map { |_, regex| /#{BEFORE}#{regex}#{TRANSLATION}#{AFTER}/ }
end
|