Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSLocationWhenInUseUsageDescription localization using .strings file not working

I've completed translating my app to Turkish using Base Localization. However, I also need to translate NSLocationWhenInUseUsageDescription key in my Info.plist file. I did exactly what I did for everything else:

Went to File inspector and checked Turkish:

enter image description here

Then I went to the new strings resource and completed my translation by adding this key to the localization file:

enter image description here

"NSLocationWhenInUseUsageDescription" = "[my Turkish description of location permissions]";

Saved, compiled, even deleted app from device and rebuilt, but no avail. When my app asks for location permissions, the explanation underneath is still the English one (I've tried including the English translation as well under Base translation file, but it didn't change anything).

Everything else is Turkish, translated just fine. It's just the location permission that doesn't translate. I've also seen How to localise a string inside the iOS info.plist file? and added the "Localized resources can be mixed" = YES key (of course, as CFBundleAllowMixedLocalizations, not literally that sentence) to my original plist but that also didn't change anything.

How can I solve the problem?

like image 275
Can Poyrazoğlu Avatar asked May 26 '15 09:05

Can Poyrazoğlu


People also ask

How do you localize a string inside the iOS Info plist file?

To do this, go to File->New->File , choose Strings File under Resource tab of iOS , name it InfoPlist , and create.

How do you perform localization in iOS Swift?

Click on iOS->App/Single View App->Next. Name your project and select the language as Swift. Select a desired location and click on Create. To start with Localization, click on your Project Name -> go to Info Tab -> Under Localizations, click on the '+' button.

What is NSLocationWhenInUseUsageDescription?

NSLocationWhenInUseUsageDescription. A message that tells the user why the app is requesting access to the user's location information while the app is running in the foreground.


2 Answers

Here's what ended up working for me in Xcode 7.1.

First, go to project directory and manually create two InfoPlist.strings files, the first inside the en.lproj folder and the second inside the fr.lproj folder.

Both files should have the following content :

NSLocationWhenInUseUsageDescription = "YOUR TEXT HERE";

Since the files won't show up automatically in Xcode, you have to manually add both to the project bundle, this can be achieve via right-clicking the project name in Xcode and choosing the Add files to X option, then selecting the files you just created.


Also if you want to test the result & make sure things work, changing the Application Language in Edit Scheme > Run > Options isn't enough.

You need to change the simulator or the device language via Settings > General > Language & Region > iPhone Language

like image 97
Zakaria Braksa Avatar answered Sep 21 '22 22:09

Zakaria Braksa


I've started over. Removed the translations, cleaned the project, and tried again. It worked. I have no idea why it didn't initially though.

like image 24
Can Poyrazoğlu Avatar answered Sep 19 '22 22:09

Can Poyrazoğlu