Search for country - php

I have built a web application where you can search for a set of locations.
Its a free text field where the visitor can input name, street, city, country, etc.
I'm using php and Elasticsearch. The problem is that all the locations have their names in English and I want the visitor to be able to search for country names in any language, at least in their native language(s).
The solution could be to either always translate the country the person searched for into English and then match agains Elasticsearch or index multiple country names in different languages on every location.
The question is how do I find out the names of the countries in their native language(s) or possibly every language. External library? Built in php? Elasticsearch feature? Web api?

Related

Different translations for different locations - CodeIgniter

I'm trying to develop an internationalized app with different translations for each country. For instance, I would like to get a different translation for spanish people than for the mexican ones, or a different translation for english people than for the american ones. What would be the best way to implement this approach?. I already got a table 'culture' on my DB where I store values like the currency or the flag image path for each country. Would be possible have different language files for each country?
Thanks in advance.

Formatting a Shipping Address by Country in PHP (or Perl)

I have an HTML form that takes an input shipping address in parts (street address, city, state/province, postal code, and country). This form is then processed with PHP.
I'd like to convert this address into the correct format for the destination country. Are there any libraries or external services that I could use to do this conversion in PHP? If not, could I do it with Perl or a similar language?
Never used it but Geo::PostalAddress is a good starting point. Useful links to regulations if nothing else.
Note that various shipping companies (Fedex, DHL etc) have their own rules for address format.
For anyone still looking for a solution, there is now a professional made, well maintained open source library https://github.com/commerceguys/addressing that solves this exact problem.
In Perl you can use Class::Phrasebook. Using it is very easy.
use Class::Phrasebook;
my $pb = new Class::Phrasebook($log, "test.xml");
$pb->load("NL"); # using Dutch as the language
$phrase = $pb->get("ADDRESS",
{ street => "Chaim Levanon",
number => 88,
city => "Tel Aviv" } );
Now in your case the shipping address will be dynamic (which will be provided by the user) so you'll have to do some more work. You can create a XML file, add dictionaries for all the countries, add phrases (street address, city, state/province, postal code) in each dictionary. Write country specific data in each phrase like "Street address: $street" for English dictionary, "adresse: $street" for French dictionary etc. And then access the dictionary according to the user's country.
More information at CPAN.
I've thought about this problem and I've decided that a file/database with address templates listed for each country is the best solution for me.
However, I'm certain that the other solutions given would work as well.

Internationalizing a web application

Not sure if stackoverflow is the most appropriate place for this question.
I am currently building a web application that will manage content, ecommerce and allow users to participate.
I am using php's intl extension to deal with different number formats and so on. gettext will be used to provide translations of the actual text in the application.
This question isn't really a technical one, but more as to how the user sets the language/version of the web app.
I have came up with a possible scenarios:
(Country regions) User selects his country and this determines his language. If the language for his country is not avaliable, default to default language.
(Language) User selects his own language, and he selects his own country/time zone settings. That means we can have users in say the United states reading content in Japanese.
With the first option, obviously it is quite fool-proof. The user claims he is from canada, so we display the content in english (en_ca) or french (fr_ca if avaliable).
However, not every web site built on top of the application will be big enough to warrant translations based on locale (i.e. canadian french (fr_ca) vs french french (fr_fr).
Some site would be quite small, so it doesn't matter where the user comes from, he should be able to select either French or English when browsing the site. However, this leads to another issue. If the user selects the content to be shown in french, how do we format things like numbers and currencies? We cannot directly infer his locale from the language he has chosen.
I have looked around the web at some "big" websites to look at how they do things.
Amazon - (Country Regions) Different sites for different countries, i.e. Amazon japan is only avaliable in japanese.
Microsoft - (Country Regions) Some countries have multiple languages. (fr_ca) vs (en_ca).
Engadget.com - (Language) English, Japanese, Chinese (both simplified and traditional).
FaceBook - (Language), but offers different versions of languages (fr_ca and fr_fr)
So I guess the question is, should I force all users of the web application to build their content around the countries/regions or languages? Or should I allow both scenarios?
Cheers :)
As a professional localizer, I reccomend "language" if there is no difference in content.
The reason why Amazon or MS ask for country is that the content is different for each territory. For stuff that is not available, say in Japan, why would they want to translate it to Japanese? Plus it's misleading to the Japanese reader, even if they are on the US site.
On the flip-side, if you offer Country as the selection, then users may expect to see different content based on the coutry they choose, and that might be misleading.
These days a lot of people are mutli-lingual so if the content is the same, defaulting by location then offering the language selection on top is more user-friendly.
I hope my thoughts might help. This is a tough question and depends on many factors - there is no 'right' answer. :)
We did something similar to this in our web app. We essentially just used the currency format of the "home" country for the language. So, if they choose French, they get France's formatting. German, Germany's formatting, etc. It won't always be the correct one but for our app we haven't had any complaints yet, so I assume that works the best if your users aren't too picky. We have a decently small userbase, however (<= 1000 visitors per instance of our app), so you may want to take this advice with a grain of salt ;)

PHP Localization and dynamic data

So I need to make a site available in different languages. Using PHP 5.x and MySQL 5.x. I believe I will be using gettext which seems fine for static text throughout the site but what about dynamic data that is stored in the db? Im referring to things like stories, events business listings etc. How do I get those to display in a different language? My initial thought was in the backend have them be able to enter multiple versions of a story, event or listing, one for each language they want to use on the site. But there could be thousands of entries times how many languages they want to show. Is there a better solution/idea that someone can point me to?
Also another issue I was thinking is currently the site allows you to search events/stories/listings, how would that work in different languages? Im assuming if someone selected the site to show in spanish they are going to use spanish words to search the site, but if the information in the db is in english I dont know that would work. Any suggestions on that?
If you want the stories to be correct in all languages, then you need them stored in all languages and provide the backend to do the translations or enter the stories on different languages as you initially thought.
If you don't like that, you might add the google translate element in your pages, to provide automatic (not correct) translation.
For the search question, I would only search for the keywords in the fields of the database in the same language as the user. If Joe is visiting your page in English, only look for the search terms in title_en, content_en, description_en fields of your database (or the ones with language='en' if you have one row per article and translation in the database, instead of one row per article (with all translations inside)). Obviously, this does only work if you put all the translations on the database.
The best solution I have seen described is this.
As i18n CMS sites as you describe are in a constant state of flux, with new articles being added, some of which have had translations, in some languages.
If an article in a chosen language has not yet been translated then show a default language (English?).
Then pick any ideas which appeal to your case:
a) If showing a default article in English also throw onto the page an input box and invite your audience to translate it for you.
b) If showing a default article in English also put on the page an offer to send the content to google translate as well as doing a) above
c) put a bounty on the translation and optionaly do a) and/or b) above.

Performing bulk language translation in a large database

My application has a 2.7 million records table with the list of all cities and villages in the world (provided by GeoNames.org). Each city has it's name in the native language. This database will be searched in an auto-complete form, but users should be able to type the city name in their own language (primarily Portuguese, since this will be a Brazilian website) and be able to locate the city (at least the most important ones).
For instance: Munich is a well-known German city. However, in the GeoNames database, it is registered as "München", the native German name. GeoNames provides an english representation of the name, but that basically strips the special characters of the city name (in this case, München becomes Munchen, not Munich).
Is there a way or service I can use to translate each of these cities names into Portuguese (or at the very least, English) and cache them in my database? I've looked into the Google Translation API, but in their TOS, automated processes are forbidden.
Thanks in advance.
A solution I found was parsing the WordPress translation files, it includes continents & cities in one of the language files.
Find the language you want here:
http://codex.wordpress.org/WordPress_in_Your_Language
Go to the language you want and download WordPress
Inside the zip goto: /wp-content/languages/
and open continents & cities file eg. "continents-cities-nl_NL.po"
In that file you'll have all the translated city names you can easily parse into your DB
I'm currently parsing the cities in PHP when I'm finished I can post the translated files here if you want.
How about parsing Wikipedia? I often use the "Languages" menu as a dictionary. It would take some time but since this is a one-time operation it doesn't matter that much.

Categories