Follow-up: 64a87b1c67
- Let the pot string extractor ignore empty strings.
This commit is contained in:
parent
3fdbd59b20
commit
54388cece5
6 changed files with 10 additions and 4 deletions
|
@ -6,7 +6,7 @@ class Generators::TranslationCatalog::Extractor::Erb < Generators::TranslationCa
|
||||||
return if string.empty?
|
return if string.empty?
|
||||||
|
|
||||||
# zt() / t()
|
# zt() / t()
|
||||||
literal_string_regex = %r{(['"])(.*?)(?<!\\)\1}
|
literal_string_regex = %r{(['"])(.+?)(?<!\\)\1}
|
||||||
t_regex = %r{(?:#\{|\s)z?t\(?\s*#{literal_string_regex}}
|
t_regex = %r{(?:#\{|\s)z?t\(?\s*#{literal_string_regex}}
|
||||||
|
|
||||||
[t_regex].each do |r|
|
[t_regex].each do |r|
|
||||||
|
|
|
@ -6,7 +6,7 @@ class Generators::TranslationCatalog::Extractor::Frontend < Generators::Translat
|
||||||
return if string.empty?
|
return if string.empty?
|
||||||
|
|
||||||
# @T / @Ti
|
# @T / @Ti
|
||||||
literal_string_regex = %r{('|")(.*?)(?<!\\)\1}
|
literal_string_regex = %r{('|")(.+?)(?<!\\)\1}
|
||||||
t_regex = %r{@Ti?\(?\s*#{literal_string_regex}}
|
t_regex = %r{@Ti?\(?\s*#{literal_string_regex}}
|
||||||
|
|
||||||
# App.i18n.translate(Content|Plain|Inline)
|
# App.i18n.translate(Content|Plain|Inline)
|
||||||
|
|
|
@ -5,7 +5,7 @@ class Generators::TranslationCatalog::Extractor::Ruby < Generators::TranslationC
|
||||||
def extract_from_string(string, filename) # rubocop:disable Metrics/AbcSize
|
def extract_from_string(string, filename) # rubocop:disable Metrics/AbcSize
|
||||||
return if string.empty?
|
return if string.empty?
|
||||||
|
|
||||||
literal_string_regex = %r{('|")(.*?)(?<!\\)\1}
|
literal_string_regex = %r{('|")(.+?)(?<!\\)\1}
|
||||||
|
|
||||||
# Translation.translate
|
# Translation.translate
|
||||||
locale_regex = %r{['"a-z_0-9.&@:\[\]\-]+}
|
locale_regex = %r{['"a-z_0-9.&@:\[\]\-]+}
|
||||||
|
|
|
@ -32,6 +32,7 @@ RSpec.describe Generators::TranslationCatalog::Extractor::Erb do
|
||||||
<<~'CODE'
|
<<~'CODE'
|
||||||
<%= zt(dynamic_variable) %>
|
<%= zt(dynamic_variable) %>
|
||||||
<%= t("String with #{interpolation}") %>
|
<%= t("String with #{interpolation}") %>
|
||||||
|
<%= t("") %> # should not happen
|
||||||
CODE
|
CODE
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,13 @@ RSpec.describe Generators::TranslationCatalog::Extractor::Frontend do
|
||||||
App.i18n.translateContent('String')
|
App.i18n.translateContent('String')
|
||||||
App.i18n.translateInline('Inline string')
|
App.i18n.translateInline('Inline string')
|
||||||
App.i18n.translatePlain("Double quoted String with '")
|
App.i18n.translatePlain("Double quoted String with '")
|
||||||
|
@T('T')
|
||||||
|
@Ti('Ti')
|
||||||
CODE
|
CODE
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'finds the correct strings' do
|
it 'finds the correct strings' do
|
||||||
expect(result_strings).to eq(Set['__ String', 'String', 'Inline string', "Double quoted String with '"])
|
expect(result_strings).to eq(Set['__ String', 'String', 'Inline string', "Double quoted String with '", 'T', 'Ti'])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -31,6 +33,8 @@ RSpec.describe Generators::TranslationCatalog::Extractor::Frontend do
|
||||||
<<~'CODE'
|
<<~'CODE'
|
||||||
App.i18n.translateContent(dynamic_variable)
|
App.i18n.translateContent(dynamic_variable)
|
||||||
App.i18n.translateContent("String with #{interpolation}")
|
App.i18n.translateContent("String with #{interpolation}")
|
||||||
|
@Tdate(ignore)
|
||||||
|
@Ti('')
|
||||||
CODE
|
CODE
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ RSpec.describe Generators::TranslationCatalog::Extractor::Ruby do
|
||||||
<<~'CODE'
|
<<~'CODE'
|
||||||
Translation.translate('de-de', dynamic_variable)
|
Translation.translate('de-de', dynamic_variable)
|
||||||
Translation.translate('de-de', "String with #{interpolation}")
|
Translation.translate('de-de', "String with #{interpolation}")
|
||||||
|
__('')
|
||||||
CODE
|
CODE
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue