Error when adding localizable string file - ios

Copy Strings File Error Group
Localizable.strings:0: error: read failed: The data couldn’t be read because it isn’t in the correct format.
I added Localizable string and add 15 different language string file from info section.
The app was running before adding all localization to it. Not sure what causing this error.
Any help

make sure all the .string files contains format of translation as below:
"key"="translation";
"nav_profile"="Мой профайл";
missing semicolon or any other different format than above format in any line of any string file can generate this error.

Related

How to change new File method in Groovy?

How do I replace the new File method with a secure one? Is it possible to create a python script and connect it?
Part of the code where I have a problem:
def template Name = new File(file: "${template}").normalize.name.replace(".html", "").replace(".yaml", "")
But when I run my pipeline, I get the error
java.lang.SecurityException: Unable to find constructor: new java.io .File java.util.LinkedHashMap
This method is prohibited and is blacklisted. How do I replace it and with what?
If you're reading the contents of the file, you can replace that "new File" with "readFile".
See https://www.jenkins.io/doc/pipeline/steps/workflow-basic-steps/#readfile-read-file-from-workspace
readFile: Read file from workspace
Reads a file from a relative path (with root in current directory, usually > workspace) and returns its content as a plain string.
file : String
Relative (/-separated) path to file within a workspace to read.
encoding : String (optional)
The encoding to use when reading the file. If left blank, the platform default encoding will be used. Binary files can be read into a Base64-encoded string by specifying "Base64" as the encoding.

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

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";
Use plutil from the Terminal:
you have to run it for each version of the localizable file. E.g
cd into your project root
cd eb.lproj - you can replace this with
any localisation you are working with.
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
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.
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}}
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.
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!
There can be multiple reasons for this:
Semicolon is missing at the end.
Multiple semicolons at the end.
" within the message which should be escaped by \".
Extra character after semicolon.
Invalid white space in the file.
Other invalid characters in the file.
Merge conflict characters in the file!
<<<<<<< HEAD, ======= and >>>>>>>.
Please note that plutil -lint Localizable.strings returned OK for point-2 & 7!
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. :/
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.
Also make sure the strings file name is always Localizable.strings
I Had the same issue and i resolved it by commenting or removed unused strings in my Localizable.String file :)
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.
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" = "භාෂාව වෙනස් කරන්න";
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.
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.
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.
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
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
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.
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.
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
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/
In my case, I had one line with using ” instead of " and that breaks the file. My code editor did not detect this difference.
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
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.

Firefox addon localization

I have problem with localization my addon. I followed this tutorial on Using Localized Strings in Preferences but I can't compile my addon because I use polish characters ć and others.
I've made locale folder and put there pl-PL.properties file with this content:
my_tag_title = Co robić?
and I got error:
Following locale file is not a valid UTF-8 file: C:\path\pl-PL.properties
'utf8' codec can't decode byte 0xe6 in position 22: invalid continuation byte"
Is there way to put special characters directly inside package.json?
How to solve this problem?
Make sure that the locale file is saved in UTF-8 format.

Localizable.strings in German

I am localizing an app into German using Localizable.string.
All well until I need to use a ü or ß type letter in the localized string.
I get an error when building.
de.lproj/Localizable.strings:0: error: validation failed: The data couldn’t be read because it has been corrupted.
Example;
"Simple introductions and alphabet" = "Einfache Begrüßungen und das Aphabet";
Anyone out there with a solution?
Thanks
In my case neither of the other answers fixed my problem. After spending some time with searching for help, I somehow noticed I forgot a semicolon on the end of a line.
Admittedly this is a really basic error on my behalf, but the compiler could have told me my mistake instead of:
Validation failed: The data couldn’t be read because it has been corrupted.
So remember that strings table files have to be in the format
"Key" = "Localized Value goes here";
After conversation in comments the problem was solved.
If you will have similar problem then first of all you should check text encoding of file where error occurred. You can find current text encoding and change it in Xcode:
Open file in Xcode.
Press ⌥⌘1 (thanks #Jano)
Find field Text Encoding
Set it to Unicode (UTF-8)
Try to rebuild the project

Xcode: Localizable.strings: Conversion of string failed. The string is empty. copystrings failed with exit code 1

I use a Localizable.strings file and replaces the strings in my app with NSLocalizedString(#"KEY",#" COMMENT").
I replaced up to now a lot of strings and it worked well. I have added some more strings and now I have got the following error message :
CopyStringsFile
build/Debug-iphoneos/Australia.app/en.lproj/Localizable.strings
en.lproj/Localizable.strings cd
/Users/regisandre/Desktop/XCode/AUSTRALIAENINT
setenv ICONV /usr/bin/iconv setenv
PATH
"/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Library/Xcode/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/copystrings
--validate --inputencoding utf-8 --outputencoding binary en.lproj/Localizable.strings --outdir
/Users/regisandre/Desktop/XCode/AUSTRALIAENINT/build/Debug-iphoneos/Australia.app/en.lproj
en.lproj/Localizable.strings:
Conversion of string failed. The
string is empty.
en.lproj/Localizable.strings:
Conversion of string failed. The
string is empty. Command
/Developer/Library/Xcode/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/copystrings
failed with exit code 1
Update:
You are right ! It was a question of UTF-8/UTF-16 encoding. Once the file generated with genstrings, it is necessary to avoid copy/paste in the strings file from other files (even from Xcode) as it induces some encoding issues.
Once the file generated with Xcode, all the modifications have to be done directly in the file by "direct typing with the keayboard" ; no copy/paste ! (except if you are sure that the format you copy/paste is correct but it seems not so easy to know)
Check if it's UTF-8 encoding when it has special symbols in it.

Resources