subfolders in iPhone localization folders - iphone

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.

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.

Related

Tool to compare and merge files in different folders

I am developing two Java based projects that are very similar which means that what i do to the first one i can use diff to... command in Netbeans to apply the changes to the second one. However there is a problem with the images folder. For example i work one week on the first project and during this week i put 34 new images in the images directory. Then i have to put some of this images in the images directory of the second project. Copy/paste is not a solution because the projects are NOT EXACTLY THE SAME.
That is why i need you to recommend me some tool that can show me which pictures are missing in the seconds directory so i can simply drag them to their new location:)
diff -rq <path1> <path2> will give you a list of files that are only in one of the paths, as well as an indication of whether file names that exist in both actually have the same content.

Why in Xcode, Groups can be created, but not real folders?

When doing iOS programming, it is interesting that in Xcode (4.3.2), we can create groups, such as a group call Images, and add files to it (either as a link or choose "Copy items into group's folder"). So it looks like a real folder in the navigator, and it even mentions "copy into ... group's folder", but in fact there is no folder. All added files are in the same location as the .m and .h files.
Why would we want Groups, but not real folder? Is there advantage of Groups over the use of a folder?
This is a pet peeve of mine.
I recommend, making the folder in your file system, where you have your project files, then drag that folder into Xcode where you want the group. It will act like any other group, but now be linked to the folder on the file system. Adding files to that group in Xcode now adds them to the folder in the file system.
Much cleaner way of working and helps when locating files in big projects. Keeps git cleaner too.
Update for Xcode 9:
Once you have the groups in Xcode matching the directory structure on disk, moving a file from one group to another in Xcode will now move the file correctly on disk to match.
Note: In Xcode 10, the default behavior now creates a linked folder when you create a new group. The information below still applies otherwise.
The recommended way to organize files is via groups, because it's more flexible than creating directories, and allows you to create complex file hierarchies while maintaining a totally different file hierarchy on the file system. It's simply an organization tool. That said, it is possible to turn groups into folder references, or create them initially as folder references.
Furthermore, using groups instead of folder references gives you greater flexibility if you need to change where things are in the file system - say you have a common folder of code that you use in a bunch of different projects. Groups allow you to organize the files inside of projects as if they were in the projects, while still maintaining one copy of the code in a central location. And yes, you can do this with folder references as well, but groups are much more flexible if you later want to add other things to the same group but don't want them to be added to that common folder.
If you want to link a group to a folder, click on the group in the project file tree and hit command+option+1. Below the drop down that'll say something like "Path: Relative to Group" on the right, there's a little white square with a grey border around it kinda icon next to the word "none". Clicking on this and then selecting/creating a folder will bind the group to the folder.
Furthermore, when you drag a folder into Xcode, it will ask you if you want it to be a group or a folder reference:
There is a Command Line Tool - "synx"
available in github that do exactly what you need.
It reorganizes Xcode project folder in finder to match Xcode groups in project.
You can find it here:
https://github.com/venmo/synx
UPDATE: XCode 9 supports this feature by default. So, no need to use other tools anymore!

Localizing iphone app html files and strange xcode 4.2 warnings

I've got an App that I am trying to localize for several languages. I'm doing most of the localization through .strings files, but for the larger help files, I need localized versions of html files.
I've read Apple's documentation as well as doing many searches on Google, and I think I am doing things correctly.
In my xcode project directory, I have an "en.lproj" and a "ja.lproj" (Japanese). I put versions of my HTML help file in each directory, and I import these into my Resources group in xcode. After doing so, the files seem to show up correctly. I see a "help.html" file under Resources, and it is a "group" and if I look inside it I see:
help.html (english)
help.html (japanese)
When I build my App, my App seems to correctly contain the two versions of the files under their appropriate .lproj directories, and everything is working correctly when I run the App (I see English documentation when settings are English, and Japanese when settings are Japanese).
However, when I build my project, I get annoying warnings from xcode 4.2:
Warning: Multiple build commands for output file .../ja.lproj/StartQuizController.html
Warning: Multiple build commands for output file .../en.lproj/StartQuizController.html
From what I understand, these "multiple build command" messages occur when there are conflicting filenames that are being added to your App. However, since these files are localized and exist in their own subdirectories, there is no real conflict.
Am I doing something wrong, or are the warnings a bug in xcode 4.2?
Thanks,
Ron
I think you can prevent these warnings if you do it the Xcode way.
Xcode uses only one copy command to copy the localized files, you have probably two separate commands.
You could try to delete the files form the "copy bundle resources" build phase first.
Delete the copy command for the localized files and add a new one. If Xcode treats your localized files right it should show a single file instead of a file for each localization in the "Choose items to add"-Picker.
If that doesn't work just remove them completely and add the physical files again.
Backup all your html files. Then delete them from the project (both logical and physical).
Add the English version of the file to Xcode, let Xcode copy it to your directory.
Select file in left sidebar
Open first tab of the right sidebar
add localizations by using the + button in the localization section
either replace the content of the file trough Xcode or use Finder to replace the localized versions.
I´m trying to localize my project as well. I always add a in-App user´s manual in a html file wich gets loaded on a UIWebView.
I haven´t done it yet, but what I´m going to do is to create different files for each language, say for example:
info_en.html // for english
info_es.html // for spanish
info_ca.html // for catalan
then when the webView gets loaded, instead of loading the #"info_en.html" file, I will load the NSLocalizedString(#"info", nil); Then, in each localized string file, the name for the html file will match the language.
I believe this should help but, again, I haven´t tried myself yet.

Using resources with the same name in Xcode

Is there a way to add multiple resources with the same name to an Xcode project and have 1 of them take priority over the others?
Example:
I added 2 files, both called icon.png, to an Xcode project. They are on different folders in the file system (Folder1/icon.png and Folder2/icon.png) and on different groups in Xcode. Is there a way to tell Xcode to have Folder2/icon.png take priority over Folder1/icon.png? And if only 1 icon.png exists, then use that one.
Thanks.
EDIT (2010-12-23):
You can have multiple files with the same name in an Xcode project even if they are not in separate folder references, but they are in separate groups. Once compiled, the app bundle (which will be flat with no folders in it), will only have one copy of the file (icon.png). How do you pick which copy of the file to use?
I was told that you can do this for BlackBerry. It works something like this: The compiler will go down the list of files in the project and start adding them to the app bundle. If it sees a duplicate, it will overwrite it (or not), so the files at the bottom (or at the top) will have higher precedence and will be the final bundle.
This can better easily be solved by using folders within a resource bundle in your Xcode project. Take a look here: http://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFBundles/Introduction/Introduction.html
Wait a second, since you specifically mentioned icon.png, are you trying to supply different iDevices (iPad, iPhone4, iTouch3...) with different icon images?
If yes, check this out, http://d.pr/W2w0 , Apple has already provided a way for us to finish this task with convenience. All you need to do is following a specific naming convention.
What we do if we have a situation like this is:
We have several subfolders on the file system level of the project dir and add them to XCode into separate groups.
This works well. For actually building, we try to avoid Files with the same Name in one target. Icon.png and iTunesArtwork are only added once in every target.
It just proved to be a Maintainability Nightmare

How do I localize multiple files at once in Xcode?

In the process of localizing my app, I have about 50 resources (mostly xibs) that need to be localized. I know how to add a localization for each file, but it's a pretty time consuming process to open the info panel and add the localization for each file.
Is there any way to select multiple files and add a localization to each of them in one shot?
Edit to add: Is this a place where AppleGlot or iLocalize can help? I haven't yet looked at those tools.
Just create a directory for the language you are localizing for if it isn't already there (e.g. "en.lproj") and copy all the files there. Then go into xcode and add the newly copied files to your project.
Have you tried using ibtool? This tool, which runs from the Terminal, can list the classes or objects in a nib files and can also dump the localizable strings into a plist.
I haven't tried this tool though, but you can find more info by typing "man ibtool" in the Terminal.
Selecting multiple files in the left/navigator pane and then adding localizations via the right/utility pane is supposed to work, but doesn't. I filed bug #9276560 against Xcode 4.0.1.
If you need to support a lot of languages, this can help:
Click on file #n
Add one localization
Repeat steps 1 and 2 for all files
Click on the project in the left/navigator section
In the project info pane, add localizations
What that does is add every previously localized file to the new language(s). You'll still have to add 50 files separately, but at least you won't have to perform 50 operations times the number of languages. In my case, that saved me several hundred steps.
The answer is in the other post here
In essence, you have to create xx.lproj directories for all your languages.
Then copy all localized files to their respective directories.
Now your lproj dirs should have the files with the same name (but with different localized contents).
Then you add all files from all dirs into Xcode.
Xcode will assign them to appropriate locales based on the lproj dirs where they reside.