2

I would like to localize some images in my iPhone project. So I created files:

en.lproj/Images/iPad/btn-check-pressed~ipad.png
en.lproj/Images/iPadRetina/btn-check-pressed@2x~ipad.png
ru.lproj/Images/iPad/btn-check-pressed~ipad.png
ru.lproj/Images/iPadRetina/btn-check-pressed@2x~ipad.png

and so on and added them to my project. But Xcode shows "English 0 files localized", "Russian 0 files localized" in Localizations list.

It also shows a warning

Warning: Multiple build commands for output file /Users/User/Library/Developer/Xcode/DerivedData/TestLocalizationDefaultPNG-ckplzmcjurofxrccjuvyzjaqketc/Build/Products/Debug-iphonesimulator/TestLocalizationDefaultPNG.app/btn-check-pressed~ipad.png

for each of my files when I try to build the project. So, as far as I understand, it copies all files in one folder, and since my files have the same names - only one of them can survive. But, if I remove my subfolders:

en.lproj/btn-check-pressed~ipad.png
en.lproj/btn-check-pressed@2x~ipad.png
ru.lproj/btn-check-pressed~ipad.png
ru.lproj/btn-check-pressed@2x~ipad.png

everything works fine.

Is there is a way to keep subfolders? Here http://developer.apple.com/library/ios/#documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html in Listing 2-4 subfolder used for the audio files, so it should be.

4

1 回答 1

2

It looks like the only way localization works in iOS is different. You base folders hierarchy should be by inverted: first goes actual folders structure and in each and every folder you want to localize, you put corresponding .lproj sub-folder with localized resources. So in your example it should be something like:

/Images
 /iPad
  /en.lproj
    btn-check-pressed~ipad.png
  /ru.lproj
    btn-check-pressed~ipad.png
 /iPadRetina
  /en.lproj
    btn-check-pressed@2x~ipad.png
  /ru.lproj
    btn-check-pressed@2x~ipad.png

This might be sub-optimal if you intended to have big hierarchy but this is the only way it works out of the box.

Of course you can always say that you don't need Xcode support and use some custom build rules to re-arrange files in you project in the way you like and then copy them into proper structure during build but I doubt it worths troubles.

Update: it looks like XCode (4.5) build script is the main villain.

According to my experiments build script should flattens resources structure at least for images. So the only way localized app can be inside is:

/YourApp
 YouApp
 info.plist
 ....
 /en.lproj
   btn-check-pressed~ipad.png
   btn-check-pressed@2x~ipad.png
 /ru.lproj
   btn-check-pressed~ipad.png
   btn-check-pressed@2x~ipad.png

The trick is that by default XCode (as of version 4.5) can flatten your project structure only if it is as described above and I don't see a standard way to change this behavior.

Of course, original comment about custom build scripts is still true.

于 2012-12-06T20:21:03.857 回答