I am working on xcode4 and created a Settings.bundle for my project. I can edit the Root.plist file in xcode4 but it is not possible to edit the Root.strings file. It isn't even displayed in the editor.
I can not expand the en.lproj folder as you see in the picture.
But when I do right-click, open in external editor it gives me:
Double click on Root.strings gives me:
I tried it several times, creating a new window-based application project and creating a new Settings.bundle. I always can not localize it. Any ideas?
In XCode 4.2 you have to follow this steps (just a modification of Xcode 3.2.2 and localization of Settings.bundle)
Reveal your Settings.bundle in Finder.
Right click (or Ctrl-click) on it and select Show Package contents.
Create a new folder called as the desired language (e.g., fr.lproj).
Copy the Root.strings file from the en.lproj folder and paste in fr.lproj folder.
EDIT: Apple fixed, once again, the wrong bug. Their change rendered my workaround useless. It just doesn't work anymore, you can't add files to the Settings.bundle.
Please refer to the answer of Javi for a method that seems to work.
I hope you like ugly workarounds.
Right click on the settings bundle in the side bar.
Select New File
Pick Resource / Strings file
Name it Root.strings, make sure it is placed inside settings.bundle
In the side bar the file will be visible twice. In the "root" section, and in the Settings.bundle. But both point to the same files.
Select the Root.strings file in the root section. (AFAIR you have to convert it to UTF16)
Add localization, xcode will ask you if you want to replace the file. Yes, you want this.
Add as much localizations as you want. You should be able to edit the file in the root section of the sidebar.
I hope this works for you, for me it does.
And if you haven't done it please report the bug at bugreport.apple.com
I'll install the new release now, let's see if this is fixed. Edit: Not fixed.
EDIT: I don't know If I understood your second question correctly. But when you add a localization to the file that appears outside of the bundle it adds a localization folder to the settings.bundle
After adding spanish localization to Root.strings:
The actual file is in the foo.lproj folder, it just doesn't show them in the xcode sidebar. If you check the location in the file system you'll see they are inside the settings bundle.
Yesterday I checked with a english and german file and it worked correctly in the simulator. I guess it's just a wrong sidebar layout. The underlying locations and the handling of the files seems correct.
For me it worked to change the File Type (in the File Inspector) of the Folder "en.lproj" from "Default / Directory" to "Directory". Magic.
Xcode 4 is creating the "Root.strings" as a binary property list. so what I had to do was set the file type to "Property List (binary)" for it to show up correctly.
I have just given up trying to do something with Root.strings. Instead, I just copied the plist into each *.lproj, and it worked!
As far as this is about translation into English and my native language, no problem.
So I have:
Settings.bundle
|- en.lproj
| |- Root.plist
| `- Root.strings -- nothing useful there
|
`- zz.proj
`- Root.plist
The good news is that Root.plist is utf8.
If you already have a Root.strings file that is a "Property List (binary)" and you wish to convert it to a proper text-based strings file, you can use plutil in the Terminal application to convert it, for instance into JSON format:
> plutil -convert json /path/to/Settings.bundle/en.lproj/Root.strings
N.B. You can run plutil -h for usage help.
However, you will then need to convert the JSON format:
{"key1":"value1","key2":"value2"}
to that of a strings file:
"key1" = "value1";
"key2" = "value2";
This is easily done with a few search/replace operations in a text editor.
Related
I have a stand alone SPM (local) in my project. When ever I add any new files to this package Xcode does not show the prompt to specify the name. Usually when adding files in a project it requests the location which allows to specify a name. But when adding in a SPM it straight away creates a file with File.swift always.
I don't mind renaming but its just that the header is also having a generic File.swift
//
// File.swift
//
//
// Created by McDuck, Scrooge on 02/06/89.
//
Any work arounds ?
I have tried on Xcode 13.4 as well
#user5381191 I had the same problem. I did some searching and found this answer.
The file you want to edit is located in:
/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates/Source/Package Swift File.xctemplate. Edit the TemplateInfo.plist.
As a test I just copied the TemplateInfo.plist file from the Multiplatform/Source/Swift File.xctemplate and it worked. EDIT: For some reason it worked, and then stopped working?
Copy the suggested plist text from the link above into your template file and it works!
Once I did that, I get a new file type "Package Swift File" in the New File dialog.
Instead of the standard file dialog, it gives a dialog for entering the file name. Better than before!
Make sure to save your old template file before making your changes, just in case you need to revert.
It doesn't insert the package name in the header. That might be a nice thing to try and get working, but I'm happy with this for now.
Actually it works as promised (according to Apple guidelines).
In this scenario (as shown on demo) a menu command without ellipsis (...), so no dialog expected.
Once file created Xcode enters edit-name mode, so we can specify a file name which we need.
The file hat is different question and can be edited in templates if needed, or not. Usually depends on project and might even not include file name at all, but for default template - yes we need to change it to align.
Tested with Xcode 13.4
How do I rename a project in Xcode 5?
What steps do I need to take?
In the past this was always a very tricky manual process.
Well, the answer is very very very Apple simple in Xcode 5!
In the Project Navigator on the left side, click 2 x slowly and the Project file name will be editable.
Type the new name.
A sheet will appear with a warning and will list all the items Xcode 5 believes it should change.
You can probably trust it, but you should inspect it.
The list will include the info.plist and various files, but also all the relevant strings from nib/xib files like MainMenu menus.
Accept the changes and you will get the prompt to save a snapshot of the project.
Always make a snapshot when Xcode asks, it will be useful to restore if something does not work.
Change the project name:-
Click on the target in xcode, on the right in "Identify and Type" under name change the name and press the ENTER button on your keyboard.
A window will appear confirming the change and what it will change. Once you confirm it will make the changes.
Change the root folder name:-
Go to the project directory and rename the root folder,
Open the project and u will find all the file are missing, u need to add all the files of project again
Right click the project bundle .xcodeproj file and select “Show Package Contents” from the context menu. Open the .pbxproj file with any text editor.
4>Search and replace any occurrence of the original folder name with the new folder name.
5>Save the file.
Change the Scheme name:-
rename .xscheme file
If your Project is static framework then make sure your header file has public target membership
I really recommend just opening the folder in a general editor such as Sublime Text, and doing a find/replace across the whole folder. The other methods I found were unstable, particularly when combined with .xcworkspace and cocoapods.
In Xcode 8.0, to rename your project, just go through the following instructions as described in Xcode help:
1- Select your project in the project navigator.
2- In the Identity and Type section of the File inspector, enter a new
name into the Name field.
3- Press Return.
A dialog is displayed, listing the items in your project that can be
renamed. The dialog includes a preview of how the items will appear
after the change.
4- To selectively rename items, disable the checkboxes for any items
you don’t want to rename. To rename only your app, leave the app
selected and deselect all other items.
5- Click Rename.
Source: http://help.apple.com/xcode/mac/8.0/#/dev3db3afe4f
Xcode 6 (beta 6 as of now) seems to be not very reliable with renaming projects. For me it didn't rename several of the files and groups. It also doesn't rename the physical folder the project is in. To rename my project to be sure that everything is clean I went the extra length to create a new project with the new name and copy over all the files. The assets are easy to copy but groups have to be recreated. The biggest issue with this however are CoreData data model files. Trying to simply copy this will result in a corrupt model file, even though everything looks like it is alright.
When you re-name the project name in XCode5 then info.plist entry removed from Targets --- > General ---> identity. You just need to mention it again.
In Xcode 7, renaming a project can still break your app. Make sure you backed it up before trying it.
Click on the project icon and find the project name in the inspector pane. If you change it there, Xcode will ask you if you want to rename related files. Might work. But if not, try this brute force approach:
Close Xcode
Using an advanced text editor like Sublime Text or Atom, open the
root folder. It will open the folder structure.
Perform a Global Search and Replace (it's probably cmd + shift + f), and
replace My Wrong App Name with New App. If your project name contained spaces, also search for My_Wrong_App_Name and replace
with
New_App. This changes all file contents.
Now you need to find all
the files inside the project with your old app name. Rename them
all, also the folders.
Important: Open the project file with
right click > Show Package Contents, and rename all files in there.
Reopen your Xcode project or workspace. Compile.
If you use Pods, you need to open the pods project as well and change the files in there.
Here is another great example which works well with xcode 5
How do I rename a project in Xcode 5?
What steps do I need to take?
In the past this was always a very tricky manual process.
Well, the answer is very very very Apple simple in Xcode 5!
In the Project Navigator on the left side, click 2 x slowly and the Project file name will be editable.
Type the new name.
A sheet will appear with a warning and will list all the items Xcode 5 believes it should change.
You can probably trust it, but you should inspect it.
The list will include the info.plist and various files, but also all the relevant strings from nib/xib files like MainMenu menus.
Accept the changes and you will get the prompt to save a snapshot of the project.
Always make a snapshot when Xcode asks, it will be useful to restore if something does not work.
Change the project name:-
Click on the target in xcode, on the right in "Identify and Type" under name change the name and press the ENTER button on your keyboard.
A window will appear confirming the change and what it will change. Once you confirm it will make the changes.
Change the root folder name:-
Go to the project directory and rename the root folder,
Open the project and u will find all the file are missing, u need to add all the files of project again
Right click the project bundle .xcodeproj file and select “Show Package Contents” from the context menu. Open the .pbxproj file with any text editor.
4>Search and replace any occurrence of the original folder name with the new folder name.
5>Save the file.
Change the Scheme name:-
rename .xscheme file
If your Project is static framework then make sure your header file has public target membership
I really recommend just opening the folder in a general editor such as Sublime Text, and doing a find/replace across the whole folder. The other methods I found were unstable, particularly when combined with .xcworkspace and cocoapods.
In Xcode 8.0, to rename your project, just go through the following instructions as described in Xcode help:
1- Select your project in the project navigator.
2- In the Identity and Type section of the File inspector, enter a new
name into the Name field.
3- Press Return.
A dialog is displayed, listing the items in your project that can be
renamed. The dialog includes a preview of how the items will appear
after the change.
4- To selectively rename items, disable the checkboxes for any items
you don’t want to rename. To rename only your app, leave the app
selected and deselect all other items.
5- Click Rename.
Source: http://help.apple.com/xcode/mac/8.0/#/dev3db3afe4f
Xcode 6 (beta 6 as of now) seems to be not very reliable with renaming projects. For me it didn't rename several of the files and groups. It also doesn't rename the physical folder the project is in. To rename my project to be sure that everything is clean I went the extra length to create a new project with the new name and copy over all the files. The assets are easy to copy but groups have to be recreated. The biggest issue with this however are CoreData data model files. Trying to simply copy this will result in a corrupt model file, even though everything looks like it is alright.
When you re-name the project name in XCode5 then info.plist entry removed from Targets --- > General ---> identity. You just need to mention it again.
In Xcode 7, renaming a project can still break your app. Make sure you backed it up before trying it.
Click on the project icon and find the project name in the inspector pane. If you change it there, Xcode will ask you if you want to rename related files. Might work. But if not, try this brute force approach:
Close Xcode
Using an advanced text editor like Sublime Text or Atom, open the
root folder. It will open the folder structure.
Perform a Global Search and Replace (it's probably cmd + shift + f), and
replace My Wrong App Name with New App. If your project name contained spaces, also search for My_Wrong_App_Name and replace
with
New_App. This changes all file contents.
Now you need to find all
the files inside the project with your old app name. Rename them
all, also the folders.
Important: Open the project file with
right click > Show Package Contents, and rename all files in there.
Reopen your Xcode project or workspace. Compile.
If you use Pods, you need to open the pods project as well and change the files in there.
Here is another great example which works well with xcode 5
Am a new bie to IOS development. While working with some sample apps, my mac restarted and after opening xcode i found one interface builder file .xib marked as red. Double click on it shows no content at all. I tried deleting and adding it back from xcode but its not working.
I dont see the file in the project directory too, but when i replace it with old file, it says
an item with same name exists
but its not visible in finder.
Any help would be appreciated.
I am not sure what is a clean solution for this but a quick fix/workaround which worked for me is this:
Along with the error message 'an item with same name exists' you must be getting an id/number which is duplicated.
Open the xib file in any text editor (TextWrangler etc.). It is just an xml file.
Search for that number in the xib. You'll find multiple occurrences of that id.
Replace one of the occurrences with another number and make sure the new number you've added is not a duplicate.
Save this file and open in xcode. The error should be resolved.
Right click on one file in the project and it displays the showinfinder . Then it opens project folder in the finder. Check your file whether it is existing in that or not.
I know one can rename a project by slowly double clicking the project name but I was wondering if it's possible to automate that through the command line (any language, possibly Apple Script) ?
Renaming an Xcode4 project is quite easy.
Click on Show the Project Manager to see the top level project file on the left side.
Click on the project name (here DeeTeeSaver will be changed to DeeTeeSaver2) in order to edit it and enter the new name.
It takes a second to let Xcode4 find out which parts have to be changed.
It then displays a dialog which parts will be changed. Simply click on Rename.
That´s it. No need to fondle around with AppleScript.
You might miss important parts inside the bundle.
Greetings from Switzerland, Ronald Hofmann
You will have to manipulate the .xcodeproj file, which is in XML format.
In my build process I have placeholder names that I simply search & replace with a command line app. If you need a generic solution you will have to parse the XML format (which is undocumented but not that hard to grasp).