Localizable.strings - The data couldn’t be read because it isn’t in the correct format
Asked Answered
K

24

102

If I copy something from textedit or web and paste it to localizable file it shows this compilation error. If I type those in localizable file it does not show any error. I am assuring you that I using the correct format and ';' in the file.

"New" = "New";
"In Progress" = "In Progress";
"Waiting" = "Waiting";
"Closed" = "Closed";
Keitt answered 25/10, 2017 at 4:49 Comment(0)
K
-2

It seems like SVN is having some issue with this file. As it consider it to be a binary file. It is inserting a lot of non printable characters between each characters. I still couldn't find a proper solution. Just changing the Localizable.string files from production PC for avoiding any issue with it.

Update: Updating the SVN client (smartSVN) to the latest version solved the issue. It seems one of my colleague was using a older version. When he commited the change to localizable file it caused the error.

Keitt answered 19/11, 2017 at 10:47 Comment(0)
C
211
  • Use plutil from the Terminal:

you have to run it for each version of the localizable file. E.g

  1. cd into your project root
  2. cd eb.lproj - you can replace this with any localisation you are working with.
  3. plutil -lint Localizable.strings

When you run step 3, you will either be shown an error, telling you what is wrong with your file. Or you will be told the file is OK

Note that plutil output is bad, it seems it always says "Unexpected character at line 1" but above that output, it prints other stuff like missing semicolon on line 121, and that is the real error

Cryptology answered 25/10, 2017 at 5:0 Comment(5)
It shows me Unexpected character " at line 1, and it is the first string like "app_name"="Any Name"Christianity
Note that plutil output is bad, it seems it always says "Unexpected character at line 1" but above that output, it prints other stuff like missing semicolon on line 121, and that is the real error...Eyeshade
For me plutil was showing the same error at line 1, although there wasn't any. But pl < Localizable.strings worked for me.Thermostatics
@ChanchalRaj you just saved me sooooo much time ty! That commend workedAmboise
plutil doesn't work. Only pl.Adiel
G
78

For me, it was missing semi-colons. If you use a tool to generate .strings file, make sure there are no un-escaped quotes that may 'eat' the delimiting semi-colons.

Granada answered 4/12, 2017 at 11:11 Comment(0)
F
65

Fastest way to detect the line with the issued string is to :

  • right click the strings file and
  • then Open as/ASCII property list.

Xcode will immediately tell you in what line there's an error.

Foulup answered 20/10, 2021 at 8:46 Comment(3)
Superb solutionTextuary
Very easy to identify the issueJuggle
Wowwwwwwwwwww!!Marcionism
N
45

pl < Localizable.strings is better than plutil -lint Localizable.strings

Log will show something like this

2019-08-14 16:39:34.066 pl[21007:428513] CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary on line 427. Parsing will be abandoned. Break on _CFPropertyListMissingSemicolon to debug. 2019-08-14 16:39:34.068 pl[21007:428513] CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary on line 427. Parsing will be abandoned. Break on _CFPropertyListMissingSemicolon to debug. 2019-08-14 16:39:34.071 pl[21007:428513] *** Exception parsing ASCII property list: NSParseErrorException Error Domain=NSCocoaErrorDomain Code=3840 "Unexpected character / at line 1" UserInfo={NSDebugDescription=Unexpected character / at line 1, kCFPropertyListOldStyleParsingError=Error Domain=NSCocoaErrorDomain Code=3840 "Missing ';' on line 427" UserInfo={NSDebugDescription=Missing ';' on line 427}}

Nightwear answered 14/8, 2019 at 8:44 Comment(4)
This is the best solution and it resolved my problem. "plutil" shows an error on the 1st symbol, but "pl < Localizable.strings" is really better and it show the proper number of line where you have a problem with *.plistShiri
Definitely the better solution. It gives you more information and the line number for the issue, rather than a generic output.Hangnail
this helped me easily find the root causePliske
This is the best solution!Amboise
I
12

I know this question was asked long ago but my scenario and solution is little bit different. Today I faced same issue but when I tried to check the issue using

plutil -lint Localizable.strings

I got OK status which means everything is fine, then I tried to find issue using

pl < Localizable.strings

But again I got file text printed with no error mentioned, then I tried a trick and it worked for me.

  • Right click on the Localizable.strings file
  • Then select option Open As option
  • Then select option ASCII Property List

That's it, XCode shows me the issue with line number and the issue was I had this DéjàVerified text as key on specified line, this helps me to identify and solve the issue, I hope it will save someone's time.

Cheers!

Irresponsible answered 4/12, 2020 at 12:34 Comment(1)
Where can we read the docs for this pl command? Can't find the < anywhere; anyway this should be part of Xcode and tell us where exactly is the problem instead of telling us to go find a wrong char in a file with hundreds of thousands of chars! stupid... open as ASCII Property List is not working here.Martinsen
K
11

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!

Kahl answered 8/7, 2020 at 13:47 Comment(1)
this is the second time I have this problem because of missing Semi-colon. I had a very long error log but they could not bother to mention a missing Semi-colonWhiles
O
6

In my case, I was missing "=" between a string pair. Even plutil did not help me to spot the error line. I manually checked each string pair. :/

Outstretched answered 21/1, 2019 at 14:35 Comment(0)
S
4

Your syntax seems to be fine, the only thing that I can see can "break" your file and cause this error is the quote character. Make sure to use the reqular one " and not in any other form like for example.

Salbu answered 25/10, 2017 at 4:58 Comment(2)
No it's not the case. There are some non printable character in the strings! May be its related to xocde update or something!Keitt
You can post it in your answer and we can analyze it. Hard to say what’s not working with the little info you’ve provided so far.Salbu
C
3

Also make sure the strings file name is always Localizable.strings

Canaday answered 14/3, 2019 at 23:5 Comment(0)
C
2

I Had the same issue and i resolved it by commenting or removed unused strings in my Localizable.String file :)

Continuate answered 22/12, 2017 at 9:14 Comment(1)
My SVN is considering the .string file as binary file. Are you sure you ran into something like this?Keitt
C
2

I once had a similar error and it turned out that there was an URL in the middle of the file, like this:

// Some Comment 1
"Some key 1" = "Some value 1";
http://...whatever...
// Some Comment 2
"Some key 2" = "Some value 2";

When calling plutil -lint on that file the output was:

Unexpected character / at line 1

Well, the first character indeed was / as the file started with a comment but the problem resolved after removing the URL; or turning it into a comment which it actually should have been. Note that the URL was nowhere near the beginning of the strings file, it was about in the middle of a 6000 lines string file. I was only able to find it by browsing through commit history and always look at the changes.

Cockatiel answered 1/4, 2019 at 17:19 Comment(0)
P
2

if missing ";" at end of the all lines in Localizable.string file, this error can occur.

eg :- "header_text" = "Current Language"; "change_language" = "Change Language";

"header_text" = "වත්මන් භාෂාව"; "change_language" = "භාෂාව වෙනස් කරන්න";

Precognition answered 27/4, 2020 at 3:18 Comment(1)
Great, Thanks bro, Saved my day (Y)Brinton
S
2

This tool can help solve this problem, just select your localizable.strings file, it will help you find out which line format is wrong, it can save a lot of time

https://localizable.appdevtool.io/

Stir answered 17/11, 2022 at 7:45 Comment(0)
S
1

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-%E7%BF%BB%E8%AF%91%E6%96%87%E4%BB%B6%E5%B7%A5%E5%85%B7/id1268616588?mt=12,

you only need to drag Localizable.strings to the software and it will It is useful to tell you which line in the file may have a problem. It saved me a lot of time. Now I share it with you.

I hope it will be helpful to you.

Stir answered 14/3, 2021 at 16:12 Comment(0)
B
0

It seems your info.plist is not in correct form . check it properly. I also had the same issue . I resolved it by modifying my info.plist.

Ballplayer answered 12/2, 2018 at 11:12 Comment(0)
Z
0

I just had this experience:

  • external translator doing the work inside Visual Code or other text editors
  • Files not working and getting an error like this one: ( testing with plutil -lint )

    Localizable.strings: Unexpected character " at line 1 CardRatingView.strings: Unexpected character / at line 2

I just created a new file within XCode and copy pasted all the file content and suddenly everything was working properly.

I guess something can go wrong / corrupting the file itself while working with other text editors.

Zoography answered 14/8, 2018 at 10:23 Comment(0)
A
0

If showing something like Unexpected character " at line 1, and it is the first string like "app_name"="Any Name"

Check that the file is UTF16

Acker answered 14/3, 2019 at 0:31 Comment(3)
Why? String files are allowed to be UTF-8 as well. All my string files are always UTF-8 and that has never been a problem. Actually there is an Xcode setting that allows you to choose which files Xcode shall write on output when copying string files and even that setting allows you to choose UTF-8, UTF-16 or binary.Cockatiel
Hey yeah, I've realized later what you are describing. I think the error is due to Xcode thinking the file is in one encoding, while factually it's in another.Acker
UTF-16 files require a BOM. If there is no BOM, macOS usually assumes UTF-8. But if you want to use UTF-8 in a place where UTF-16 is expected, this often works as well if you place an UTF-8 BOM (BOMs are optional for UTF-8 but macOS usually recognizes them). de.wikipedia.org/wiki/Byte_Order_MarkCockatiel
C
0

I ran into this issue, all my formatting was correct. Checking for illegal characters using plutil -lint Localizable.strings and using ruby libraries like "utf8_utils" also didn't work at finding the illegal characters. BUT when I pasted the Localizable.strings contents into the Terminal app while running irb, it did show me the weird characters.

"PercentComplete" = "%d procent gennemført";

Pasted into irb:

"PercentComplete"\U+FFC2\U+FFA0= "%d procent gennemf\U+FFC3\U+FFB8rt";

Then all I had to do was a regex replace to fix those weird white space characters: \U+FFC2\U+FFA0

Cesena answered 3/7, 2019 at 17:23 Comment(0)
M
0

Thanks to the plutil suggestion I understood that to make it work you have to delete also any \ or * as are not read as comments and, important, add a ; to the end of the file. Xcode 11.5.

Minerva answered 12/6, 2020 at 8:18 Comment(0)
R
0

If pl and plutil show no problems, check the file's encoding. I had a similar problem twice and in my case it was due to incorrect encoding, though I have no idea how it has been changed (I literally added a single line in the middle of the file in X-Code). Converting from UTF-16LE to UTF-16BE in some editor (I used Android Studio) fixed the problem.

Redo answered 17/2, 2021 at 9:42 Comment(0)
E
0

For me I had an NSLocalizedString in my code that contained a string interpolation e.g. NSLocalizedString("\(product.price ?? "")per_month"). When I exported localisations this got added to my strings file, which was then in the wrong format. It threw me off because my strings file in Xcode looked fine, but actually the file gets updated as part of the export localisations process, and errors were creeping in there.

If anyone things they might be having the same issue try calling genstrings separately and seeing if the newly generated file is in the correct format. Make sure you save your strings first as this will overwrite your strings file : find ./ -name "*.swift" -print0 | xargs -0 genstrings -SwiftUI -o en.lproj

Electromechanical answered 2/6, 2021 at 8:48 Comment(0)
M
0

In my case, I had one line with using instead of " and that breaks the file. My code editor did not detect this difference.

Misguided answered 23/11, 2022 at 11:33 Comment(0)
B
-1

I was having the similar issue where i didn't escape the string value with backslash \ for one of my string's value.

Before:

"INVALID_NUMBER" = "It seems you're entering invalid number. Number should starts with "0" or "7"";

Updated:

"INVALID_NUMBER" = "It seems you're entering invalid number. Number should starts with \"0\" or \"7\"";

Backslashes are required when you want to display the quotation marks "

Please, have a quick look at here for How to include Quotation mark in strings

Bondholder answered 23/4, 2018 at 5:40 Comment(0)
K
-2

It seems like SVN is having some issue with this file. As it consider it to be a binary file. It is inserting a lot of non printable characters between each characters. I still couldn't find a proper solution. Just changing the Localizable.string files from production PC for avoiding any issue with it.

Update: Updating the SVN client (smartSVN) to the latest version solved the issue. It seems one of my colleague was using a older version. When he commited the change to localizable file it caused the error.

Keitt answered 19/11, 2017 at 10:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.