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

No way to access country data to localize country names #8

Closed
wchristian opened this issue Oct 22, 2013 · 7 comments
Closed

No way to access country data to localize country names #8

wchristian opened this issue Oct 22, 2013 · 7 comments

Comments

@wchristian
Copy link

I'm working on a website that uses the javascript included in https://metacpan.org/module/Locale::Simple to localize various strings with data from our PO files. I'd like to localize the country names of intl-tel-input as well, but you've done an extremely good job of making that inaccessible it seems. Can you advise on a way to do this, or maybe implement some public interface towards the country data, so i can do this without forking the JS?

@jackocnr
Copy link
Owner

Hmm interesting. I was thinking it would be good to add localised country names in brackets anyway (like the gmail signup form). Would this solve your problem?

Otherwise, I could probably provide getters and setters for the country data without too much trouble, but I likely wont have time to work on this until next week.

Obviously I'm open to pull requests :)

@jackocnr
Copy link
Owner

I have now added the localised country names. Check it out and let me know if it solves your issue.

@jackocnr
Copy link
Owner

I have now also added a getter and setter for the country data, so it's all yours.

@wchristian
Copy link
Author

Sorry for the late reply, i wasn't in the office for the past days.

Either way, thanks a bunch for the work! I wouldn't have minded doing it too, but you saved me a bit of time. There's only one thing that you might or might not regard as an issue:

Since the country data is only being read when initializing a dropdown, i need to change it before initializing any dropdowns, but there's no way to access the country data without having an initialized dropdown, so i need to do this:

            var dropdown_data = $("<input />").intlTelInput().intlTelInput("getCountryData");
            dropdown_data.countries.forEach(function(obj){
                ...

It works, but isn't necessarily the best API. :)
Maybe being able to pass in a function on initialization to munge the country data would be something agreeable with you? (I'd also make the patch.)

@jackocnr
Copy link
Owner

It seems we need a static getter and setter. Could you try the solution posted here and see if that works? http:https://stackoverflow.com/questions/9364129/how-do-i-create-a-static-method-for-a-jquery-plugin

@jackocnr jackocnr reopened this Oct 31, 2013
@wchristian
Copy link
Author

Sure, i'll let you know tomorrow how it works out. :)

@jackocnr
Copy link
Owner

Ok I just implemented the static getter and setter. Here is an example of how you could use it to modify the country data before you instantiate the plugin:

var countryData = $.fn.intlTelInput.getCountryData();
countryData.countries[0].name = "TEST";
$.fn.intlTelInput.setCountryData(countryData);

Does that solve your problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants