Localizable.strings corrupted?
Asked Answered
F

7

29

I'm trying to include the internationalization of my application, and only for testing purposes I added a simple line in the file Localizable.string.

This is my whole file:

"Test locale" = "Test locale"

And when I try run my application I get this error:

Localizable.strings:0: error: validation failed: The data couldn’t be read because it has been corrupted.

I've tried changing the "Text Encoding" to UTF-16 but nothing resolved.

Fulfil answered 16/4, 2012 at 20:34 Comment(1)
here is a library that might help you to localize project github.com/dipkasyap/DGLocalizationChildbed
M
58

If this is your whole file, add a semicolon at the end. Change it to:

"Test locale" = "Test locale";

Malva answered 16/4, 2012 at 20:51 Comment(1)
Learning iOS first time with swift comming from Android, this is actually a really annoying mistake...Dowie
G
45

To get more detailed informations you can use the Property List utility from the command line:

plutil -lint <your_strings_file>.strings

the -lint switch is for checking the syntax. If you have an error you'll get line number and more informations, and in general better directions on how to fix the issue.

Graehme answered 4/9, 2015 at 10:51 Comment(6)
Thanks, exactly what I needed. Way too big of a file to check by hand.Warhol
Is there a way to integrate this command into the Xcode build ?Pemberton
Never tried, but this is what you can try: you can add a run script phase in "build phases" and, in this phase, call a script that checks all of your .strings files. You can drag the script phase on top of the others (or drag the others down) in order to execute tour script pre-build. it you set XCode -> Preferences -> Building -> Build options "Continue building after errors" then the build stops if the script fails.Graehme
In order to stop the process and fail the build you can simply terminate your script with an exit code other than zero. As an example if something goes wrong you can use "exit 1".Graehme
If plutil -lint reports "OK", does not necssarily mean that there are no errors. For example I had the problem that there were unescaped quotation marks within my strings, but the Linter said the file was OK. So I would say you can trust plutil -lint if it reports errors but not if it reports OK.Virg
It's sickening that Xcode itself doesn't show any line numberings for these errors and you have to run an external tool :/Primula
G
7

You can verify your Localizable.strings file with this script:

https://github.com/dcordero/Rubustrings

Gremlin answered 5/10, 2014 at 1:20 Comment(0)
S
4

In my case, it was like this:

/* Comment for Very Long Sentence */
"Very Long Sentence Very Long Sentence Very Long Sentence Very Long Sentence " =;
"Very Long Sentence Very Long Sentence Very Long Sentence Very Long Sentence ";

(Notice the ' = ; ' instead of ' = ' at the end of the first line)

Samovar answered 17/7, 2012 at 11:19 Comment(0)
L
1

In my case it was brackets inside string — I needed to add slash before \".

Led answered 26/9, 2013 at 16:43 Comment(0)
G
0

I've made a little script to check whole folders .strings files using plutil.

https://github.com/CarlesEstevadeordal/check_strings

Gilroy answered 5/10, 2015 at 16:59 Comment(1)
A simple command is enough: find . -name '*.strings' -exec plutil -lint {} \;Pasture
M
0

There can be multiple reasons for this:

  1. Semicolon is missing at the end.
  2. Multiple semicolons at the end.
  3. " within the message which should be escaped by \".
  4. Extra character after semicolon.
  5. Invalid white space in the file.
  6. Other invalid characters in the file.
  7. Merge conflict characters in the file!

<<<<<<< HEAD, ======= and >>>>>>>.

Please note that plutil -lint Localizable.strings returned OK for point-2 & 7!

Madaras answered 26/5, 2022 at 13:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.