Commit 92b82c52 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'gettext-lint-performance-improvements' into 'master'

Improve rake gettext:lint performance

See merge request gitlab-org/gitlab!47196
parents 5fbcd769 e40978f1
...@@ -24,7 +24,9 @@ module Gitlab ...@@ -24,7 +24,9 @@ module Gitlab
return 'PO-syntax errors' => [parse_error] return 'PO-syntax errors' => [parse_error]
end end
validate_entries Gitlab::I18n.with_locale(locale) do
validate_entries
end
end end
def parse_po def parse_po
...@@ -156,12 +158,10 @@ module Gitlab ...@@ -156,12 +158,10 @@ module Gitlab
end end
def validate_translation(errors, entry) def validate_translation(errors, entry)
Gitlab::I18n.with_locale(locale) do if entry.has_plural?
if entry.has_plural? translate_plural(entry)
translate_plural(entry) else
else translate_singular(entry)
translate_singular(entry)
end
end end
# `sprintf` could raise an `ArgumentError` when invalid passing something # `sprintf` could raise an `ArgumentError` when invalid passing something
...@@ -230,9 +230,7 @@ module Gitlab ...@@ -230,9 +230,7 @@ module Gitlab
# This calls the C function that defines the pluralization rule, it can # This calls the C function that defines the pluralization rule, it can
# return a boolean (`false` represents 0, `true` represents 1) or an integer # return a boolean (`false` represents 0, `true` represents 1) or an integer
# that specifies the plural form to be used for the given number # that specifies the plural form to be used for the given number
pluralization_result = Gitlab::I18n.with_locale(locale) do pluralization_result = FastGettext.pluralisation_rule.call(counter)
FastGettext.pluralisation_rule.call(counter)
end
case pluralization_result case pluralization_result
when false when false
......
...@@ -461,9 +461,10 @@ RSpec.describe Gitlab::I18n::PoLinter do ...@@ -461,9 +461,10 @@ RSpec.describe Gitlab::I18n::PoLinter do
fake_metadata = double fake_metadata = double
allow(fake_metadata).to receive(:forms_to_test).and_return(4) allow(fake_metadata).to receive(:forms_to_test).and_return(4)
allow(linter).to receive(:metadata_entry).and_return(fake_metadata) allow(linter).to receive(:metadata_entry).and_return(fake_metadata)
allow(linter).to receive(:locale).and_return('pl_PL')
numbers = linter.numbers_covering_all_plurals numbers = Gitlab::I18n.with_locale('pl_PL') do
linter.numbers_covering_all_plurals
end
expect(numbers).to contain_exactly(0, 1, 2) expect(numbers).to contain_exactly(0, 1, 2)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment