Question

ibtool is the tool to extract strings from XIB files. Example command:

find . -name \*.xib | xargs -t -I '{}' ibtool --generate-strings-file '{}'.strings.txt '{}'

But output generated by ibtool is NOT READABLE for 'normal' (read: non-developers) human being.

Example:

/* Class = "IBUILabel"; text = "Regards:"; ObjectID = "201"; */
"201.text" = "Regards:";

There are few problems with it (from the perspective of translator);

  1. This format is different that one expected by Localizable.strings.
  2. It it confusing which texts to translate: a) this in commented line, b) one in uncommented line, c) or both maybe
  3. It has just a lot of clutter.

I need XIB strings extracted in Localizable.strings format (strings extracted from NSLocalizableString macros using genstrings:

 "key"="to translate";

It there a way to make ibtool output text this way?

Was it helpful?

Solution

I wrote my own script in bash, which does the following:

  1. Extracts all strings from all xib files in the directory
  2. Converts it to the .strings format (expected by NSLocalizableString macro). "text to translate"="text to translate"; It can be used directly by your translator.Only right side, text in quotes after = needs to be edited.
  3. Removes duplicates (I agree - sometimes it is not the best idea as translations may differ depending on context)
  4. Removes comments (leaves just the juice)
  5. Sorts alphabetically (optional)
  6. Saves result to the 1 output file (all merged and ready for translation)

Script is not perfect but it works quite well.

It has a bit too long to past it here (90 lines), so here is the direct GitHub link:

https://github.com/lukaszmargielewski/extract-strings-from-xib-files/blob/master/extract-strings-from-xib-files.sh

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top