11

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.

enter image description here

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:

enter image description here

Double click on Root.strings gives me:

enter image description here

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?

DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601

6 Answers6

21

In XCode 4.2 you have to follow this steps (just a modification of Xcode 3.2.2 and localization of Settings.bundle)

  1. Reveal your Settings.bundle in Finder.
  2. Right click (or Ctrl-click) on it and select Show Package contents.
  3. Create a new folder called as the desired language (e.g., fr.lproj).
  4. Copy the Root.strings file from the en.lproj folder and paste in fr.lproj folder.
Community
  • 1
  • 1
Javi
  • 211
  • 2
  • 4
13

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.

  1. Right click on the settings bundle in the side bar.
  2. Select New File
  3. Pick Resource / Strings file
  4. Name it Root.strings, make sure it is placed inside settings.bundle
  5. 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.
  6. Select the Root.strings file in the root section. (AFAIR you have to convert it to UTF16)
  7. Add localization, xcode will ask you if you want to replace the file. Yes, you want this.
  8. 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

enter image description here

After adding spanish localization to Root.strings:

enter image description here

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. enter image description here

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.

Community
  • 1
  • 1
Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
  • Thanks that works great :) Is it fixed with the new release? I think there is already a bug report on this http://www.openradar.me/9127927 – DarkLeafyGreen Mar 27 '11 at 08:53
  • Aww, I forgot something to ask, what Is with localization?? The Root.strings is not in en.lproj or de.lproj, how does it know it is german or english language? – DarkLeafyGreen Mar 27 '11 at 09:03
  • @ArtWork I made an edit, but after reading your second question again I realized that you might just ask where the file is on the file system. It's in the de.lproj folder inside of the settings.bundle. Right-Click the settings.bundle in finder and select `Show Package Contents` – Matthias Bauch Mar 27 '11 at 10:59
  • How do you get this Root.strings dropdown? I can just create a Root.strings without an arrow to show the childs, however how do I create childs? For me it adds just the Root.strings and I can not create another one because it just replaces the old – DarkLeafyGreen Mar 27 '11 at 11:49
  • Did you add a localization? In the Utilities side bar. – Matthias Bauch Mar 27 '11 at 11:54
  • the de.lproj doesn't show up in the sidebar, but I can browse it in the finder, strange thing, apple should definitely fix that. thanks for your help! – DarkLeafyGreen Mar 27 '11 at 12:02
  • Check if the files physical location is really inside the settings bundle. I doubt that it'll work if you don't see the folder. – Matthias Bauch Mar 27 '11 at 12:41
  • @Downvoter What's wrong with this method? I understand that my workaround is more complicated than the little change from dalind. But have you tried to add a dozen localizations with his approach? I doubt it. – Matthias Bauch Apr 17 '11 at 21:50
  • 2
    I don't get it. When I click on the Settings.bundle and choose New File Xcode won't let me place the Strings File inside of the Settings.bundle. How am I supposed to put the Root.strings file inside of the Settings.bundle from within Xcode? This is a horrible bug! It's driving me nuts :( – Julian Jul 23 '11 at 20:21
  • The same situation as Julian has(. Root.strings is not added to Settings.bundle – Tamara Dec 06 '11 at 05:53
  • Same for me as for Julian, too... ;( – Daniel Albuschat Jun 27 '12 at 11:20
  • I'm sorry, for not responding and for the solution that doesn't work anymore. Apparently Apple fixed the bug that enabled my workaround (you could create a new file within Settings.bundle). No need to mention that they didn't fix the bug that made the workaround necessary in the first place. Please see the answer of Javi, I haven't tried but that one sounds like it could work. – Matthias Bauch Jun 27 '12 at 21:15
7

For me it worked to change the File Type (in the File Inspector) of the Folder "en.lproj" from "Default / Directory" to "Directory". Magic.

dalind
  • 181
  • 12
  • Am seeing the same. Although Xcode4 said the filetype was "Directory - automatic" (or something like that), manually setting it to "Directory" made the Root.strings file finally appear. – DarkDust May 02 '11 at 07:46
  • 1
    ... but the change wasn't persistent for some reason. Went with fluchtpunkt's solution instead, seems to work alright. – DarkDust May 02 '11 at 08:10
2

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.

Urkle
  • 1,520
  • 13
  • 12
  • I tried this -- while it worked to show the default strings (after doing dalinds change to enable the directory to behave), editing the defaults didn't actually change the strings on the settings screen. – lilbyrdie Jun 18 '11 at 21:40
2

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.

18446744073709551615
  • 16,368
  • 4
  • 94
  • 127
0

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.

Rolleric
  • 167
  • 1
  • 7