Localised Strings Xcode 4 ... Copy .strings file Error Validation failed
Asked Answered
B

13

68

How do I define localised strings in Xcode 4?

I assumed I could just add languages to InfoPlist.strings using the "Localization" property (File inspector, right panel).

...and then type in the "key" = "value"s in each localised version.

But I can't build the project. I get this error:

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

Converting the text encoding to UTF 16 doesn't fix the problem. Neither does quitting Xcode and starting it again.

Q1: How do I remedy these build errors?

By some fluke, I did once manage to get a test app to run adding a InfoPlist.strings (French) and (English). I didn't get the error on the French strings file, but I did with the English. So I left the English one alone, and just put a parameter in the French one. However, in the simulator, set to French - the parameter wasn't picked up. It reverted to the default specified in NSLocalizedString()

Q2: How do I get it working even if the build errors are remedied?

Braswell answered 12/4, 2011 at 12:29 Comment(0)
C
239

Could be as simple as a missing semi-colon at the end of the line.

Commonable answered 14/4, 2011 at 3:49 Comment(5)
Thanks. That helped. However, although it builds and runs - it still doesn't work. NSLocalizedString(@"default",@"greeting") gives me default all the time.Braswell
Do you have multiple .strings files? If so, NSLocalizedStringFromTable.Commonable
It works now. Not sure why. Maybe saving and loading again?Braswell
you problem was that NSLocalizedString(x,y) takes the key you want as the first argument (x) and a comment as the second (y) so what you wrote in your comment should have been: NSLocalizedString(@"greeting", @"default")Semifinal
When there is a missing semi-colon, Xcode somehow doesn't show that warning until you close and re-open it. Project runs without any error, or warning. You just get keys as values. You see what the problem is just after restarting Xcode.Bukovina
J
101

I had same the issue finding the errors within the localization file...

Just use the tool plutil in the terminal to convert the file and you will get a proper error message with the line number.

plutil -lint Localizable.strings

Response

plutil[74058:707] CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary on line 422. Parsing will be abandoned. Break on _CFPropertyListMissingSemicolon to debug. Localizable.strings: Unexpected character " at line 1

Jaredjarek answered 24/7, 2013 at 12:36 Comment(3)
Fully agree with @Jason; this immediately pinpointed my problem (which Xcode did not even find - it simply did not show the translations in the app). Good find, @Jaredjarek !!Avaria
Possibly the best answer anywhere on StackOverflow! thank you (in my case it was some smart quotes which caused the problem)Unbeliever
Thanks a lot, it was a missing ';' but the same thing is tedious to find in a big file,Repulse
L
14

yes just trawled through 500 translations

note the KISS in the second string is in Double quotes which are INSIDE another DOUBLE QUOTES ERROR

"Before using KISS Remixer, you must agree to the terms and conditions of use." = "Vor der Nutzung des Remixers "KISS" müssen Sie die Allgemeinen Geschäftsbedingungen akzeptieren.";

This is OK

"Before using KISS Remixer, you must agree to the terms and conditions of use." = "Vor der Nutzung des Remixers KISS müssen Sie die Allgemeinen Geschäftsbedingungen akzeptieren.";

as is this (replace with single quotes INSIDE THE DOUBLE)

"Before using KISS Remixer, you must agree to the terms and conditions of use." = "Vor der Nutzung des Remixers 'KISS' müssen Sie die Allgemeinen Geschäftsbedingungen akzeptieren.";

TIP USE a BINARY SEARCH to find the offending line.

  1. get localized files back from translator.
  2. copy all Loclaizable.strings into your project localized folders.
  3. Open XCODE
  4. Clean all - in iOS Device/all Simulators
  5. Build
  6. Copy .strings file Error Validation failed: The data couldn't be read because it has been corrupted.
  7. Open the log navigator
  8. See which of the translations is corrupt.
  9. I opened the Localizable.strings in TextWrangler At bottom in tool bar Translator had sent back UTF-16 file as

UTF-16 Little Endian Changed it back to just 'UTF-16' 10. Cleaned build/Build SAME ERROR

Somewhere in the file is

Missing semicolon?

/* popup message */
"Save mix" = "Enregistrer le mixage";

/* popup message */
"Save mix" = "Enregistrer le mixage"

"Extra "double quotes" inside double quotes"

WRONG

/* popup message */
"Save mix" = "Enregistrer le "mix" age"

RIGHT

/* popup message */
"Save mix" = "Enregistrer le mixage"

ALSO RIGHT

/* popup message */
"Save mix" = "Enregistrer le 'mix'age"
  • remember there may be more than one error in a file I found "KISS" in double-double quotes in two places
Lyte answered 29/3, 2012 at 13:4 Comment(0)
S
8

Check your file encoding. This is often caused by extended characters (like accented characters) and a non UTF encoding. In particular there is a bug in XCode 4 that if you copy accented characters into a strings file from Safari it will then save as Western Mac OS Roman.

Shrewish answered 21/4, 2011 at 16:30 Comment(2)
Yes, my strings file somehow got re-set to UTF8 encoding, setting it to UTF16 allowed building to succeed.Radborne
Even though I only had valid UTF-8 characters, changing my files to UTF-16 fixed this error.Fipple
T
7

It's a shame that XCode's syntax checker can't figure this out.

You can also copy the text into Text Wrangler (something I do after receiving a file from a translator) to check for properly quoted strings or run a regex checking for semicolons. The syntax coloring in Text Wrangler will show mis-quoted (or mis-escaped) strings where XCode's strings editor currently does not.

Thereof answered 16/10, 2011 at 23:23 Comment(2)
TextMate does the same thing.Dulia
TextWrangler (which is now BBEdit) with its syntax coloring is a great way to check for issues on the file. In my case there were blank spaces which were not normal. View > Text Display > Show Invisibles will show you those problematic characters.Weatherglass
G
6

In my case, plutil -lint Localizable.strings didn't help because the error message it produced was "Unexpected character " at line 1" when the real error was a instead of a " on line 2340.

Gaol answered 5/11, 2014 at 14:31 Comment(0)
W
2

In my case, it was a problem of "quote" sign copy-pasted from a website, that was not accepted.

I should have detected that from syntax-highlighting not working, but I just read the source "quote sign, key, quote sign, equality sign, quote sign, value, quote sign... yup okay".

Wrand answered 20/12, 2011 at 10:54 Comment(0)
F
2

If you use double quotation "" in your localisation, don't forget to escape them using a back slash.

Flammable answered 31/12, 2014 at 10:47 Comment(0)
D
2

One should Check syntax like this

"Recharge_Data" = "Data";

1) "" should be there on proper place.

2) = should be checked.

3) ; should be there at end of statement.

Discomfit answered 12/8, 2015 at 9:51 Comment(0)
H
1

In Xcode 14, there is a convenient solution for this issue.

Follow these steps to resolve it:

  1. Right-click on the affected Localizable.strings file.
  2. Select Open As and then choose ASCII Property List from the submenu.
  3. This action will prompt a popup that displays the line number and error message.

By following these steps, you can easily identify the problematic line and address the error in your Localizable.strings file.

See attached screenshots: Click on the localizable and select Open As menu

Xcode Alert Error Message

Hemimorphic answered 13/6, 2023 at 15:52 Comment(2)
#76470238Alane
Most useful answerMethodius
P
0

I have had the same problem. I had a about 60 pages long localization file, and had just one " too many - took a while to spot that

Prow answered 28/1, 2013 at 20:19 Comment(0)
T
0

I'd the same issue for a big localized file from an hour and apply all above steps won't solve my problem, finally what I am done with is, devide localize file into some ranges (parts), say part-a, b, c ... and cut those strings from file, and keep those in a text file, build the project again, unless and until I reached to the point, where only part-k was left, I found that by mistakenly I pressed f on my keyboard..fewww! it solved. I know this is not a solution but may be help to someone like me:)

Tsui answered 21/2, 2013 at 6:18 Comment(0)
S
0

My friend did translation for me in Windows. I found, that changing encoding doesn't help, so what I did: I commented all of the strings, and then I uncommented a few and pressed cmd-B, to find out which strings had problems. Then I rewrote problem strings manually and after that it worked.

Sermon answered 20/2, 2014 at 16:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.