List All the countries in a specific language - odoo

I need to list all the countries in the French Language.
all_countries = self.env['res.country'].search([])
for country in all_countries:
_logger.error(country.name)
With this code i get the Country English Name.How to get the French one?

As far as I know, there is no reference between country and languages. You have to get the list by external modules. Try pycountry (https://pypi.python.org/pypi/pycountry/0.12.1), get the list of country code (by language code fr-*), then search for matches in res.country.
Or you can override res.country and add language reference your self :)

Related

How do I tag the gender of a noun with Spacy?

I would like to tag the gender of nouns using Spacy; specifically in my case, German.
I am not sure which Spacy pipeline has information about noun gender, for example, the Tagger or the Lemmatizer?
Different languages have different grammatical features, so you can look at the specific language model of a language to determine what pipelines it has.
For German, we can see under “Label Scheme” that the “morphologizer” pipeline has tags including “gender”.
Here, it shows that the morphologizer assigns the attribute “morph” to each Token.
“morph” is respectively of type “MorphAnalysis”.
There are different ways to access the morphological annotation from a MorphAnalysis object.
The simplest is to use the “.get” method, by passing the name of the category you want:
Token.morph.get(“gender”)
which returns a list of strings in case that category has multiple values.
You can also return the MorphAnalysis as a dictionary with to_dict(), as a string with str(Token.morph), or iterate over Token.morph with a loop, which returns each attribute-value pair as strings.

What's the proper way to let vb.net program to read a list?

For example, say I have a vb.net program and I want the program to be able to reference country codes. If I know the country name I wants to know the country code and via versa.
I can hardcode all the country in the program.
I can make the program read a text file
What would be the proper way?
I am thinking of something like string table in ios programming where instead of telling what a label should say you make a table and then the code reference that table. Something like resource file? Does vb.net have that?
It will be better if you will have the data in a file in your hard drive instead of "hardcoded" ,
it will be easier to change, add, replace, delete values , not mention if you will suddenly decide to move to another country ;)
I would make an enumeration list.
i.e.
Public Enum CountryCodes
Albania = 355
Algeria = 213
American Samoa= 684
End Enum
Find enum
Dim value As CountryCodes = CountryCodes.Algeria

How to get the user country always in English?

In my app I have a system with geolocation that compares the user's country with a string in my code. Here is something similar:
if (UserLocation.country == #"Switzerland") {
//country is Switzerland
}
This system works fine if the user language of the device is English.
Some users have reported that it isn't working and that they have the device in German or Italian.
How can I force the device to give me the string of the country always in English?
It is generally not ideal to use natural language (i.e., the language we speak and write as humans) to store information that is inherently symbolic.
You found a good example yourself that arises when your software travels, as it does with modern devices used world-wide.
Another reason could be that even within the same language there may be several widely-used ways to refer to the same "object" or topic. Just think about America, which can be referred to as America, US, USA and probably a couple of other names, too. Or the UK, which is referred to as both the United Kingdom (UK) and Great Britain (GB). Or even for some simple object properties: Is it color or colour? I am sure that more examples can be found for other languages - especially if they are spoken in more than one country.
On top of that, natural language is also prone to misspellings, typing mistakes, use of abbreviations and changes to spelling standards over time.
Hence, a better solution would be to use a language-independent method.
The commonly accepted practice for country names is to use ISO country codes ("CH" for Switzerland, "DE" for Germany, etc., in case you use the 2-letter versions.)
In your database (which can be as simple as a plist file) you would create a field called for instance countrycode of length 2 characters which should take a value of "US", "CH", "DE", "FR", etc. following the ISO 3166 standard. You can also use 3-letter ISO country codes, but it seems that the most commonly used is the 2-letter one.
Then, for UI purposes you would keep another table, which could be a .strings file for localization with the natural language names of the countries:
US = United States;
DE = Germany;
CH = Switzerland;
/* etc. */
On the screen you can translate to natural language:
NSString *isoCountryCode = #"CH"; // Or however you want to set it
NSString *countryName = NSLocalizedString(isoCountryCode, #"Default string if country name not found.");
// Now you can set the country name in human-readable form in the UI
myCountryNameLabel.text = countryName;
In the rest of your code, i.e., the code that handles the data before showing it to the user in the UI, you only use the ISO codes to distinguish countries. Some people refer to this part of the code as the business logic, and as a simple example it could look something like this:
if ( [UserLocation.countryCode isEqualToString: #"CH"] ) {
// Do things needed for Switzerland
}
Internationalization is an extensive topic, and you can find Apple's documentation on it here for iOS. The OS X version is here - but they will be largely identical.
I used Google Places and made a request to this url
"https://maps.googleapis.com/maps/api/geocode/json?latlng=\(userLocation.latitude),\(userLocation.longitude)&key=\(self.googlePlacesApiKey)&language=en&result_type=country"
so it always gives me the results in english independently from the user's language or locale settings
you can change change the information you receive with result_type parameters. Full guide here:
https://developers.google.com/maps/documentation/geocoding/intro#Viewports

SQL fuzzy search and Google-like improvements

Interesting challenge; my client enters some product information in a SQL database. The product is a painting of a famous old Russian composer called Rachmaninoff. So that name is in the description field. Now, only a few of their customers searching for products know exactly how to spell this name, but most of the time it's misspelled. Besides misspelling there are also a lot of international customers who just write this name completely different like, Rachmaninow, Rahmaninov, Рахманінаў.
If i put any of these misspellings or translations in Google it (almost) always knows how to correct it and to redirect me straight to the right page.
Does anyone know what my possibilities are to get some of this magic in my product search? Are there some API's i can use? Some super free text option that i don't know of? Or ...
We solved a similar problem with quite some success: Searching for people (german names) by name given over phone.
E.g.: The very common german last names "Schmidt", "Schmitt", "Schmied", "Schmid", "Schmit" and "Schmiedt" will be all but impossible to hold apart when given by a voice. Combine this with a first name of "Sylvia" or "Silvia" or "Sylvya" and a caller saying "Hi, I'm Sylvia Schmidt, I have forgotten my customer number" has no chance of being quickly found.
Our solution was to put up a list of synophones, e.g. (in pseudo code, for german):
{consonant}+ := {consonant}
ie := i
ii := i
dt* := t
y|j := i
{vocal}v := {vocal}f
etc., you get the drift. Now we stored the synophone-translated strings with the original strings to make search possible. This works really well.
I understand that MySQL has the Soundex() function for English strings. I would expect MSSQL to have something similar.

How to find the most popular Foursquare venue in each category in a given city?

According to Foursquare API, Venues/Explore returns a list of recommended venues near the current location, Venues/Search returns a list of venues near the current location, optionally matching the search term. So in both cases, the return-list is the collection of venues near the current location. Not the global collection for a given city. In this case, how does 'Plan my next trip' find the most suitable place for each category in a given city? Thanks!
You can send a geocodable string (such as the city name) as the near parameter in the Search API, leaving the ll (lat/long) parameter empty. This will search in the entire city and not rank results by distance to a specific point.
From the docs:
near Chicago, IL
required unless ll is provided. A string naming a place in the world.
If the near string is not geocodable, returns a failed_geocode error.
Otherwise, searches within the bounds of the geocode. Adds a geocode
object to the response. (Required for query searches)
You can specify the latitude and the longitude using the ll parameter.