Skip to content
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 translations #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions app/assets/javascripts/subdivision_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,21 @@ var SubdivisionSelect = (function() {

function onChange() {
self.country = self._countrySelect.val();
$.ajax( {
url: "/subdivisions",
data: { country_code: self.country }
}).done(function(newSubdivisions) {
var locale = self._subdivisionSelect.data("locale");
if(typeof(gon.subdivisions_data) !== 'undefined' && typeof(gon.subdivisions_data[self.country]) !== 'undefined'){
// we can get the data without an ajax call, might be important in high traffic times for example
self._clearSubdivisionSelect();
self._updateSubdivisionSelect(newSubdivisions);
});
console.log("gon subdivisions found, no ajax call required");
self._updateSubdivisionSelect(gon.subdivisions_data[self.country]);
} else {
$.ajax( {
url: "/subdivisions",
data: { country_code: self.country, locale: locale }
}).done(function(newSubdivisions) {
self._clearSubdivisionSelect();
self._updateSubdivisionSelect(newSubdivisions);
});
}
}
};

Expand Down
2 changes: 2 additions & 0 deletions app/helpers/subdivision_select/subdivisions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def self.get_subdivisions(alpha2)
if ISO3166::Country[alpha2].nil?
{}
else
# ISO3166::Country[alpha2].subdivisions.map { |k, v| [k, I18n.t("states.#{alpha2}.#{k}", default: v["name"])] }.to_h
# ***** change this line so the source of truth is the Subdivision name in our app that we registered with ISO3166::Data.register, not the translation file - subdivisions do not need translations anyway
ISO3166::Country[alpha2].subdivisions.map { |k, v| [k, v["name"]] }.to_h
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/subdivision_select/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module SubdivisionSelect
VERSION = "0.0.6"
VERSION = "0.0.8"
end