How to extract the strings in double quotes for localization - objective-c

I'm trying to extract the strings for localization. There are so many files where some of the strings are tagged as NSLocalizedStrings, and some of them are not.
I'm able to grab the NSLocalizedStrings using ibtool and genstrings, but I'm unable to extract the plain strings without NSLocalizedString.
I'm not good at regex, but I came up with this "[^(]#\""
and with the help of grep:
grep -i -r -I "[^(]#\"" * > out.txt
It worked, and all the strings were actually grabbed into a txt file, but the problem is ,
if in my code there is a line:
..... initWithTitle:#"New Sketch".....
I only expect the grep to grab the #"New Sketch" part, but it grabs the whole line.
So in the out.txt file, I see initWithTitle:#"New Sketch", along with some unwanted lines.
How can I write the regex to grab only the strings in double quotes ?
I tried the grep command with the regex mentioned in here, but it gave me syntax error .
For ex, I tried:
grep -i -r -I (["'])(?:(?=(\\?))\2.)*?\1 * > out.txt
and it gave me
-bash: syntax error near unexpected token `('

In xcode, open your project. Go to Editor->Export For Localization...It will create the folder of files. Everything that was marked for localization will be extracted there. No need to parse it yourself. It will be in the XML format.
If you wanna go hard way, you can then parse those files the way you're trying to do it now ?! It will also have Storyboard strings there too, btw.

Related

Error: Bad character (ASCII 0) encountered in BigQuery

I'm trying to upload a CSV file to Bigquery, but I get the following error:
Error: Bad character (ASCII 0) encountered (bigquery)
I've tried the following, but none of this are working:
a) Open the file as save it as "UTF-8" in notepad.
b) Open the file in notepad++ and use the option "Search characters by type" - Non ASCII. Didn't find any character
c) Use notepad++ with the followings regular expressions, didn't find any character:
[^\x00-\x7F] and [^\x1F-\x7F].
d) Use the following command:
gsutil cp gs://bucket_987234/compress_file.gz - | gunzip | tr -d '\000' | gsutil cp - gs://bucket_987234/uncompress_and_clean_file
Didn't work: "tr" is not recognized as a command (I'm using windows 10 and I don't have access to a VM of google.)
d) Open the file and deleted the first row, then it worked. But i've lost a line of data, and I have thousand of files.
The trouble is that I need to automate the "cleaning" of this files.
How can I clean this file in Windows, Any idea about what else can this "ASCII 0" character or how to get rid of it?
Thanks!!
You can use a GitBash on your machine? If you can, I would recommend you using this.
cat -v filename
For example, I have created a file called TESTINGCAT.txt with three lines, which visually has 7 empty spaces. However, if you count spaces with notepad++ you will find just 5 because 2 of those empty spaces are "non-breaking spaces" generated by typing ALT + 0160. Below you can see that I have on Notepad++
However, if I use cat -v TESTINGCAT.txt I can see M-BM- characters, which according to this are non-breaking spaces
Therefore, if you do not have access to a Linux machine, you should try using GitBash to see the hidden characters in your file.

Running into issues with importing multiple CSV's into different collections using Keen's Command Line Interface

I have no problem importing one CSV file into a collection by using the keen-cli command
keen events:add -p xxxxxx -k xxxxxx -w xxxxxx -r xxxxxx --collection xxxxx --file xxxxxx.csv --csv
With -p, -k, -w, -r being key overrides to avoid installing dotenv and having to mess with an .env file.
This import works fine the first time until I try to repeat this with a different file and a different collection. By goal is to be able to compare both collections so I want to keep them in the same project but I always get the following error.
/Library/Ruby/Gems/2.0.0/gems/keen-cli-0.2.3/lib/keen-cli.rb:16:in `deep_merge': undefined method `keys' for "15:53:30":String (NoMethodError)
I know Keen allows for multiple collections in the same project so I'm not 100% sure what's going on here.
If one file is working and a seemingly identical file isn't working, try inspecting the not-working file for:
misc or missing spaces, commas, and carriage returns at the end of the text
misc or missing spaces, commas, and carriage returns at the end of lines
Figured it out!
Keen assumes that whatever your first column is will act as your unique key for the collection.
If there is any missing values in that list the entire thing fails.

Split a batch of text files using pattern

I have a directory of almost a thousand html files. Each file needs to be split up into multiple text files, based on a recurring pattern (a heading). I am on a windows machine, using GnuWin32 tools.
I've found a way to do this, for a single file:
csplit 1.html -b "%04d.txt" /"Words in heading"/ {*}
But I don't know how to repeat this operation over the entire set of HTML files. This:
csplit *.html -b "%04d.txt" /"Words in heading"/ {*}
doesn't work, and neither does this:
for %i in (*.html) do csplit *.html -b "%04d.txt" /"Words in heading"/ {*}
Both result in an invalid pattern error. Help would be much appreciated!
The options/arguments order is important with csplit. And it won’t accept multiple files. It’s help gets you there:
% csplit --help
Usage: csplit [OPTION]... FILE PATTERN...
I’m surprised your first example works for the single file. It really should be changed to:
% csplit -b "%04d.txt" 1.html "/Words in heading/" "{*}"
^^^^^^^^^^^^^ ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
OPTS/ARGS FILE PATTERNS
Notice also that I changed your your quoting to be around the arguments. You probably also need to have quoted your last "{*}".
I’m not sure what shell you’re using, but if that for-loop syntax is appropriate, then the fixed command should work in the loop.

In texinfo, how to specify a bash single quote?

I am writing a package using the GNU build system. The documentation hence is in the texinfo format. As a result, executing make converts the texinfo file into the info format, and executing make pdf automatically produces a pdf file.
In the texinfo file, I have something like this:
#verbatim
awk '{...}' data.txt
#end verbatim
However, in the pdf, the "basic" single quotes (U+0027) in the awk command above are transformed into "curvy" single quotes (U+2019) so that, if one does a copy-paste of the command from the pdf into a terminal, bash complains ("syntax error"). This forces the user to edit the command he just copy-pasted. Same problem occurs if I replace #verbatim by #example. I searched the texinfo manual but couldn't find a way to specify apostrophes. I am using texinfo version 5.2.
Karl Berry (via the bug-texinfo mailing list) told me to add 2 lines to my texi file (more info):
#codequoteundirected on
#codequotebacktick on
as well as add the latest version of texinfo.tex to my package.

How to make a variable out of the output of a unix command?

I'm trying to have a variable $totalLines that stores the total lines in a file (given as input $1).
I'm trying to do something like this:
totalLines= grep -c *.* $1
But Unix doesn't like that.
I've tried enclosing it in paranthesis, square brackets, and (), but that doesn't work either. This has got to be super simple but I'm searching for the answer around the web and not finding a page or forum that clearly states it.
Sorry to trouble you guys with such an easy one.
There are two ways to achieve it:
totalLines=$(grep -c *.* $1)
or
totalLines=`grep -c *.* $1`
Like:
totalLines=$(grep -c *.* $1)