I am learning how to localize the strings in my project and I am using Xcode 4.
I have generated the base Localizable.strings file, and I want to import this file, changing its encoding from utf-16 to Unicode utf-16 so that the text in the file is readable within xCode. If I strate import this file, when I select it within xcode, the text shows up as gibberish.
In Xcode 3 when you drag the Localizable.strings into your project, the dialog box which appears gives you the option to change the text encoding, but this is not the case in Xcode 4.
Does anyone know a way around this?
Maybe this can help you Objective C/Xcode 4: Encoding Problem with Localizable.strings files
These kind of errors can happen if you copy and paste content within Xcode or from external files in your localization files. The consequence is that the encoding of the file changes to for example Western (Mac OS Roman). The Localizable.strings file should be in UTF-16 though.
Solution
1.
Like in the picture below, navigate in Xcode to the Localizable.strings location and open it so that you can see all the languages you are supporting.
Left-click on the language file the causes the build error.
Make sure your Utilities View is showing in Xcode. Activate on the button at mark 1 in Picture below.
In the Utilities View select the File Inspector. (Small Logo that looks like Page)
Under Text Settings change the encoding to UTF-16(Marked as 2 in the picture above). The Drop-Down might be grayed out but you can click on it anyways. Click on "Convert" on the Popup.
That's it your project should now compile again.
The "Text Settings" for my Localizable.strings files don't have the option of changing the encoding like XCode 3. However, I found if I simply restart Xcode 4, it reinterprets it correctly (UTF-16).
Sometimes Xcode displays the warning, even if the file contents are UTF-16, but the file is somehow interpreted as UTF-8. iconv usually says that it can’t convert the file in this case. Converting the file in Xcode to UTF-8 and then converting it back again to UTF-16, like Edmar suggested, solves this problem. The warnings are gone.
To make sure that nothing got broken during the conversion, recheck the whole strings file.
After changing the encoding, and re-executing the genstrings command to regenerate the localize string, things should work.
View -> Utilities -> Show File Inspector
Change Text Encoding in the file inspector utility view.
Related
For some unknown reason, the encoding of my files has changed without me noticing for a while.
It was UTF-8 and now is windows-1252. I have reset the project encoding from Settings->File encoding but I can't detect which files are badly encoded and can't figure out how to reencode all files within the project at once.
I have a strong feeling that the problem appeared with WebStorm 10 first released version, but I may be wrong. (I think it's because it set by default the project encoding setting to windows-1252)
Close every project you have opened by clicking File > Close Project.
Once they are all closed, the startup window will show up (The window with the latest opened projects with the options to open new project, etc..) In that window, at the bottom right corner you have settings.
In Settings > Editor > File Encodings.You can set up all the File Encoding options to UTF-8, it will be added to the new projects from now on.
If you want it for old projects, do the same steps, but access the settings once you have the project open.
I hope this help!
To convert the file encoding, you have to use some external tool to perform the conversion, such as iconv:
iconv -f windows-1252 -t utf-8 <input file> > <output file>
You can change your code's character set in WebStorm foot bar
Open code file
You can see foot bar ( This menu is in right down. )
Click character set select bar
change your code encoding
change and save
If you have encoding defined in your files e.g. like this <meta charset="windows-1252">
you can you use Idea's Replace in Path... functionality and modify multiple files at once.
Even you don't have that definition, you may be able to add it to your files using the same search and replace functionality. I had to convert massive amount of ISO-8859-1 encoded file to UTF-8 and this solution worked fine.
After upgrading to iphone xcode 4.1 build 4B110F all of my localizable.strings files are showing up as gibberish in the xcode editor. I created these files using UTF-16. I can not find a way to tell the editor that they are UTF-16. I am able to view the Localizable.strings files by viewing as a property list, but if I view them as Source Code, I see gibberish. I like to translate the entire localization.strings file and paste it into the editor. I don't want to have to cut and paste one line at a time in the property editor. There should be some way to tell xcode to show the file as UTF-16. Does anyone have any ideas?
I tried removing the files and re-adding them. I used to get prompted for the UTF type, but it does not do this any more.
You can find the text encoding setting for a file in the Utility area of Xcode 4.1. The utility area is the right-handside lateral area.
In the utility area, look for and select the first pane, named "File Inspector".
There, you will find the text encoding in the "Text Settings" block. Expand if necessary using the triangle.
I had this same problem. I was able to work around it (without much actual investigation) by simply opening the previous string files in TextWrangler, then copy from TextWrangler and paste into XCode4's view of the string file. Things seem to be working fine as a result.
To fix XCode 4.1 UTF-16 encoding issues:
1: Open the file you want to change
2: Put your cursor into the file, which will give the editor focus (VERY IMPORTANT).
3: Proceed to look under the Utilities Pane (very far right) for Text Settings and use the Text Encoding drop down to select UTF-16 or whatever other encoding you want.
If you forget step 2, and only highlight the file in the Project Navigator, you will not see encoding options.
When I click on the the en sub-file of that Localizeable.strings file which has a arrow to expand, I can't see what's written in that file. Screenshot:
I can reveal the real file in finder and then see the real content in TextEdit with no problems. Then I copied that from TextEdit and pasted it into Xcode, and VOILLA all looks nice. Saved, build & run, and Localization stopped working. Damn.
Any idea what's going on? I created this in Xcode, and I clearly remember that once upon a time I was able to edit the contents with no problem from inside Xcode.
The file is likely encoded in UTF-16. So, you can go to the Info for it (general pane) and set the right encoding for it.
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.
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.