0

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 `('
Community
  • 1
  • 1
Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109
  • I think it's talking about the first parenthesis. `grep -i -r -I (` I think it needs a quoted string. – Laurel Apr 28 '16 at 20:11
  • why can't you use the export/import tool in xcode? – Eugene Gordin Apr 28 '16 at 20:16
  • I always want to use it, but the translation guys who work for our company doesnt want us to use it.Hence the hard way!@EugeneZhenyaGordin – Teja Nandamuri Apr 28 '16 at 20:18
  • If you plan to localize your app, you need to use `NSLocalizedString` for every string in your code that you need to localize. Update your code base once and do it right. It will save you a ton of effort over time. – rmaddy Apr 28 '16 at 20:22
  • I agree @rmaddy, I will do that if I can't find any easier way. – Teja Nandamuri Apr 28 '16 at 20:23
  • That is the easier way in the long term. Your code may be full of strings that shouldn't be localized. In my own code, I flag such lines with a `// NO_I18N` comment. Everything else uses `NSLocalizedString`. Then you can use the proper tools to extract the strings and get the files that need to be translated. No need to scan some home grown list of strings and manually removing the lines that shouldn't be localized. Think how this will work over time as you update and add code. – rmaddy Apr 28 '16 at 20:26
  • That's the problem @rmaddy, I was given the task to do localization where the other developer team who developed this whole SDK didn't take care of localization. They didn't even left the flags or some sort of indication for the not localized strings. Now I have to manually go through each line and do find and replace.Hence I posted the question looking for the easier way to grab those strings in double quotes and send them to trnaslation, and in the meanwhile I could update each statemtn with NSLocalizedString.Again, I totally agree with your statement. I will update the question as I move on – Teja Nandamuri Apr 28 '16 at 20:32
  • atleast this out.txt file will guide me where the strings are :P – Teja Nandamuri Apr 28 '16 at 20:34

1 Answers1

0

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.

Eugene Gordin
  • 4,047
  • 3
  • 47
  • 80
  • Thanks for the answer, but when we do this, only the strings tagged as NSLocalizedStrings will be exported but not the plain strings. – Teja Nandamuri Apr 28 '16 at 20:20
  • storyboard localization is done, it is just these class files that are left. – Teja Nandamuri Apr 28 '16 at 20:21
  • 1
    that's correct...I've done localizations like that. It's easier to go and add NSLocalizedString to all the strings that have not being marked first, otherwise you'll have this pain all the time. Especially adding/changing strings. – Eugene Gordin Apr 28 '16 at 20:22