Question

I am building an Weather iPhone App. I am using an API which gives the Response in English. Now what I want to do is translate the Response to German. Is that somehow possible? I have already translated Time and Weekdays like this:

- (id)init {
if (self = [super init]) {
    _hourlyFormatter = [[NSDateFormatter alloc] init];
    _hourlyFormatter.dateFormat = @"h a";
    _hourlyFormatter.locale=[[NSLocale alloc] initWithLocaleIdentifier:@"de_DE"] ;
    
    _dailyFormatter = [[NSDateFormatter alloc] init];
    _dailyFormatter.dateFormat = @"EEEE";
    _dailyFormatter.locale=[[NSLocale alloc] initWithLocaleIdentifier:@"de_DE"] ;


}
return self;
}

Ah and the Interface is completely code based so no Interface files if that is needed (Which I don't think but you never know, hu?)

So in my case I want to translate the condition. For Example Clear or Rain.

Could you maybe hall me with that? The API that I am using is the openweathermap.org one.

Was it helpful?

Solution

If you want the app to translate the text automatically, the system doesn't have support for that, but there are some APIs you can use for that:

Language Translation API for iPhone

The other option is translating the text yourself, with NSLocalizedString. In the code you could have something like:

newString = NSLocalizedString(originalString, nil);

NSLocalizedString will search for a translation to that string in a .strings file.

For this to work, you must create and fill the .strings file. Then you need to select the languages you want for your project, and localize(translate) that .strings file.

Here is a nice tutorial on how to do this (you only need the first parts): http://www.raywenderlich.com/2876/localization-tutorial-for-ios

After that, if your device is in german language, the text will appear in german too. And you can easily add other languages if you need it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top