6

I am working on an iOS app. It is working fine in Xcode 9.4.1, but when I build it in Xcode 10 it gives me following error:

Error

I tried the solution given in the following post by changing the encoding, but it didn't work. I tried it by both Reinterpret and Convert

enter image description here

still the same error:

enter image description here

It's working fine on Xcode 9.4.1

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Akshay Sunderwani
  • 12,428
  • 8
  • 29
  • 52
  • This sounds like a corrupted file, so it depends on what the file actually contains and what you expect it to contain. If I had to guess, I'd guess that this is the localization file for a Cyrillic language (maybe Russian?) and someone has encoded parts of it in UTF-8 and parts of it in 8859-5, possibly by incorrectly editing it (perhaps on Windows or with a non-UTF8 editor) – Rob Napier Sep 19 '18 at 18:55
  • Its working fine with the same file on Xcode 9.4.1, could there be anything else? Started happening in Xcode 10 only. – Akshay Sunderwani Sep 19 '18 at 18:58
  • 1
    The fact that Xcode 9 didn't check this file as closely doesn't suggest that the file is not corrupt. – Rob Napier Sep 19 '18 at 19:00
  • Try setting Text Encoding of that file to UTF 16 – onmyway133 Mar 07 '19 at 09:24
  • @onmyway133 -- I'm struggling with the same error message in Xcode 11. I have not been able to find *where* to set the Text Encoding of the file to either UTF-8 or UTF-16, nor anything except the error message that says what Xcode thinks the encoding is supposed to be. Could you (or someone) please point me to the right place in the Xcode 11 UI or the doc? Thanks. – August Aug 31 '23 at 19:49

6 Answers6

11

Find your Localizable.strings in a Terminal and execute:

$ iconv -f UTF-16LE -t UTF-8 Localizable.strings >  LocalizableNew.strings

Then check LocalizableNews.string and if there is no errors just replace files

$ mv LocalizableNew.strings Localizable.strings
Edward Brey
  • 40,302
  • 20
  • 199
  • 253
Eva Madrazo
  • 4,731
  • 2
  • 23
  • 33
7

I have similar error once i open my project in Xcode 10.4 and open it agian in Xcode 10.1.

I solved it by selecting my all Localizable.strings file and change there text encoding to UTF-16(In my case error was related to UTF-16 you can change it to UTF-8)

So changing the text encoding to UTF-16 or UTF-8 will works.

enter image description here enter image description here

guru
  • 2,727
  • 3
  • 27
  • 39
  • This is the best answer here, the file is encoded differently to what Xcode is expecting so all you need to do is tell Xcode what encoding to read. – Leon Dec 04 '19 at 11:40
4

It sounds like the file is corrupted, probably with parts of it encoded in UTF-8 and parts of it encoded in 8859-5. From its name, I would suspect this is a Cyrillic localization (perhaps Russian), and the file was probably edited using an editor that didn't correctly maintain encoding or use UTF-8 (the most common cause of that is editing on Windows).

You'll need to open the file, probably in an external editor that can handle random encodings like vim or Sublime Text, and fix any corruption. Exactly how to do that depends on the nature of the corruption.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
2

You need to set correct Text Encoding in the File Inspector. The default is UTF-8.

marko
  • 1,336
  • 2
  • 12
  • 25
  • I appreciate your answer, but, if you look at the information provided in the question, you will find that I have already tried this solution. The file itself was corrupted, so, changing the file worked perfectly fine. – Akshay Sunderwani Nov 21 '18 at 14:43
  • This helped me after I had converted a file from UTF-16LE to UTF-8 using `iconv` without realizing I had to notify Xcode to reinterpret the file. Thanks! – Warpling Feb 28 '19 at 14:28
2

If you want to fix the problem without UI, you need to look for the XCode project definition (generally YOURPROJECT.xcodeproj/project.pbxproj), then find the reference to the file causing an issue.

You should find something like this (from Adium, in this case)

D182F1B611DFF23700E33AE2 /* sk */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = sk; path = sk.lproj/schema.strings; sourceTree = "<group>"; };

fileEncoding = 10 is UTF-16; 4 is UTF-8, which is currently the default, so you can either set it to that value explicitely, or simply remove the fileEncoding bit altogether.

shtrom
  • 71
  • 1
  • 6
0

I got this error message when I forgot to put semicolons at the end of the line to separate the individual translations.

Palimondo
  • 7,281
  • 4
  • 39
  • 58