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,8 +24,10 @@ module Gitlab
return 'PO-syntax errors' => [parse_error]
end
Gitlab::I18n.with_locale(locale) do
validate_entries
end
end
def parse_po
entries = SimplePoParser.parse(po_path)
......@@ -156,13 +158,11 @@ module Gitlab
end
def validate_translation(errors, entry)
Gitlab::I18n.with_locale(locale) do
if entry.has_plural?
translate_plural(entry)
else
translate_singular(entry)
end
end
# `sprintf` could raise an `ArgumentError` when invalid passing something
# other than a Hash when using named variables
......@@ -230,9 +230,7 @@ module Gitlab
# This calls the C function that defines the pluralization rule, it can
# return a boolean (`false` represents 0, `true` represents 1) or an integer
# that specifies the plural form to be used for the given number
pluralization_result = Gitlab::I18n.with_locale(locale) do
FastGettext.pluralisation_rule.call(counter)
end
pluralization_result = FastGettext.pluralisation_rule.call(counter)
case pluralization_result
when false
......
......@@ -461,9 +461,10 @@ RSpec.describe Gitlab::I18n::PoLinter do
fake_metadata = double
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(: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)
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