Follow-up: 64a87b1c67 - Let the pot string extractor ignore empty strings.

This commit is contained in:
Martin Gruner 2021-11-16 15:44:21 +01:00
parent 3fdbd59b20
commit 54388cece5
6 changed files with 10 additions and 4 deletions

View file

@ -6,7 +6,7 @@ class Generators::TranslationCatalog::Extractor::Erb < Generators::TranslationCa
return if string.empty?
# zt() / t()
literal_string_regex = %r{(['"])(.*?)(?<!\\)\1}
literal_string_regex = %r{(['"])(.+?)(?<!\\)\1}
t_regex = %r{(?:#\{|\s)z?t\(?\s*#{literal_string_regex}}
[t_regex].each do |r|

View file

@ -6,7 +6,7 @@ class Generators::TranslationCatalog::Extractor::Frontend < Generators::Translat
return if string.empty?
# @T / @Ti
literal_string_regex = %r{('|")(.*?)(?<!\\)\1}
literal_string_regex = %r{('|")(.+?)(?<!\\)\1}
t_regex = %r{@Ti?\(?\s*#{literal_string_regex}}
# App.i18n.translate(Content|Plain|Inline)

View file

@ -5,7 +5,7 @@ class Generators::TranslationCatalog::Extractor::Ruby < Generators::TranslationC
def extract_from_string(string, filename) # rubocop:disable Metrics/AbcSize
return if string.empty?
literal_string_regex = %r{('|")(.*?)(?<!\\)\1}
literal_string_regex = %r{('|")(.+?)(?<!\\)\1}
# Translation.translate
locale_regex = %r{['"a-z_0-9.&@:\[\]\-]+}

View file

@ -32,6 +32,7 @@ RSpec.describe Generators::TranslationCatalog::Extractor::Erb do
<<~'CODE'
<%= zt(dynamic_variable) %>
<%= t("String with #{interpolation}") %>
<%= t("") %> # should not happen
CODE
end

View file

@ -18,11 +18,13 @@ RSpec.describe Generators::TranslationCatalog::Extractor::Frontend do
App.i18n.translateContent('String')
App.i18n.translateInline('Inline string')
App.i18n.translatePlain("Double quoted String with '")
@T('T')
@Ti('Ti')
CODE
end
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
@ -31,6 +33,8 @@ RSpec.describe Generators::TranslationCatalog::Extractor::Frontend do
<<~'CODE'
App.i18n.translateContent(dynamic_variable)
App.i18n.translateContent("String with #{interpolation}")
@Tdate(ignore)
@Ti('')
CODE
end

View file

@ -33,6 +33,7 @@ RSpec.describe Generators::TranslationCatalog::Extractor::Ruby do
<<~'CODE'
Translation.translate('de-de', dynamic_variable)
Translation.translate('de-de', "String with #{interpolation}")
__('')
CODE
end