سؤال

I have made an ios app that is localized to two languages (english and danish, english being default).
I have made a Localizable.strings with two subfiles, en and da.
Everything should be made correctly, and i see the english texts load fine from the strings file. But the danish ones do not.

I have tried to check the preferred language via below code and it is danish.

[[NSLocale preferredLanguages] objectAtIndex:0];

I have tried clean + delete and rebuild with no luck.

I know that the Localizable.strings file is working since it is getting the english texts. and i know that it is seeing the danish localization via the above line of code. What am i missing?

Just to add a couple of examples:
from the EN:

"YesButton" = "Done";
"NoButton" = "Not yet!";
"NextButton" = "Next";
"BackButton" = "Back";
"EditButton" = "Edit";
"DoneButton" = "Done";  

and the DANISH:

"YesButton" = "Færdig";
"NoButton" = "Ikke endnu!";
"NextButton" = "Næste";
"BackButton" = "Tilbage";
"EditButton" = "Redigér";
"DoneButton" = "Færdig";

and the code for getting the text would be:

[yesButton setTitle:NSLocalizedString(@"YesButton", nil) forState:UIControlStateNormal];

which is returning "Done" even when preferredLang is da (danish)!

Hope somebody has an idea? :)

Thanks in advance.

EDIT:::
Something was wrong with the actual DANISH-DENMARK localization. i dont know if apple updated it or what they did but it went from being called "Danish-Denmark" to just "Danish". After making a whole new Danish localization and deleting the old one it worked! crazy stuff. keeps you scratching your head!

هل كانت مفيدة؟

المحلول 3

There was something wrong with the actual danish localization.
When i started making the localization it was called "Danish-Denmark". After an update of ios and/or xcode, it is now only "Danish".
So had to make a whole new localization.

Thank you apple...... NOT!

نصائح أخرى

I had similar thing happened to me before. All I did to fix the problem was to change the string encoding from:

encoding:NSASCIIStringEncoding

to

encoding:NSUTF8StringEncoding

~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

Now assume the problem is not string encoding. You can also work around it and do something like:

NSString * language = [[NSLocale preferredLanguages] objectAtIndex:0];

NSString yesButtonStr=@"";
NSString noButtonStr=@"";
NSString nextButtonStr=@"";

if([@"en"  caseInsensitiveCompare:language] == NSOrderedSame )
{
yesButtonStr = @"Done";
noButtonStr= @"Not yet!";
nextButtonStr = @"Next";
//...
}
else if if([@"da"  caseInsensitiveCompare:language] == NSOrderedSame )
{
yesButtonStr = @"Færdig";
noButtonStr = @"Ikke endnu!";
nextButtonStr = @"Næste";
//...
}

Then:

[yesButton setTitle:NSLocalizedString(yesButtonStr, nil) forState:UIControlStateNormal];

Try this,

NSString *translatedString = [self languageSelectedStringForKey:@"YesButton"]; // Give your key here

-(NSString*) languageSelectedStringForKey:(NSString*) key
{
    NSString *path;
    path = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"]; // give your language type in pathForResource, i.e. "en" for english, "da" for Danish
    NSBundle* languageBundle = [NSBundle bundleWithPath:path];
    NSString* str=[languageBundle localizedStringForKey:key value:@"" table:nil];
    return str;
}

Hope this helps, Thanks. Happy coding

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top