How do you localize static UIApplicationShortcutItems? - ios

I have an application and I want to add a mix of static and dynamic app shortcut items. Localizing for dynamic items is pretty straightforward, using NSLocalizedString, but not so much with the items in your info.plist. I already have an InfoPlist.strings file for localizing the name of my application, but I am less sure about how static UIApplicationShortcutItems would work since these items do not have a unique key.
How do you localize static UIApplicationShortcutItems?

Turns out that the app will search the InfoPlist.strings file for a corresponding key matching the value in the Info.plist. That might sound a little confusing, so here's an example:
For the UIApplicationShortcutItemTitle key in the info.plist, add a value of, say, ADD_ITEM_SHORTCUT_TITLE:
<key>UIApplicationShortcutItemTitle</key>
<string>ADD_ITEM_SHORTCUT_TITLE</string>
This value will then need a corresponding entry in your InfoPlist.strings file:
ADD_ITEM_SHORTCUT_TITLE = "Add Item";

Add one new string file and save it with name "InfoPlist.strings"
Enable Localization for this file, and add string with title like below explanation.
Now Open your info.plist file and add title like below.

Related

How to insert space into a CFBundleDisplayName, IOS

I'm new to IOS and currently I'm working on Localization of Displaying Apps icon.
and I made InfoPlist.strings
and then I put the text for like this in my InfoPlist.strings(MyLanguage) file
"CFBundleDisplayName" = "sometext sometext andlasttext ";
and it literally shows every text, include &#x2007 on iphone emulators home screen.
and of course either
"CFBundleDisplayName" = "sometext sometext andlasttext";
is also not working! could you help me?
This solution works for me before iOS11  consider space as double space.
But from iOS 11 Apple has stopped truncating for longer app names. I thing if app name count is greater then 12 to 14, the spaces will be removed. Otherwise, they'll still exist.
  = 2 spaces
Localizing your app display name is actually a very simple task, so let’s just get right into it.
Set up Localization
First, make sure you set up localization for another language (Note, this is not all that is required to completely localize an app, just the display name). Select your project in the project navigator, go to Localizations, then select a language to localize your display name.
Create a Strings File
Next, you have to create a Strings file that will contain the localized name to be used in your project. Go to File > New > File, select your OS target, go to Resources, and select the Strings file template.
Select the template, enter InfoPlist into the name field, and create the file.
Adding Localized Strings
Once you have created your strings file, open it and select all of the languages you would like to localize for in the inspector. In your base language file, add the following:
/* Localized Bundle Display Name */
"CFBundleDisplayName" = "Your_Localized_Name_In_Native_Language";
Then, enter the same in every other language file, swapping in your translated name in the place of your native name as so:
/* Localized Bundle Display Name */
"CFBundleDisplayName" = "Localized_Name_In_Other_Language";
When you are done, each file should look like the following:
Add Localization Keys to Info.plist
The last thing you have to do is add the necessary keys to your Info.plist file to enable your app to read and swap in your localized display name when appropriate. The first key you will add is the “bundle display name” key, it will look like so:
Bundle display name = $(PRODUCT_NAME)
You also have to add the “application has localized display name” key and set it to yes, which will look like the following:
Application has localized display name = YES
These keys in Info.plist will look like the following:
Thats all there is to it! Your app name will now be displayed in all languages that you localize to.

Put a resource string (from infoPlist.strings) on info.plist

I have my infoPlist.strings with my localizable strings. I want to add on my info.plist the resource I added. How do I accomplish that?
On Infoplist.strings:
"NSAppleMusicUsageDescription" = "My description";
On Info.plist:
NSPhotoLibraryUsageDescription - $(NSPhotoLibraryUsageDescription)
NSAppleMusicUsageDescription - $(NSAppleMusicUsageDescription)
Or changing $ for # is not working either...
Thank you
STEP-I : On Info.plist put the default value
STEP-II : Create Infoplist.strings file and localize it to all supported languages
STEP-III : On each Infoplist.strings file put localized values to every key you want to localize its messages
The application uses the Info.plist key-value as a default value if it didn't find a specific language file. so, you can put English value in the Info.plist file and translate other languages in specific localizable file

NSLocalizedString is returning the key

In my framework app, I have some localization files added and have a method to get
localised strings as follow
-(NSString *)getCurrentLocale{
return NSLocalizedString(#"mykey", nil);
}
and I have installed this pod into one demo app, and trying to get the locale but it always returns the key, (it returns 'mykey')
I have double checked the format and name (Localizable.strings) within the string files
all files has proper format
but I do have locale strings as values in my Localizable.strings
ex: "mykey" = "ar_SA";
any Idea where I am going wrong?
Usually, this happens when you don't have the Localizable.strings file in the appropriate language folder (e.g. de.lproj). Also, ensure you haven't put your Localizable.strings file in the Base.lproj folder, as the same problem will occur.
To summarize, make sure your project Localizations have their Localizable.strings files in their respective language folders to provide the correct translations.
Finally, if the above are true (and this may be obvious), the device must have its locale set to actually pull strings from a given language.
Reference: Internationalization and Localization Guide

Trying to read InfoPlist.strings file... getting the key (?)

As many people don't know, the way to localize an application name on iOS and OSX is to add an InfoPlist.strings file to the bundle and localize that file. People mix this file with the Info.Plist file. Localization is not done into the Info.plist, is done in the InfoPlist.strings file.
Said that, I have created this file with two keys: CFBundleDisplayName and CFBundleName, as I always do. This works wonderfully and you can define different names for your app in different localizations. This file works seamlessly. You have to do nothing, just add the file to the project and localize it.
InfoPlist.strings is a strings file like this:
"CFBundleDisplayName" = "My Localized App Name";
"CFBundleName" = "My Localized App Name";
For this project in particular I have also to read the value of CFBundleDisplayName at run time.
I have tried to use this code:
NSString *appName = [[NSBundle mainBundle] localizedStringForKey:#"CFBundleDisplayName" value:nil table:#"InfoPlist"];
to read the CFBundleDisplayName key but the value I get back is CFBundleDisplayName. In other words, I provide the key and receive the key back, not the value. I should receive My Localized App Name.
What am I missing?
I did this exactly in Swift, and it works as expected.
let appname = NSBundle.mainBundle().localizedStringForKey("CFBundleDisplayName", value: nil, table: "InfoPlist")
but, if I delete de localisation string from the corresponding InfoPlist.strings file, it returns "CFBundleDisplayName".
So, check that you are not missing something in your .strings files
After trying several possibilities..
The BUG was "A second copy of InfoPlist.strings inside the project"

Localizing strings from the Settings.bundle using InAppSettingsKit

I am attempting to use InAppSettingsKit to manage my settings. This uses the Settings.bundle with a .plist file and the .strings files for each of the languages being translated.
I can confirm that the translation of my strings is working properly outside of my application, using the Setting application. But when I am in my application, the translation is not occurring.
I think it comes down to code like this, from the InAppSettingsKit class IASKSettingsReader, with a couple logging statements that I thought my be helpful:
- (NSString*)titleForStringId:(NSString*)stringId {
NSLog(#"%#",[_bundle localizedStringForKey:stringId value:stringId table:self.localizationTable]);
NSLog(#"%#",[_bundle localizedInfoDictionary]);
return [_bundle localizedStringForKey:stringId value:stringId table:self.localizationTable];
}
If I understand correctly, this should be using a table with the name self.localizationTable as the source of the translation. This value is simply "Root". It's not a path to the Root.strings file in the selected language, so I am guessing that the method localizedStringForKey:value:table: must be using some global system reference that points to the correct path.
I have confirmed that the strings file name is "Root.strings" all around, with a capital R, including in the Root.plist file.
[_bundle localizedInfoDictionary] returns (null); It is doing this for two language settings of English and French.
I'm not sure how to debug this. Thanks for any help you can give.
I'm using InAppSettingsKit with localized text with no problems. Two things I can think of that you could check: are your Root.strings files located in the correct subdirectories of Settings.bundle (en.lproj and fr.lproj for English and French?
Is there a "Strings Filename" entry in your Root.plist? It should simply contain a string with value "Root"
It has been quite some time since I resolved this, and at the time, I didn't fully understand it. But, in the interest of closing out this question, I'll point to the following documentation for future reference:
NSBundle Class Reference
which refers to the following:
Resource Programming Guide
In the second document, refer to the section "String REsources -> Loading String Resources Into Your Code"
The solution contains a properly configured Root.strings file, which shows up in the file list like this:

Resources