-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add interpolation variable matcher #15
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
RSpec::Matchers.define :have_interpolation_keys_of do |default_locale_filepath| | ||
extend I18nSpec::FailureMessage | ||
|
||
match do |test_locale_filepath| | ||
default_translations = I18nSpec::LocaleFile.new(default_locale_filepath).flat_interpolations_only_hash | ||
test_translations = I18nSpec::LocaleFile.new(test_locale_filepath).flat_interpolations_only_hash | ||
|
||
@superset = default_translations.keys.reject do |key| | ||
default_value = default_translations[key] | ||
test_value = test_translations[key] | ||
|
||
test_value.nil? || | ||
I18nSpec::Parse.for_interpolation_variables(default_value) == I18nSpec::Parse.for_interpolation_variables(test_value) | ||
end | ||
|
||
@superset.empty? | ||
end | ||
|
||
failure_for_should do |filepath| | ||
"Expected #{filepath} interpolation variables to match #{default_locale_filepath}. \nProblems in:\n- " << @superset.join("\n- ") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I followed the pattern in another matcher file for |
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module I18nSpec | ||
class Parse | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created a |
||
|
||
def self.for_interpolation_variables(str) | ||
return nil if str.nil? | ||
str.scan(/%{[^%{}]*}/) | ||
end | ||
|
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
es: | ||
cats: | ||
zero: 'no gatos' | ||
one: 'un gato' | ||
other: 'gatos' | ||
itteh: | ||
bitteh: | ||
ceiling: | ||
kitteh: 'te mira' | ||
group: | ||
joined: "(interpolation should var should be here) unido correctamente" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
es: | ||
cats: | ||
zero: 'no gatos' | ||
one: 'un gato' | ||
other: '%{count } gatos' | ||
itteh: | ||
bitteh: | ||
ceiling: | ||
kitteh: 'te mira' | ||
group: | ||
joined: "%{user_name} unido correctamente %{groupo}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this feature, I am declaring it a pass ✅ when:
A) the test locale string completely is empty / blank
OR
B) the test locale & the default locale have exactly the same interpolation variables
Is this ok?