41

I made Localizable.string files and compiled my project (my source code uses NSLocalizedString macro function) but my project doesn't compile because of the Localizable.string file. If I comment all the lines in the Localizable.string file, my project compiles successfully.

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

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

My Localizable.string file contains:

"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.

ricardopereira
  • 11,118
  • 5
  • 63
  • 81
MonsterK
  • 565
  • 1
  • 6
  • 12
  • Could you post the compile error and the strings file if it isn't large? My guess is that you have a formatting error in the strings file, but it's hard to give a fix without more info. – McCygnus Apr 16 '11 at 02:10
  • @McCygnus I have appended my code. Thank you for your comments. – MonsterK Apr 16 '11 at 02:40
  • 4
    Your strings file needs a semicolon at the end of each line. – jowie Apr 14 '15 at 16:09

13 Answers13

97

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.

McCygnus
  • 4,187
  • 6
  • 34
  • 30
  • 13
    oh!!! my god!! Thank you very very very really really much. I was fool. You have made me awake. I already changed to UTF-16, but I missed ';'. This made the error happen. (Copy .string file Error Validation failed). And this made me confused. I never thought this made the issue happen. – MonsterK Apr 16 '11 at 07:51
  • You told me to append my code on this board, it made me know that what the issue was. I can't use NSLocalizedString function since I start to use xcode4. But I can do this now. Thank you! – MonsterK Apr 16 '11 at 07:52
  • 1
    I appreciate all your answer and your trying. I am very happy. – MonsterK Apr 16 '11 at 10:13
  • 1
    This is especially confusing in Swift because you don't need semicolons in the Swift code, so you're in the habit of leaving them off the end of the lines, but it turns out you still need them in the *.strings files. – James Toomey Jul 06 '16 at 14:01
67

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!

Ser Pounce
  • 14,196
  • 18
  • 84
  • 169
  • it tells me my comments are invalid, but they are not. – jimpic Jul 07 '14 at 12:50
  • @jimpic - So far when I've used this, about 95% of the time it works, but sometimes I've noticed, like if you have stray text in the file, then that will screw it up and it won't give a valid response (for me it kept saying that the first character in the file was invalid when it wasn't). Try it again next time and it may help you. – Ser Pounce Jul 21 '14 at 10:54
  • 1
    This tool worked for me. I was running into the mysterious "Copy .strings file Error" and plutil identified several places with extraneous and unescaped quote marks in a very large Localizable.strings file. It finds one bad quote at a time so you have to run it repeatedly. Thanks! – Phil Aug 14 '14 at 18:05
  • 1
    This is huge - thanks so much for that tool. I had some translated files and there were unescaped double quote characters in the middle of a string. The original used single quotes. – Andy Weinstein Aug 25 '14 at 11:16
  • 1
    In my case in turned out to be incorrectly escaped " – tomi44g Sep 29 '14 at 16:25
  • (OSX 10.5.5/Xcode 7.1.1) Because `/usr/bin` is probably in your PATH variable, you can just do: `$ plutil ....`. To check if plutil is in your PATH variable: `$ which plutil` If there's no output, then /usr/bin is not in your PATH. I found that `-lint` doesn't do anything, so the command I used was simply `$ plutil Localizable.strings`, which identified a missing semi-colon. – 7stud Jan 13 '16 at 19:48
20

All of the lines in .strings file should end with a semicolon. It worked for me.

Muhammad_Awaab
  • 1,578
  • 13
  • 19
7

I had the same issue today after importing the localisations from Apple Notes and the cause was really subtle. The standard double quotes had been swapped with slanting double quotes.

Slanting double quote: ”

Standard double quote: "

Nigel
  • 141
  • 1
  • 9
3

I've been struggling with this same error, and ended up having a couple similar issues, but with different details. First off, even though it appears that Xcode's internal "builtin-copyStrings" tool should be able to handle either little-endian or big-endian UTF-16 files, it really only handles big endian. My theory is it's running some extra validation step (perhaps using the plutil command line utility) that didn't used to happen in Xcode 3, and that tool barfs on anything but big-endian UTF-16. Not entirely sure though.

The second trick is that you need to make sure your strings files are saved with no BOM (Byte Order Marker). I did some editing of my .strings files in BBEdit, which ended up saving a BOM to the file, and that also appears to make Xcode 4 have a conniption fit. Xcode itself doesn't appear to have any way to remove the BOM from the file, so this has to be done in a text editor such as BBEdit or TextWrangler which can do that for you.

Brian Webster
  • 11,915
  • 4
  • 44
  • 58
2

With Xcode 10.1, one missing semicolon stops compilation with this error:

Localizable.strings: read failed: Couldn't parse property list because the input data was in an invalid format

BTW, you can find out if the error is general to your file (an encoding issue) or specific to one or more lines by temporarily removing most of the file content. You can then locate the problem by incrementally adding content back in until the error returns.

arlomedia
  • 8,534
  • 5
  • 60
  • 108
0

Perhaps you have something like: "Bla"="bla";;

Note the duplicate ; symbol. If you have that, it will compile properly but will fail in run time.

Ricardo
  • 2,831
  • 4
  • 29
  • 42
0

Related to this - take care when manually merging strings into Localizable.strings - I managed to copy/paste BOTH strings from a NSLocalizedString() macro, so that the Localizable.strings entry was in this form:

"KEY" = "STRING", @"COMMENT STRING COPIED ACROSS ALSO, IN ERROR";

The bit ,@"xxx" on building caused me to get the error:

Read failed: The data couldn't be read because it isn't in the correct format.

In this case doing a quick search on @" helped identify the places I'd done this.

Rob Glassey
  • 2,237
  • 20
  • 21
0

I had this problem. My fix? Add a newline at the top of the file. Bizarre but it got it working for me.

So instead of at the top of my file having this:

/* comment */
"LOCAL_APP_GRADE" = "Basic"

I had to do:

[newline]
/* comment */
"LOCAL_APP_GRADE" = "Basic"

(Can't get the formatting right - don't type 'newline', just hit return!)

tactusben
  • 11
  • 1
0

Looks like this is an standard message for error reading the strings file.

In my case it was a (json force of habit) colon instead of equal sign:

"key1" = "String1";
"key2" : "String2";
"key3" = "String3";

Changed it to = and everything worked fine.

Community
  • 1
  • 1
gfpacheco
  • 2,831
  • 2
  • 33
  • 50
0

My problem was, that I've forgotten ; in one of the lines

Vlad Pulichev
  • 3,162
  • 2
  • 20
  • 34
0

Make sure that you have declared string in following format:

"YOUR_STRING_LABEL" = "Your message";

Note: Don't forget Quotation Marks ("), Equals Sign (=) and Semicolon (;) at end.

Chintan Shah
  • 1,744
  • 2
  • 26
  • 28
0

This may be because the translation file format is wrong. You can download a mac software called Localizable.

This is the download link: https://apps.apple.com/cn/app/localizable-翻译文件工具/id1268616588?mt=12

You only need to drag Localizable.strings file to the software. and it willtell you which line in the file may have a problem.

It is useful .It saved me a lot of time. Now I share it with you, I hope it will be helpful to you.

ChenYuan
  • 33
  • 3