XIB localization failed in iPad - ios

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.

Related

Is there a way to set English as a default language

I localized my app for 2 languages (EN, FR). When iPhone language set to English, app shows up in English. When iPhone language set to French, app shows up in French. But when iphone language set to another language lets say Spanish app shows up in French not in English.
I set "Localization native development region" to "en" or "United States" in my Info.plist file but didn't help.
Main.storyboard (Base) also in English.
Solution:
One way to do it is to get the English string from en.lproj if the preferred language does not match en or fr.
This is how you get the preferred language:
let preferredLanguage = Locale.preferredLanguages[0]
This is how you get the English string using your localized key:
if let enPath = Bundle.main.path(forResource: "en", ofType: "lproj") {
let enBundle = Bundle(path: enPath)
enBundle?.localizedString(forKey: "your_key_here", value: nil, table: nil)
}
Explanation of your problem:
In iOS native Settings App -> General -> Language & Region, there is a Preferred Language Order list.
Apps and websites will use the first language in this list that they
support.
For example:
Set "French" as your iPhone Language.
Open the App and everything is localized in French because your app does support French.
Set "Spanish" as your iPhone Language.
Open the App and everything is localized in French because your app does not support Spanish and it'll fall through your next preferred language which is French in this case.
Just set developer language to English
YOURPROJECT.xcodeproj -> show package content -> Editing the .pbxproj file directly using a text editor - look out for the developmentRegion property
And change the Localizations native development region property in the Info.plist accordingly en Or bellow image
once your result like this then you setup successfully :
]1

String localization for framework

I'm building a framework that includes UI components. I'm retrieving localized strings with:
var bundle = Bundle(identifier: "com.my.identifier")
bundle.localizedString(forKey: "myKey", value: nil, table: nil)
The problem I'm seeing is whatever parent application integrates with my framework, must also have localization enabled for my same localizations (e.g. if I have localizations for es-ES, the parent application must also turn on localization for es-ES in project settings:
Otherwise my localized strings always default to english.
I have found a workaround by manually grabbing a language bundle based on the device's preferred language:
var bundle = Bundle(identifier: "com.my.identifier")
guard let deviceLanguage = Locale.preferredLanguages.first else {
return notFound
}
guard let languagePath = bundle.path(forResource: deviceLanguage, ofType: "lproj") else {
return notFound
}
guard let languageBundle = Bundle(path: languagePath) else {
return notFound
}
return NSLocalizedString(self, tableName: "Localizable", bundle: languageBundle, value:"KEY_NOT_FOUND", comment: "")
But the issue with this workaround solution is that I lose the built-in iOS language fallback (e.g. if the device preferred language is es-MX it will auto-choose the es-ES string over the en string I have).
For my framework, is there a way to avoid forcing parent applications to turn on localization for all my localized strings, yet still keep iOS language fallback logic?
Why do you want your framework to use a localization not supported by the app? This is a terrible user experience.
Imagine app that uses your framework only supports English and Spanish. Now imagine that a user of the app have their device setup to use German first, and English second.
Since the app doesn't support German, the app shows English. The entire app should show English. If your app framework manages to show German in this case, the app's user experience is now very confusing because much of the app is in English but the parts supported by your framework appear in German.
tl;dr - Don't do anything. Let the default behavior work as-is. It makes for a much better user experience.

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

Localization is not working properly in Xcode 7

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.

iOS accessibility - How to localize VoiceOver language

My app is in the process of becoming localized for a few languages and regions. How Do I localize the voiceOver (its a accessbility feature for the blind). I want the language of voiceOver and voiceControl to change based on the users selected language ?
in my info plist the Localization native development region (CFBundleDevelopmentRegion) is already set to en_us as a fail safe if no language is found to localize to.
So to make it clear, i want to know if i localize all my strings in the app will the voiceOver use the localization in my app ?
In viewDidLoad
changeNationButton.accessibilityLabel = NSLocalizedString ("Change Nation", comment: "Accessibility Label: Button to change Nation")
changeNationButton.accessibilityHint = NSLocalizedString ("Tap to Change Nation", comment: "Accessibility Hint: Button to change Nation")
then localize it as a normal String in localizable.strings
"Change Nation" = "Cambia Nazione";

Resources