How can I validate Localizable.strings file in Xcode?
Asked Answered
M

3

9

How can I check if there are any errors in the file and where I am getting these errors? In the other words, How can I debug Localizable.strings file in Xcode ?

Marchant answered 2/12, 2016 at 8:39 Comment(0)
D
28

Unfortunately, Xcode dosesn't show line with error. If you or another developer was changing Localisable.strings recently, probably one of added / changed lines is missing semicolon at end (see answer under this question: Localizable.strings corrupted? ). If file is big and / or error is not easy to see probably lucianoenrico answer will be helpful. I will quote it now:

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.

If it is a semicolon issue you can also open corrupted file, search for ";" and look for line without highlighted ";" at end. Also look for block comments without closing "*/" and unescaped or incorrect quotation marks (need \"). This last issue is visible because part of string changes color.

Duplessis answered 2/12, 2016 at 9:21 Comment(3)
Wiki said xx.strings is kind of reduced plist file.Selfsupporting
@Selfsupporting yes, and plutil is tool for plists. But .strings file is so reduced, that you can't view it "as plist" in Xcode, making even detection of errors harder (plus no braces making analyzing harder). In case of corrupted normal .plist or even .stringsdict it is at least faster to detect corrupted file.Duplessis
This tool saved me months !Exploratory
F
1

I recently released an open source tool, Locheck, that does exactly what you're asking for. It validates your .strings and .stringsdict files (and Android strings.xml files as well) for common errors.

Funeral answered 8/11, 2021 at 22:39 Comment(0)
G
0

I'd suggest using a tool like https://github.com/SwiftGen/SwiftGen, which will fail to compile if a file contains an error. You then get compile time errors if the file is invalid as well as if you accidentally remove a key that you are using in your app.

Greathouse answered 20/10, 2020 at 14:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.