How to insert space into a CFBundleDisplayName, IOS - 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.

Related

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"

How do you localize static UIApplicationShortcutItems?

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.

How to localize my app with Xcode 5?

This is a follow up question (and answer) on the How to localize my app with Xcode 4? question.
How do I localize my app with Xcode 5.x?
It's quite simple once you understand it.
The first thing you want to do is add a localization file to your project.
To do so, simply select your project's main group
,
then, from the toolbar, select File → New → File... (or just hold down ⌘N)
.
Under the Resource category, select Strings File ,
and name it Localizable.strings (note that it is case sensitive) .
Now that we have our localizable file, we can click on the Localize... button, in the File Inspector
.
Xcode is going to ask you if you want to localize the file, just click on Localize with Base selected
.
Now this next part is a bit tricky. We need to enter our project's Info section, to do so, click on the project file in Xcode's Navigator, then to your right you'll see a category named PROJECT, click on your project file under this category
.
Now we can add our desired language under the Localizations category. I'll add Norwegian
.
It's important that we only leave our Localizable.strings file checked in the menu that appears
.
Now we can expand our Localizable.strings file in the Navigator to see our localizable files
.
We now how our Base file (within our Localizable.strings file), which will be our app's "main language", and our previously selected language.
It's important to know that the structure of these files needs to be identical. You'll see what I mean in just a sec.
In our Base, I'll add a string named it_worked, and add it's localization
.
And in our previously selected language (In my case Norwegian), i'll add the same string it_worked (to keep the structure), but with a different localization
.
Now that we have our localized file, we can make our app read it when needed.
I added a UILabel to my app, so that we can make our app display the localized text.
[myLabel setText:NSLocalizedString(#"it_worked", nil)];
Now if I launch my app, we'll see our base language
,
and if I change the language of the simulator to Norwegian, we'll see our other language
.
You don't need to add the uilabel and change the text on code.
You can take advanced of the User Defined Runtime Attributes:
http://cupobjc.blogspot.com.es/2014/04/interfaz-builder-localization.html
First define a new category for UILabel:
#import "UILabel+Localized.h"
#implementation UILabel (Localized)
-(void) setTextLocalized:(NSString *)aText{
[self setText:NSLocalizedString(aText, nil)];
}
#end
Then in the interface builder, User Defined Runtime Attributes :
textLocalized String your string to localized

How to implement language Translation in iPhone app?

I need to implement language translation in my app. Could anybody tell how to do that. Actually i am not able to find APIs for it and google translation API v2 is paid.
To localize strings in your code:
-Create a new Localization.strings file
File -> New File -> iOS -> Resources -> Strings file
-Select this file and Show the file inspector
Command + Option + 1
-Click the add button under localization and add a default language (I expect English) and the other languages you want.
-You'll notice that you have a little arrow next to your Localizable.strings file, if you click it, you can see the languages that you've added.
-For each phrase you want to translate, use the following syntax:
"key" = "value";
"hello" = "bonjour";
-In your code where you want to use the translation, use NSLocalizedString(#"hello", #"hello"); (The second parameter is a comment, it doesn't matter what value you use here)
When it comes to nibs, you'll need to manually change the strings and re-arrange the text fields etc in each nib.

Resources