Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localizable.strings files.. in xcode4

In xcode4, (I have used v4.0.1 until now and downloaded v4.0.2 yesterday.) I made Localizable.string files and compiled my project. (As you know, my source code uses NSLocalizedString macro function.)

But my project doesn't compile with Localizable.string file. If I change all code in this file to comments( like this -> // ), my project is compiled completely.

As result, the problem is Localizable.string files. I searched about it on Google, I found that UTF-8 files (Localizable.string) is changed to UTF-16. And though I tried this... this way didn't work, too.

On this moment, many people are trying to use Localizable.string files. But they might solve this problem that I can't do. Because there aren't the questions about this problem so many.

===============================================================

In Localizable.string file,

"LOCAL_APP_GRADE" = "Basic"

"LOCAL_APP_LAST_UPDATED_DATE" = "2011/04/20"

"LOCAL_MAIN_MENU_TITLE" = "Main Menu"

In my source code,

NSLocalizedString( @"LOCAL_MAIN_MENU_TITLE", @"" ); 

Error message,

Copy .strings file Error Validation failed: The data couldn't be read because it has been corrupted.

like image 699
MonsterK Avatar asked Apr 16 '11 01:04

MonsterK


People also ask

How do you make a string file localizable?

To add Localizable. strings file, go to File->New->File , choose Strings File under Resource tab of iOS, name it Localizable. strings , and create the file. Now, you have a Localizable.

What are localization strings?

A localized string can have different values depending on the language in which the project is being build. There are two categories of localized strings: the strings included in the installation package's UI, common to every MSI file.


2 Answers

I'm assuming Xcode 4 here. Double check what it shows for the encoding on each of the Localization.string files in the file inspector. When I was having that error it was due to one of the files being read as Mac Roman instead of UTF-16. Once I changed the encoding the warning went away. What was driving me nuts at first was that the warning was only happening in Xcode 4. Xcode 3 did not give it.

You also have an issue with the formatting of your .string file. All of the lines should end in a semicolon.

"LOCAL_APP_GRADE" = "Basic"; "LOCAL_APP_LAST_UPDATED_DATE" = "2011/04/20"; "LOCAL_MAIN_MENU_TITLE" = "Main Menu";  

I don't think this is the cause of the warning though. At least I've never seen a warning for it. It usually only manifests itself at runtime when LOCAL_MAIN_MENU_TITLE shows up in app instead of Main Menu. It would be nice if the build process did check for semicolons though. It's easy to miss adding one when editing the files.

like image 190
McCygnus Avatar answered Oct 14 '22 23:10

McCygnus


Per Apple:

If you run into problems during testing and find that the functions and macros for retrieving strings are always returning the same key (as opposed to the translated value), run the /usr/bin/plutil tool on your strings file. A strings file is essentially a property-list file formatted in a special way. Running plutil with the -lint option can uncover hidden characters or other errors that are preventing strings from being retrieved correctly.

Fire up a console window, go into your project folder, and do:

/usr/bin/plutil -lint ja.lproj/Localizable.strings 

(obviously replace the correct language folder name). This will tell you exactly where the problem is!

like image 41
Ser Pounce Avatar answered Oct 14 '22 22:10

Ser Pounce