Get EN,IT,FR,DE,ES Localized City name from google api - ios

In my ios app i'm using this call to get an autocomplete function
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=%#&types=(cities)&key=%s
After that i use another call to retrive details of a place starting by his placeid:
https://maps.googleapis.com/maps/api/place/details/json?placeid=%#&key=%s&language=en&oe=utf8
Now i need to store in my app the city name in localized format (english,italian,french,spanish). I think that i can made a localized place-detail each language i wanna support but i would like to retrive this information with the minimum number of requests. There's a way to get all the localized name of a city starting by his placeid?

I might be wrong on this, but it seems like you can only set one lanugage in the language parameter. Yet, even with that you should be able to make multiple calls like
var langIDs = ["en","it","fr","de","es"];
for(var langID in langIDs){
url = "http://maps.googleapis.com/maps/api/directions/json?origin=34.431741,135.392299&destination=34.631741,135.992299&sensor=false&language=" + langIDs[langID]+ "&";
}
Note, I did not test the code.
Thank

Related

How to get via Organisation service for Microsoft Dynamics the OptionSet value and Formatted value in different languages?

I have a custom .NET application to query and managing data on a Microsoft Dynamics CRM instance.
This application is multilingual and the user can change via a language switch the language of the application.
For the connection and actions I'm using the OrganizationService and CRMServiceClient from Microsoft.Xrm.Sdk. This is combined with dependency injection to pass the connection to our different classes.
With Ninject this bindings look like
Bind().To().WithConstructArgument("crmConnectionString","the connection string");
Querying and updating the data in Dynamics is working but we are not able to retrieve the OptionSet values and Formatted values in the language the visitor have selected in the custom app. This is always in the same language even when we change the culture for the Thread before we call Dynamics.
How can we pass the current language / culture to the OrganizationService so that it knows in what language it have to retrieve the fields?
Someone told me that this is based on the account used to connect to the CRM. So if that's indeed the case then it means that if we have 5 languages that we need to have 5 connection strings and 5 OrgnaizationService instances that need to be called. How should I handle this in a good way in that case?
Thanks for your answers
The solution I implemented was to use CallerId.
Before returning the client I fill the CallerId with a Guid.
The Guid is from a user configured with a specific language in Dynamics.
Based on the language I take a different user.
I don't know if you can pass a culture to the OrganizationService, and I think having different connection strings would work if you want to go this route.
However, you can query the CRM to retrieve the localized labels for the option set you want, as described here.
To sum it up, it's using a RetrieveAttributeRequest, passing the entity logical name and field name and looping trough the result to get the labels.
var request = new RetrieveAttributeRequest
{
EntityLogicalName = "incident",
LogicalName = "casetypecode"
};
var response = organizationService.Execute(request) as RetrieveAttributeResponse;
var optionSetAttributeMetadata = response.AttributeMetadata as EnumAttributeMetadata;
foreach (var option in optionSetAttributeMetadata.OptionSet.Options)
{
Console.WriteLine($"Localized labels for option {option.Value}:");
foreach (var locLabel in option.Label.LocalizedLabels)
{
Console.WriteLine($"Language {locLabel.LanguageCode}: {locLabel.Label}");
}
Console.WriteLine($"Localized description for option {option.Value}:");
foreach (var locLabel in option.Description.LocalizedLabels)
{
Console.WriteLine($"Language {locLabel.LanguageCode}: {locLabel.Label}");
}
}
The code in the link also add caching of already retrieved values, so that you only query the CRM once per option set.

iOS Localization of Server Provided Strings

I need to figure out what is the standard/best practice for displaying localized UI text in an iOS from text that is received from a remote source, such as API driven, server-provided text. iOS Localization of static text is not a problem and we already have a system for managing that.
It seems to me the right and best thing would be to have the translated text sent by the server and displayed as received on the app, but there are some concerns about doing it this way, such as the app's locale/current language being possibly different than the current settings on the server. This presents the possibility that there may be a mismatch in dialect or language between what the phone is currently set to and what the server is set to. Also, we are considering how having the server do this breaks any of the S.O.L.I.D. design principles.
So, it comes to two possibilities. Either the server provides the translated text or the app does.
We could possibly provide a parameter to the server that would indicate which locale the device is set to (ie "en-us"). I imagine that this would be sent as an HTTP request header parameter.
It has also been suggested that the mobile app provide similar functionality for itself. This would involve maintaining a data store of some kind (tbd) so that display strings would be given to a facade and translated strings would be returned. ie: func translate(uiText: String) -> String. Internally, it could determine the user's locale and use that as part of the query needed to select the correct translated text. Again, the implementation of this would have to be decided, but that's not the problem I'm hoping to find a solution for.
To sum it up, what I really need is to know what is standard practice for translating server provided text that is to be displayed to the user and are there any frameworks out there designed to assist with this requirement (assuming the solution should exist in the mobile app)?
It seems to me that this is functionality best provided by the server. Also note that we have an Android app that would require similar enhancement.
I think I found a solution to this question but I do not want to mark it as the accepted answer unless I can get some feedback reinforcing what I have learned.
Most of the research I've done has lead me to what works for Web development, which is similar because it's still development but a much different creature than mobile. Mobile is compiled, which makes the advantages and disadvantages of where to do the presentation logic balance a little differently.
Some sources said it belongs on the server where it came from. Some sources said the client should do it. (I'll post references at the end.)
I opened up a discussion amongst my colleagues on the topic and this is where I found what I think will be our best solution. (Comments and criticisms are certainly welcome.)
I'll refer to data provided by the server through the API here forth as just "server".
For every string that the server provides that is meant to be displayed in the UI, I need to have some way to define these strings statically in the iOS app. Ideally I think an enum per display string would work. I can wrap every string with NSLocalizedString in the definition of the enum. Make the enum a String type, and initialize an instance of the enum from the string received from the server. The enum will return the NSLocalizedString. The iOS Localization system should export all of those localized strings, I will receive translations, and they will then exist in the various respective .strings files.
EG:
enum Emotion: String {
case happy = "Happy"
case sad = "Sad"
case angry = "Angry"
case joy = "Joy"
case amused = "Amused"
case bored = "Bored"
case undefined = ""
func translation() -> String {
switch self {
case .happy:
return NSLocalizedString("Happy", comment: "Happy")
case .sad:
return NSLocalizedString("Sad", comment: "Sad")
case .angry:
return NSLocalizedString("Angry", comment: "Angry")
case .joy:
return NSLocalizedString("Joy", comment: "Joy")
case .amused:
return NSLocalizedString("Amused", comment: "Amused")
case .bored:
return NSLocalizedString("Bored", comment: "Bored")
default:
return "--"
}
}
}
Implementation:
let thisCameFromTheServer: String? = "Happy"
let emo = Emotion(rawValue: thisCameFromTheServer ?? "") ?? .undefined
References
https://softwareengineering.stackexchange.com/questions/313726/where-should-i-do-localization-server-side-or-client-side
https://softwareengineering.stackexchange.com/questions/373395/api-internationalization
https://www.appliedis.com/localization-of-xcode-ios-apps-part-1/

How can the actual displayed language's culture info be retrieved in Windows Phone?

If the selected phone language isn't supported by an application it will fall back to the neutral language. How can this be detected in code? The CultureInfo.CurrentUICulture will always return the language selected in the phone settings.
One way to achieve this goal could be to add a string to each resource file with the culture identifier of it. That is, add an entry to the resource file, for example with the name ResourceLanguage and the value (e.g. "en-US" if English etc.).
Then you can retrieve the value in your code:
var language = AppResources.ResourceLanguage;

JSF Strategies For Long Lists in SelectOneMenu e.g. TimeZones

I am implementing a way for a user to specify their timezone. Nothing new there. I want to hear what people say is a good strategy for handling cases when users need to select from a list of a couple hundred choices, but might not know the correct value for it in the list right away. I know I can use something like autocomplete, but that only works if people know what they are looking for. Sure countries should be obvious but... lowest common denominator (some people are dumb... like me ;).
There are something over 400 distinct iso timezones (not including things like EST, PST, etc. which I am not including). That is a long list. It can be conveniently divided if we let the user chose the country they are in first in say, another selectonemenu. But there are more than 200 countries. So how to present 200 countries that is easy and efficient to work with?
I have already created and packaged in a jar a number of classes to read from the Olson timezone files (iso3166.tab and zone.tab) and provide arraylists of timezone and and timezonecountries, including prioritizing specified countries to the top of the list. But now I would like to maybe learn a better way to present the countries and the timezones. I did this myself since I found it an easier and cleaner way to extract and correlate country codes and timezone codes.
For your particular requirement, I can think of using a world map like you see in a Linux distro like Ubuntu centered at Greenwich. Then placing markers for the data that you have and letting the user select the nearest marker.
See Timezone selection for Ubuntu
For this you can make use the Primefaces GMAP component and add an overlay like this:
LatLng coord1 = new LatLng(36.885233, 30.702323);
PlaceResult placeResultObj1 = new new PlaceResult("660")
//Basic marker
simpleModel.addOverlay(new Marker(coord1, "Konyaalti", placeResultObj1));
PlaceResult.java
public class PlaceResult {
private String utc_offset;
public PlaceResult(String utc_offset){
this.utc_offset = utc_offset;
}
public String getUtc_offset() {
return utc_offset;
}
public void setUtc_offset(String utc_offset) {
this.utc_offset = utc_offset;
}
}
Another approach is to use the Places library from Google maps. Using that you can get the google.maps.places.PlaceResult object by various methods, I like the autocomplete feature where you can choose the city. After a city is selected you can show the utc_offset in the infowindow.
You can take a look at this demo
Currently, it seems that most of the cities don't have utc_offset already set. One of the address I found that had utc_offset was
Newy Airport Transport Shuttle in Australia. Then you can pass the off_set as a input hidden parameter to submit the value to the server.
See also:
Google Places Library

Retrieving a country telephone code for a specific country in iOS

I'm quite new to iOS development and I'm currently building my first app.
I'm trying to get a text field to automatically populate the telephone country code for a specific country.
So if for example the user picks "UK" he gets "+44" inserted automatically into that text field.
Currently I'm struggling a way to find how to get the exact country telephone code for the country.
I could create an NSDictionary with all of the countries and country telephone code but I thought there might be a better way.
If your goal is to get the dialling code of the user's current location then you should use HMDiallingCode.
It uses CoreLocation and reverse geocoding to get current country of the user and then retrieve it's dialling code.
I think, you can only get country code for the current Carrier using CoreTelephony framework:
CTTelephonyNetworkInfo *info = [CTTelephonyNetworkInfo new];
CTCarrier *carrier = info.subscriberCellularProvider;
NSLog(#"country code is: %#", carrier.mobileCountryCode);
If you need a full list of codes for all countries, you need to use some online service for querying it.
I'm afraid there is not a better way. My app include a .plist file with the array of countries with name, code, phone code, trunk code, etc for each. You will not get all that info from iOS API.
If you only need the international phone code for a country code, here you are a link with a complete table.

Resources