Localization is not working properly in Xcode 7 - ios

I am using localization in my application. Before Xcode 7, all visuals were traslated without a problem. I ve faced a weird problem with Xcode 7. Some parts of the application is not being translated. For example one of UINavigationItem is not translated. Here is how I translate it like others:
"tdw-ch-DPh.title" = "İletişim";
I have uninstalled the app and installed again and tried to change the translated text to English chars. Not working. As I mentioned, there are only few items not translated. How can I solve this issue?

I think you should use NSLocalization.
Create a string file and say:
Test 1 = "Test String 1";
Test 2 = "Test String 2";
In your code say (for example):
NSString *TheFirstTest = NSLocalizedString(#"Test String 1", #"");
NSString *TheSecondTest = NSLocalizedString(#"Test String 2", #"");
NSLog(#" 1. %# \r 2. %# ", TheFirstTest, TheSecondTest);
And if you want to localize your storyboard, just click localize (Identity Inspector -> Identity and Type -> Localization) and Xcode'll create multiple storyboards in different languages.

Related

XIB localization failed in iPad

My app support Traditional Chinese and English
Now I set my device language as Japanese
Well... In iPhone everything is fine, but iPad localization failed
If I set text used code, it show English when app running
Since app doesn't support Japanese it use English as default language
theLabel.text = NSLocalizedString("theKey", tableName: nil, bundle: Bundle.main, value: "", comment: "")
But if I set text used xib localize
xib base file↓
// English String
"fKW-21-ZWh.placeholder" = "Please fill in your skype ID";
"hyL-A7-fx9.placeholder" = "Please fill in your paypal ...";
// Chinese String
"fKW-21-ZWh.placeholder" = "請填入你的skype";
"hyL-A7-fx9.placeholder" = "請填入你的paypal";
it shows Chinese text when app running
I hope it can use English as default language
do I missing something?
What I did
TARGET -> Info -> Localization native development region = United States
TARGET -> Info -> Localizations = [English, Chinese(traditional)]
PROJECT -> Localizations = [Chinese, English - Development Laanguage]
Delete DerivedData, APP
Clean Project
restart computer
Edit
Edit
I found a Apple tech QA, link
the language that app used is depend on user language preferences
Just select your storyboard/xib, go to File Inspector. In the Localization section, you can tick the language you want.

Reading Localized String

I have an app that I'd like to be able to get the localized string for a certain key, regardless of what my current localization on the iPhone is.
I have the following in an en.lproj localized strings file
"Black" = "Black";
In the es.lproj localized strings file I have
"Black" = "Negro";
So what I would like to do is get the Spanish string when my phone is in the US and set up accordingly
I'm using the following code:
let bpath:String = NSBundle.mainBundle().pathForResource("es", ofType: "lproj")! as String
let bundle = NSBundle(path: bpath as String)
let thisWord="Black"
let ourWord=NSLocalizedString(thisWord, bundle: bundle!, comment: "")
I'm expecting to get "Negro" in the value for ourWord, but I always get "Black"
Am I missing something obvious?
Localization settings apply based on the settings you set in your phone not the location. If your phone is setup to display an Application Language of Spanish then you will see the appropriate string. To configure Application Language settings so you can test this you need to edit your Scheme.
In Xcode 7.1+ Goto Product > Scheme > Edit Scheme
Then change the Application Language and/or Region to simulate what a user would see who has an iPhone configured for a region or language other than English in the US.
(Switch it to Spanish and then debug the app on the device again to see the updated localized strings).
Actually my code works fine. I had made the stupid mistake of not setting the "Localizable.strings" file as localized.
Feeling pretty dumb right now

IOS 8.1 localization not working,only show key not value

First of all,I did this follow this site http://www.raywenderlich.com/64401/internationalization-tutorial-for-ios-2014
I create a new Localizable.strings file,and localize it ,then add English and Japanese support.
I edit my Localizable.strings(en) file as follow:
"APPTITLE" = "Calibrate";
I edit my Localizable.strings(ja) file as follow:
"APPTITLE" = "こんにちわ";
At the source code,the early code :
self.title = #"PianoDisc Calibrate";
instead of :
self.title = NSLocalizedString(#"APPTITLE", nil);
Then I run it,But I get "APPTITLE" not "こんにちわ";
My environment is iPad mini,ios 8.1 system,Xcode 7 or 6.4. I'm also searched long time on the StackOverflow,like as NSLocalizedString only retrieves the key, not the value in Localizable.strings (IOS) ,I have tried the all answer,But it still not work.
There are some info,I use follow code,
NSString *path = [[NSBundle mainBundle] pathForResource:#"ja" ofType:#"lproj"];
NSLog(#"!!!!!!!!!!!!!!!!%#",path);
sometimes get null,sometimes get the true path.
What I'm missing? Thanks anyway!
I resolved it. Some guy remind that "check you haven't somehow messed up with the Build Rules (Xcode 4 -> select your target -> tab "Build Rules") There, check if you don't have too many "CopyStringsFile" rules that aren't using "CopyStringsFile". If so you can remove them all but one."
This step just resolve my problem,thanks god.

font awesome ios icons all the same

I'm trying to use FontAwesome on my ios app (ios8, xcode6), and am having trouble. I've downloaded the font, tried the TTF and OTF versions separately. I've included the font name in my plist file, and have included the NSString+FontAwesome and UIFont+FontAwesome categories that are standard out there.
The problem is that every font awesome symbol showing is always this same one. Everything works, it just never changes the character.
id github = [NSString fontAwesomeIconStringForEnum:FAGithub];
id twitter = [NSString fontAwesomeIconStringForEnum:FATwitter];
label1.font = [UIFont fontWithName:kFontAwesomeFamilyName size:32.f];
label1.text = [NSString stringWithFormat:#"%# %#", github, twitter];
If I use the unicode string directly instead of the helpers, it is still always the same
#"\uf001"
#"\uf002"
// etc
When I debugged the category classes and printed out the unicode array with all the font-awesome codes in the console, all the symbols were identical to the ones above.
[NSString fontAwesomeUnicodeStrings]
Has anyone seen this problem of the repeating symbol, or know a resolution?
EDIT
2 weeks later, after fixing by re-install: I believe the symbol shown is, which was always the same, is the result of the label's font either not being set correctly to FontAwesome, or the font not being loaded so it is not able to be set. That is the symbol that shows up when font is set to something like "System".
Steps taken for this to work:
File > Add File > Added ios-fontawesome in it entirety (copied folder)
Removed all .m files from fontawesome besides NSString+FontAwesome.m from compile sources
Added FontAwesome.tff to info.plist key Fonts Provided By Application
(Compiled for iPhone 5s Sim, 8.1 using XCode 6.1.1)
Test project listed here: https://github.com/spacedrabbit/StackScratchPad
As the comments indicate, this doesn't explain why it wasn't working it just is the way I was able to make it work.

localizedStringForKey:value:table ignores Base localization

My application need to be localised in 2 languages: German and English. German should be Base language. It means that app should always localize to German except the language on device is english (in this case it should be on english)
I have custom *.string files for localisation and use localizedStringForKey:value:table to localise strings.
When I have only base localisation everything works fine. But in case if I add english localisation, in some reason localizedStringForKey:value:table just ignore Base localisation and always use English (for all languages)
Here how it looks like after I've added english:
and here is how I localise strings:
[[NSBundle mainBundle] localizedStringForKey:#"key" value:#"" table:#"Shared"]
I'm testing on simulator and here is my language screen:
Does anybody know what could be a problem? Thanks in advance!
As I mentioned in the comments, you need to set the Localization native development region (CFBundleDevelopmentRegion) in the Info.plist to your language code. Xcode seems to set it to a en_GB or de_DE style region code, setting it to de (no region) will fix it. Note that by default it is en, but selecting United Kingdom or Germany will change it to use the longer codes.
I have another solution, I think it works for you:
NSString* NSCustomLocalizedString( NSString *key , NSString *comment)
{
NSString *rs = nil;
if( [[NSUserDefaults standardUserDefaults] integerForKey:KEY_LANGUAGE ] == e_language_japanese)
{
rs = NSLocalizedStringFromTable(key,#"Localizable.strings-ja",nil);
}
else
{
rs = NSLocalizedStringFromTable(key,#"Localizable.strings-en",nil);
}
return rs;
}

Resources