How to add localized .strings files back to Xcode? - iphone

I have a .strings file that is localized in a number of languages. I'd like to add it to my Xcode project. How do you get Xcode to correctly reference the files? I've tried
dragging the english version of the .strings file (found in English.lproj) to Xcode and hoping it would automatically pick up the other localized versions of the file -- it doesn't.
dragging all 5 localized versions of the .strings file (found in English.lproj, es.lproj, etc.) assuming Xcode would create a single file reference with the various localized versions -- it crashes.
dragging each of the .lproj folders to Xcode hoping it would figure out that the file in each of the folders is all the same file, but localized -- nope
dragging the English version of the localized .strings file to Xcode, then add a localization that already exists -- Xcode warns that it will overwrite the file, but doesn't give the option to use the existing file.
UPDATE: Submitted a bug report to Apple: #10181468.

The simplest way as of Xcode 4.6 is to drag localization file (.strings file, not the folder it's located inside of) from Finder to the Xcode project tree. Be accurate and drag to the top of .strings group, not to the bottom or inside of the group as the latter makes Xcode crash.

Add the original file (only the file, not the .lproj folder) then make it localizable, add all languages you want, xcode will create .lproj folders and duplicate your original file for each language.
After you can overwrite each file duplicated by your already translated file (either the file if it have the same name or content).
Don't forget to set the format of the original file to UTF-16 when you add it.

Related

Localizing resources with xcode 4.0.2

I am having multiple issues trying to localize an app with xcode 4.0.2.
This app was coded initially with previous version, but since I installed the 4.0.2 everything (more or less) has worked, except localization. I have about 10 png's that load in 10 different xibs via UIImageView using Interface Builder. These png's are "correctly" localized, inside the es.lproj folder the spanish ones and in the en.lproj folder the english ones.
The weird thing is that even inside xcode, when I open the xib file, it sometimes shows the english version and sometimes the spanish. ¿?
The xibs are not localized, because there is nothing more to localize in there, just that UIImageView with the png's.
Is it not possible to localize just the png's?
Does anyone know if this issues respond to known bugs?
This png's are named text1.png, text2.png, text3.png ... Could it be something related to the serialized naming?
The default xib when there's no localization is english. When it load it pulls in the english resources. So you need to create the localized xibs in addition to the images. Or, what I'd recommend in your case since it's just 10 images, is to load and set the correct image in viewDidLoad. It'll be easier to maintain since you won't have to update every localized version of the xib for every change you make. Save that headache for when you have more items in one that are localized. :)
Well, I think that I get it...
I have changed the name to the png's. Instead of text1.png -> textone.png, texttwo.png ...
(The name should not be a problem, though)
When changing the names, some of the png's has become red. Even though they were still in the right lang.lproj (ex. en.lproj) folder.
I have created another directory to back-up the files and cut-paste all the "red ones".
Then I have deleted (references and file) these files from xcode.
Using finder, I have pasted each one of these png's inside my main language file. Just to move it again to the xcode resources from there.
After having it in xcode again, I have localized it using the "Localization +" Inspector.
Then, using finder again, I have replaced new "localized" png inside lang.lproj (ex. es.lproj) with the old language png in the back-up folder.
Finally, I have deleted the app in the simulator, cleaned, and Run again.
I did the same process with xib files. And everything works now. I haven't found any way to fix dependencies or paths to files that aparently are ok, but the localization doesn't reach them as expected. I understand that this should not be the way, though.

Localization of Bundle Display Name fails in XCode 4

I have an app that is localized in two languages. I'm trying to change the bundle display name according to the selected localization.
In many articles on the Internet, this is done localizing the info plist file.
I'm using XCode 4 and it automatically creates a MyProject-Info.plist file containing the bundle display name.
As soon as I try to localize it (even having only the first language added) I cannot build the app anymore, cause the Identifier field in the "Summary -> iOS Application Target" section in the project properties becomes blank (and I cannot edit it).
What happens in the file structure of the project is that the original MyProject-Info.plist files is moved to the en.lproj folder, as well as duplicated into the other *.lproj folders I have (one for each supported language).
Any hint?
1.select "InfoPlist.strings" file
2.Open “File Inspector"
3.add your localization language at Localization Section.
4.Open "InfoPlist.strings(English)" file, add CFBundleDisplayName = "Yours English Application Display Name";
5.Open "InfoPlist.strings(your local language)" file, add CFBundleDisplayName = "Yours Local Application Display Name";
Taking the risk of being redundant, let me just clarify (as I've tested this right now) that the trick is to translate the InfoPlist.strings and never the MyProject-Info.plist.

Localization of the iPhone Settings.bundle

For some reason I cannot get the Settings.bundle to recognize my additional languages. I must be missing something obvious, but I just cannot figure it out. Here's what I've got:
Project Structure in XCode:
Root.plist file:
Root.plist file http://img227.imageshack.us/img227/571/screenshot20100624at334.png
French Root.strings file
french Root.strings file http://img121.imageshack.us/img121/571/screenshot20100624at334.png
From everything I've read, I believe the project structure is right. The StringsTable in the Root.plist matches the name of the individual .strings files, and the Key for each item in the Root.plist has a match in the .strings files as well.
Why don't I see French text in my settings when I change the default iPhone language?
Thanks in advance!
For me, the problem was leaving off a semi-colon!
In localizable.strings, you get a runtime error if you omit the ";", but in Root.strings, you don't get any warnings, you can run it fine, but it just won't work!
So double-check to make sure you punctuate each key:value pair with a semi-colon!
I'll go ahead and answer my own question since I solved the problem myself through testing and failing. Hopefully this will help someone else in the future.
First, I think my Root.plist file may have been corrupted. I'm not exactly sure why, but I completely deleted the Settings.bundle, and re-created it to be sure.
Second, and perhaps most importantly, the main issue was the "key" in the root.strings file didn't match to the "key" field in the Root.plist, it actually matches the "Title" field.
Once I made those changes to the Root.strings file, it all started to work.
All you have to do is keep (or Add, if it's not there) "Strings Filename" in the Root.plist, after your settings.
Then, add Value "Root" (or, the name of your file and the translations) to make the created lang.lproj translations functional.
In my case, it appeared as if "Strings Filename" was set to "Root" in the Property List View of Root.plist, but when viewed the file in Source Code View, it was actually "StringsTable" pointing to "Root". The solution is to add another entry where "Strings Filename" points to "Root". (I also tried deleting the previous entry, but then it stops working, so you need both.)
In Xcode 5 there is still no obvious way to localize the Settings.bundle.
The problem
Xcode doesn't allow you to localize a file that is only shown because it is a file inside a folder that's directly shown in Xcode (hence the blue folder icons in the tree).
The Solution:
right-click the Root.strings file and select "Show in Finder"
List item
move the Root.strings file one folder up, so that the en.lproj folder is empty and the
Cmd-Drag the Root.strings file is next to the Root.plist.
delete the now empty en.lproj
go back to Xcode, notice that the tree will reflect the changes you now made
cmd-drag the file in the tree outside to outside the settings-bundle, so that it appears next to your source-code.
Do not copy the file
a dialog will appear asking you what to do with the file.
DO NOT select the checkbox to copy the file (you need this to be a reference)
DO NOT select a target to include the strings-file (the settings.bundle is already assigned to the correct target)
in the file inspector you can now choose to localize the file and to add languages to the localizations. The files will be placed correctly inside the settings.bundle and the tree will automatically reflect these changes, too.
After some repeated tries to activate localization,following steps worked for me:
Close xcode
Drag and duplicate the settings bundle onto the desktop (or wherever)
Open bundle contents
Drag Root.strings into
the en.lproj folder
Duplicate the en.lproj folder and rename to
whatever language you want (using 2-letter code ie fr.lproj)
Replace the original settings bundle with the new one(without
opening xcode).
Now Open xcode and the new files and folders
should be there
Now delete the older app and run xcode,Works fine in simulator and on device.
NOTE:Closing xcode,updating of duplicated setting bundle outside xcode and replacing updated back only will help.

Xcode 3.2.2 and localization of Settings.bundle

I have just discovered that after upgrading to the latest Xcode 3.2.2, I am not able anymore to localize Settings.bundle. The "Make File Localizable button always appears grayed out, and the Settings.bundle files appear with "No Explicit File Encoding", instead of UTF-16.
This happens not just for my old projects, it happens even for new projects.
Any clue? Is the localization procedure changed?
Thank you in advance.
Looks very strange, maybe need to report to bugreport? But here is workaround that works.
Reveal your Settings.bundle in Finder.
Right click (or Ctrl-click) on it and select Show Package contents.
Copy en.lproj and rename to desired language (e.g., fr.lproj).
Now you can go back to Xcode and edit localized Root.strings and files as you need.

ibtool generates .strings file that are unreadable in xcode

I'm using the ibtool to localize my nibs. I run the following command:
ibtool --generate-strings-file MainMenu.strings en.lproj/MainMenu.nib
I then add the generated .strings file to the xcode project so that I can reference and edit it later.
When I do that, if I select the .strings file in xcode, it displays a bunch of upside question marks and garbage. However, if I choose not to add the file and manually open it using xcode, it reads the file perfectly.
I can only guess that ibtool is encoding the file in an unreadable xcode format.
If I open file .strings file in xcode, copy the contents to the clipboard, close the file, add the .strings file to xcode, replace its garbage contents w/ the contents in the clipboard, and then save the file, its fine. I also notice doing that will reduce the size of the .strings file by half.
Any guidance would be appreciated.
Thanks!
Yes, somehow XCode fails to auto-detect the encoding of the generated file which is UTF-16 as required by specification. But when you add the generated file to XCode you have the option of choosing the character encoding (it defaults to UTF-8). There should be a dropdown for this right below the "Copy items into destination groups folder" checkbox. Just select UTF-16 and you should be fine. You can also choose the encoding in which XCode opens the file at any later time. To do this just right-click the strings file, select "get info" and you should get a drop down list of encodings.