After adding a few Localizations:
and localized the (AppName)-info.plist file:
and checked Bundle Resources (also tried to remove Go-info.plist from the Copy Resources Bundle list:
and the file property:
Xcode (4.6.3) give an error:
error: could not read data from '.../Go/Go/Go-Info.plist': The file
“Go-Info.plist” couldn’t be opened because there is no such file.
It looks like Xcode ignores the localization folder in the path. It tried to find the info.plist as:
.../Go/Go/Go-Info.plist
instead of:
.../Go/Go/(Localization)/Go-Info.plist
How can I fix it?
I think Info.plist can not be localized. If you want to localize your application Name, you should localize the InfoPlist.strings file and use those keys :
"CFBundleDisplayName" = "AppName";
"CFBundleName" = "AppName";
Step by step localized Info.plist:
Find in the x-code the folder Resources (is placed in root)
Select the folder Resources
Then press the main menu File->New->File...
Select in section "Resource" Strings File and press Next
Then in Save As field write InfoPlist ONLY ("I" capital and "P" capital)
Then press Create
Then select the file InfoPlist.strings that created in Resources folder and press in the right menu the button "Localize"
Then you Select the Project from the Project Navigator and select the The project from project list
In the info tab at the bottom you can as many as language you want (There is in section Localizations)
The language you can see in Resources Folder
To localize the values ("key") from info.plist file you can open with a text editor and get all the keys you want to localize
You write any key as the example in any InfoPlist.strings like the above example
"NSLocationAlwaysAndWhenInUseUsageDescription"="blabla";
"NSLocationAlwaysUsageDescription"="blabla2";
That's all work and you have localize your info.plist file!
Related
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   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.
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"
We use a setup with different plists for each configuration. Like this:
Target-Info-Dev.plist, Target-Info-Beta.plist...
This way our configurations could have their own CFBundleDisplayName, and we can differentiate builds by app-name on device. Like this: "DEV Appname", "BETA Appname"...
However, now we are required to localize the app-name. We have done this by creating a localized InfoPlist.strings for each target:
"CFBundleDisplayName" = "<localized-appname>";
"CFBundleName" = "<localized-appname>";
But since the CFBundleDisplayName is no longer derived from Target-Info-[Configuration].plist, we cannot differentiate the app-name for different configurations.
It should be noted that we have several Targets as well, for different brands of the same app, but we already got that working by haveing a separate InfoPlist.strings for each target.
Anybody have an idea of how to accomplish both localized and configuration-based app-name?
Better Solution
Edit Info.plist, set CFBundleDisplayName's value to a variable named something like $(MY_DISPLAY_NAME)
Open 'Build Settings' tab of the project or target, add a key named MY_DISPLAY_NAME under User-Defined section(you need scroll to the bottom to find this section), then just expand the newly-added key, and set any name for each configuration as you wish.
When building your project, every variable in the Info.plist will be replaced to its value.
The solution is much simpler than the original one.
Original Solution
I had the same requirement in my project, and then I found your question, and at last I solved it.
Edit your projects' scheme, add pre-action and post-action script to execute your change. Like this,
Step 1. change app name in Build's Pre-actions
str=""
if [ "${CONFIGURATION}" == "Debug" ];then
str="dev"
elif [ "${CONFIGURATION}" == "AdhocDevelopment" ];then
str="dev"
elif [ "${CONFIGURATION}" == "AdhocDistribution" ];then
str="adhoc"
elif [ "${CONFIGURATION}" == "DailyBuild" ];then
str="rdm"
fi
perl -pi -e "s/appName[^<]*/appName${str}/g" ${PROJECT_DIR}/smd/Info.plist
Step 2. Restore app name in Build's Post-actions
perl -pi -e "s/appName[^<]*/appName/g" ${PROJECT_DIR}/smd/Info.plist
echo ${PROJECT_DIR}/${INFOPLIST_FILE} > ~/tmp.txt; rm -f ~/tmp.txt
Something to explain: Debug/AdhocDevelopment/AdhocDistribution/DailyBuild are your projects' configuration names; ${CONFIGURATION} is predefined by Xcode; perl is preferable to awk and sed, which are all pre-installed on every mac OS X.
By the way, what I have done is changing appName in Info.plist, you can change your infoPlist.strings. In this way, you just need a single Info.plist file.
Since the file InfoPlist.strings is not just 1 single file, but is spread across multiple folders and files like so: en.lproj/InfoPlist.strings, de.lproj/InfoPlist.strings. It is a bit trickier to use it for different schemes.
Here is how I localized the name of the Today Widget shared by 2 flavors / schemes of the same target. For demonstration purposes, I used 2 "flavors": TA and EC. I will refer to them in this answer.
Step 1:
Create folders for each "flavor" or scheme in the target directory. Name each folder exactly as they are named in your user-defined scheme. Copy there the InfoPlist.strings file.
This step might be tricky. What I did: I created a new folder in XCode and named it TA. I dragged & dropped there my InfoPlist.strings file, then browsed to that folder in Finder, duplicated that folder, and renamed it to EC. Then, I drag & dropped it into XCode. Don't add it to any target. It is not needed.
Step 2:
Remove the InfoPlist.strings from the target's Copy Bundle Resources build phase:
Click on your project name -> Select the widget's target (ex. Today Widget) -> go to Build Phases -> open the Copy Bundle Resources -> find the file InfoPlist.strings, select it and press Delete button
Step 3:
Add a new Run Script to copy the correct InfoPlist.strings file
Here is the script I came up with which will copy the correct file, based on the current flavor/scheme your app is running now:
for lng in en de es fr it nl pt-PT tr
do
INFO_PLIST_FILE="${PROJECT_DIR}/TodayMatchesWidget/${APP_FLAVOR}/${lng}.lproj/InfoPlist.strings"
BUILD_APP_DIR="${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}"
FILE_LOCATION="${BUILD_APP_DIR}/${lng}.lproj/InfoPlist.strings"
cp "${INFO_PLIST_FILE}" "${FILE_LOCATION}"
done
This is a for loop, which iterates through all my localization
languages. You need to put there only the languages that you support.
Each language abbreviation should be separated by a space, nothing
else.
The only variable which you need to take care of is APP_FLAVOR,
which in my case is a user-defined setting inside the project's Build Settings, and in my case will be either TA or EC.
Here is the final folder structure in Today Widget's folder:
P.S:
I assume you already have a InfoPlist.strings file in the target's directory. If not, just add a new Strings File and call it InfoPlist.strings and add this value inside:
CFBundleDisplayName = "My Localized Widget";
I hope it helps anyone out there!
Here's how you can have different InfoPlist.strings for different build configurations in the same target, using only Build Settings and a few duplicate Info.plist files.
In your Build Settings:
Specify a different Info.plist File (INFOPLIST_FILE) for each configuration.
Set Adjust Strings File Names for Info.plist (STRINGS_FILE_INFOPLIST_RENAME) to Yes. On Xcode 14, it was set to Yes by default.
Create .strings files with the base name of your Info.plist filename + Plist.strings.
For example, if your Info.plist filename is Beta-Info.plist, your strings file should have the name Beta-InfoPlist.strings. Make sure you include all of these strings file to your build.
Do not include an InfoPlist.strings file in your target.
The key to making this work is Adjust Strings File Names for Info.plist in the Build Settings Reference.
Adjust Strings File Names for Info.plist.
Setting name: STRINGS_FILE_INFOPLIST_RENAME
If enabled, renames .strings files whose basename matches that of the target’s Info.plist file, to InfoPlist.strings in the built product.
Example
Here's an example in my app which has 3 different variants (AdSupported, AdSupported-Dev, Pro) that require different app names.
Build settings.
Strings files. They are all included in my target.
Info plist files. As usual, they are specified in the Build Settings and NOT included in my target.
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
In iOS project, I changed the target name.
But for building, on the top left (beside stop button), its still showing old target name only... What should I change so that old project name will completely disappear from XCode?
Select your target from TARGETS(in left navigation bar) and double click, then rename it.
Just Click on your target Name beside stop button > Manage Schemes > Select and change name
If you want to change Project Name, Target name, -Info.plist name & -Prefix.pch name then,
- Select Project in Xcode (.xcodeproj file)
- Selecte file inspector
- In identity section change project name which u want to update & press enter
- After scanning whole project it will ask to change the file names i.e target, plist & pch file
- Select check boxes as per your need
Target name(TARGET_NAME)
To change a Target name(TARGET_NAME) you can:
Rename a target via Project Settings(Double click or press Return)
Also after changing Target Name you can:
Rename a schema via Manage Schemas... -> Select -> Press Return
Rename a root Group via Navigator. In this case you should resolve errors that can be caused by out-to-date path. For example:
Info.plist(INFOPLIST_FILE) or
Build input file cannot be found: '<some_path>/Info.plist'
Bridging Header(SWIFT_OBJC_BRIDGING_HEADER) or
error opening input file '<some_path>/<module_name>-Bridging-Header.h' (No such file or directory)
Move umbrella header from private to public scope or
Umbrella header '<name>.h' not found
[Xcode components]
To make the change of target name effective you can go to manage schemes and there, remove all old targets. Then click on "Autocreate Schemes Now"