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.
Related
I have been searching XCode and Google all over, but I just can't find out how to do it:
I am using Base localization and it shows 4 Files Localized for English. I have no idea why it's 4 and I would like to find out why.
But how? How can I get a list of all localized files (and where these files are located)?
Is this such an uncommon task that I can't find any answer to it? Or is it that obvious and I am just unable to find it?
I realized that when I am trying to add another language (like Japanase), I will see there are 4x InfoPlist.strings-files for English and 1x file for Base Localization (Storyboard), but I still don't know why and where are these files and how to remove them.
Checking the en.lproj Folder, there is only 1 InfoPlist.strings-file. Why XCode is telling me that I have 4 of them?
There is a way to delete the localized files. If you are using version control, you can make sure your work is committed and your tree is clean. Then when you delete the localized files, you can just check the status of your tree and see what files they were, and recover them a figure out what you need to do from there.
I agree that it is a pretty terrible developer experience. Just add it to the list of ways in which mobile developers are abused.
Xcode is deriving this information from your project file. So if you can't deduce it by looking at your lproj folder, you can open up pbxproj file (under your .xcodeproj folder) and search for the locale in there.
Just had the same issue. Here is a really easy way to get a list of all localized files, by going through the motions of adding a new language (and cancelling):
Project -> Localizations
Hit the plus button to add a new language.
Select any language.
The "Choose files and reference language to create ... localization" dialogue will appear. This is a list of all localized files.
Hit cancel (don't add the new language).
use this answer manual language selection in an iOS-App (iPhone and iPad)
You can set any language you want, remember "Localizable.strings" for containing language text
The easiest way is to open een finder screen in the root of your project. After that enter en.lproj (or your main language) in the search bar.
Select to only search in the folder
Now you have a list with all the files which are localized.
You can check your files selecting them in Project Navigator and then looking at File Inspector on the right of Xcode.
Here, if your file is localized, you can see what languages are present and select/deselect them.
You can also use Finder: go to your project folder, there there are folders named like ja.lproj or it.lproj (the actual name changes as per Xcode version). In these folders you'll find all the files that are localized for that language (e.g. in ja.lproj you'll see al file localized in Japanese).
I was wondering the same myself. I had not started the localization process and Xcode was already telling me I had "2 Files Localized".
You might want to check the targets in your project. I had one InfoPlist.strings file for my main target and a second InfoPlist.strings file for my unit test target.
By trying to add a new localization, a confirmation screen shows up with a table listing all Resource Files and a dropdown for each Reference Language associated with those Resource Files.
Resource File != Localized File.
Reference Language = Localized File.
For every language you see in the Reference Language drop-down the "Files Localized" counter goes up by one.
In my case this confirmation screen had shown two identical entries corresponding to the InfoPlit.strings resource files in each target with English being the only language referenced for each, making it "2 Files Localized".
Funny thing about all this is that the "Resource Files" don't technically exist in the file system, only the localized files do in those .lproj folders.
"Resource Files", as far as I can tell, are Xcode nonsense.
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!
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.
Sorry if this has been answered before but all my searches do not return anything related to this.
Is there a way to collect all the files referenced in a project and save them in the procject folder automatically? Rather that having links to places where you may accidentally delete the files.
Thanks,
Eds
Xcode doesn't have a particular feature to support this, but when you add items to your Xcode project it does give you the option to copy those items to the project directory. Otherwise you need to manually copy the items to a common location.
What do you mean collect all the files? Do you mean your external files or class files. Your external files like images or audio/video files should be added into Resources directory, it does not matter where is the root directory of these files. Then, you can access with their name in the project.
I would like to localize one of my apps. But I just CANNOT seem to figure it out. I have tried to read apple's docs, and I have looked at a bunch of tutorials that I found by searching. I understand how to change all my strings to NSLocalizedStrings, and how to edit those localized files one there created, but my problem is I can't figure out how to create those directories in the first place.
How do you make those folders en.lproj and a spanish one. Also, how do you make the two string files that go inside them.
Step by step help would be greatly appreciated, or a link to a detailed tutorial on this part.
Thanks in advance.
Note: I've made countless attempts and an simply stuck.
you are nearly done with doing NSLocalizedStrings. You open up terminal.app and change the dir to your project by changing dir. Type in cd and drop in your project folder. Then tipe in: genstrings ./Classes/*.mthis will create a file with all strings you entered. Look in your project folder for Localizable.strings and drag it into Xcode project. Uncheck the box that says "copy into destination group..." and change the text encoding to UTF-16! Then open the info window for that file and check "Make file localizable", switch to general tab and enter for ex: fr for the new localization and click add. Now you can change the localization to french, where it says fr (or whatever you have)
When selecting a file, in the Utility sidebar you will see the localization panel.
There you can add languages.
Note that in Xcode 4.4 and up you have to go to the Project Info and add all the languages there, you can't add languages from any file info