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";
Related
I am looking to add multiple languages to my app and so I have created the different String files and have added them to my localisations. I have a settings page in my app where I want them to be able to select the language the app is in, and the whole app is changed.
VStack{
Button("English"){
//set app to English
}
Button("Francais"){
//set app to French
}
Button("Cymru"){
//set app to Welsh
}
.....
}
I've found the modifier .environment(\.locale, init(identifier: "en")) but I believe this modifier needs to be added to every view and I was wondering if there is an easier way to do this? I want the language to be saved to user defaults too.
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
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.
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
Connected issue: Non-English default language for iOS App?
I am wondering how to check the current localization of my app in code.
For example:
I want to check if the app is running with German localization (.strings, storyboard)
This line of code:
[[[NSLocale preferredLanguages] objectAtIndex:0] isEqualToString:#"de"]
doesn't provide the correct answer. Because if a user's language list in device settings looks like this for example (french, german, english) and we have only localization for english and german, application is launched in german but the above condition isn't fulfilled.
My naive solution would be to create a localized string "LanguageCode" which is set to "de" in the german string file and to "en" in the english string file
e.g.:
if ([NSLocalizedString(#"LanguageCode", #"en, de etc.") isEqualToString:#"de"]) {
// german
}
NSString * language = [[NSLocale preferredLanguages] objectAtIndex:0];
This will return a two letter code for the currently selected language. "en" for English, "es" for Spanish, "de" for German, etc. For more examples, please see this Wikipedia entry (in particular, the 639-1 column):
Check the first entry of Bundle's preferredLocalizations property, which is:
an array of NSString objects containing language IDs for localizations
in the bundle. The strings are ordered according to the user's
language preferences and available localizations.
For example, if you're checking to see if your German localization are being used:
if Bundle.main.preferredLocalizations.first == "de" {
// Is using German
}