-
Notifications
You must be signed in to change notification settings - Fork 31
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
Support for localized area names #93
Comments
|
Damn, someone caught my Anglo-centric laziness :-) This is a very good point you raise, although it's a bit more complicated than just picking the right language for each country - Belgium, for example, has datasets available in Dutch, French, and German, and for country code 7 (Russia and Kazakhstan) data in Russian appears to only be available for Kazakh numbers(!). My instinct is to default to English but if the user says that he wants it to use another language if data is available. I'll ask on the mailing list for people to comment here. What's the best way of telling the library which language to use? Just go with the various locale environment variables? IIRC the rule is something like:
|
Maybe the cleanest solution would be to introduce a new method, e.g.
I18N::LangTags::Detect seems to be a simple solution for this, and it's even a core module :) I've written a short proof of concept: Seems to do the right thing: (It might be a bit surprising that Matching against |
|
Ooh, that looks useful, thanks! |
|
@martinvonwittich can you take a look at that pull request above? Most importantly, does the documentation in lib/Number/Phone.pm make sense and can you think of any more edge-cases I need to write tests for? And if you're able to, can you test that branch on your systems and see if it does what you need? |
|
Looks great, and yes, it does exactly what we need! Thank you for your work on this! The only improvement idea I can come up with is to maybe add a note to the documentation that localized areanames may contain Unicode codepoints, and that it's necessary to enable proper Unicode support (e.g. with I bet that's a common trap for many people because Unicode mostly seems to work fine in Perl as long as all your input handles happens to give you valid UTF-8 bytes and all your output handles happen to expect UTF-8 bytes :) |
|
Thanks. Users are already having to deal with the utf-8 shenanigans, as even in English some of the data includes non-ASCII characters. eg https://metacpan.org/source/DCANTRELL/Number-Phone-3.5001/lib/Number/Phone/StubCountry/DE.pm#L721 |
|
Merged, and will be in the next quarterly release in September. |
|
FYI version 3.6000 is now on the CPAN: https://metacpan.org/pod/Number::Phone#areaname |
Currently, when using
Number::Phoneto determine the area name of a German phone number, it will return the English name instead of the localized name of the area. E.g. +49 89 would be "München" in German, butNumber::Phonewill return "Munich" instead, regardless of the current locale:This is due to the fact that
Number::Phone's build process always reads the area name out oflibphonenumber/resources/geocoding/en/<areacode>.txt(e.g.libphonenumber/resources/geocoding/en/49.txt) and ignores the different locales (e.g.libphonenumber/resources/geocoding/de/49.txt):As we use
Number::Phonein an Asterisk AGI script to put the area name into our (German) agents' phone displays, we wanted to have the German string instead. Back in 2016 when we first encountered this problem, we just dirtily hacked it directly intobuild-data.stubs:We then copied the resulting
Number/Phone/StubCountry/DE.pmto/etc/perl, and so far this hack works pretty well. Unfortunately we failed to report this issue back then, which I now have done :)The text was updated successfully, but these errors were encountered: