Extract texts from XIB files for translation in human readable way - iphone

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);
This format is different that one expected by Localizable.strings.
It it confusing which texts to translate: a) this in commented line, b) one in uncommented line, c) or both maybe
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?

I wrote my own script in bash, which does the following:
Extracts all strings from all xib files in the directory
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.
Removes duplicates (I agree - sometimes it is not the best idea as translations may differ depending on context)
Removes comments (leaves just the juice)
Sorts alphabetically (optional)
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

Related

How to rename partly the downloaded file using wget?

I'd like to download many files (about 10000) from ftp-server. Names of the files are too long. I'd like to save them only with the date in names. For example: ABCDE201604120000-abcde.nc I prefer to be 20160412.nc
Is it possible?
I am not sure if wget provides similar functionality, nevertheless with curl, one can profit from the relatively rich syntax it provides in order to specify the URL of interest. For example:
curl \
"https://ftp5.gwdg.de/pub/misc/openstreetmap/SOTMEU2014/[53-54].{mp3,mp4}" \
-o "file_#1.#2"
will download files 53.mp3, 53.mp4, 54.mp3, 54.mp4. The output file is specified as file_#1.#2 - here, #1 is replaced by curl with the value of the sequence [53-54] corresponding to the file being downloaded. Similarly, #2 is replace with either mp3 or mp4. Thus, e.g., 53.mp3 will be saved as file_53.mp3.
ewcz's answer works fine if you can enumerate the file names as shown in the post. However, if the filenames are difficult to enumerate, for example, because the integers are sparsely populated, this solution would result in a lot of 404 Not Found requests.
If this is the case, then it is probably better to download all the files recursively, as you have shown, and rename them afterwards. If the file names follow a fixed pattern, you can select the substring from the original name and use it as the new name. In the given example, the new file names start at position 5 and are 8 characters long. The following bash command renames all *.nc files in the current directory.
for f in *.nc; do mv "$f" "${f:5:8}.nc" ; done
If the filenames do not follow a fix pattern and might vary in length, you can use more complex pattern substitution using sed, see SO post for an example.

Using diff3 where filenames contain a dash (-)

I'm trying to use diff3 in this way
diff3 options... mine older yours
My problem is that I probably can't use it, since all my 3 files contain a "dash" within.
The manual mentions:
At most one of these three file names may be `-', which tells diff3 to read the standard input for that file.
so I probably have to rename filenames before running diff3.
If you know for a better solution or a workaround, please let me know about. Thank you!
At most one of these three file names may be `-', which tells diff3 to read the standard input for that file.
It does not state, that your filenames should not contain dash symbols. It simply says, that if you want to, you can put - instead of one of the names, in which case the standard input will be read instead of reading one of the files.
So, you can have as many dashes in your filenames as you like and diff3 should work just fine.
However, on Windows putting filenames in "" for escaping space characters does not work, and I failed to find a suitable workaround. However, you can automatize the process of renaming files (if the files are relatively small, this would not even be too inefficient):
#echo off
copy %1 tempfile_1.txt
copy %2 tempfile_2.txt
copy %3 tempfile_3.txt
"C:\Program Files (x86)\KDiff3\bin\diff3.exe" -E tempfile_1.txt tempfile_2.txt tempfile_3.txt
del tempfile_1.txt tempfile_2.txt tempfile_3.txt
Put this in a file like diff3.cmd, then run diff3.cmd "first file.txt" "second file.txt" "third file.txt".
P.S. Moving files would be more efficient (if they are on the same disk volume as the script, which they are not in your case), you could even move them back to where they were initially, but for some time they would not be present at their original folder.

Rename file containing '©' character

We received as input in our application (running on Windows) a list of files. These files were automatically extracted from a database with a script.
Apparently some of the names are containing special characters (like accents) and these characters are rendered as '©' on our side.
How can rename programmatically these text files (around 900'000) to get rid of this character?
We cannot change the source neither re-extract the files.
The problem is that because of this character another program involved with our system does not accept the files.
Have a look at the unix command rename. It allows you to apply a perl regex to the names of a bunch of files. In this case you might want something like:
$ rename 's/[^a-zA-Z0-9]//' *
In debian the rename command is part of the perl package. It should also be available on CPAN.
I ended up creating a new script that reads the input files and search for special characters in their title.
It was quite easy indeed:
string filename = filename.Replace("©", "e");
Since the '©' is in the filename, the script (in C#) is able to recognize it and replace the match accordingly. In this way I can loop through all the folders and subfolders simply reading the filename and change specials characters.
Thank you all for the contributions!

Localizing Xcode source files using genstrings?

I've gone trough my source files and updated all my strings using the NSLocalizedString() macro. Now because I have a lot of strings that come up across multiple source files , I decided to place a large amount of the strings in a header file called "LocalizedStringDefinitions.h" using the #define directive. So for example each line looks like this,
#define kLocalizedSTRINGNAME NSLocalizedString(#"STRINGNAME", #"Comment")
I just ran the genstrings command in terminal and the Localizable.strings file that was created contained only the localized strings that were directly placed in my code and none of the #defined ones. I have around 100 lines of #defined strings which I do not want to place back in my code especially because they appear across multiple files. How can I localize the strings?
I just realized how simple this is. If you look a the Terminal command genstrings *.m the .m part is clearly specifying to look through the implementation files. The file with the #define's is a header file (.h) so by using the command genstrings *.h I was able to generate the .strings file, or I could just change the name of the file with the definitions to "LocalizableStringDefinitions.m"

Cocoa/iPhone: How to I keep ibtool from outputing non-localizable strings in a xib file?

I'm working on internationalizing an iPhone application, and I'm using ibtool to extract the string from my xib files so they can be translated by a localization house like so:
ibtool --generate-strings-file BlahBlahView.strings English.lproj/BlahBlahView.xib
The problem with this is that the .strings file I end up with contains all the strings contained in the xib when I really want the subset that I actually care about for i18n. Is there any best best practice for dealing with this? Ideally I'd like to be able to add some kind of annotation in interface builder to say either "This is localizable" or "This is not localizable" and have ibtool only output the localizable strings when I run it.
Thanks!
Edit: OK, let me expand the parameters a bit. The solution doesn't need to use ibtool only. Ibtool + some data in the xib + a shell script is fine. As long as it works!
Ibtool is extremely verbose in its string-files output and generates stirngs by object-id, instead of by unique source string.  This type of output is extremely useful when you're trying to re-create interface builder or otherwise need extensive control over the objects in your xib files, but less so when you simply want to localize your software.
Matteo at Digitalwaters.net found a way to convert the output from ibtool to and from the format used by nibtool, its predecessor, which was less powerful, but a lot easier to use for localization. More info here.
I have re-purposed his scripts to streamline the localization of our Mac OS X app, and they work well for me.  Good luck :)
I think you can automate this, but it'll take a few steps. You can extract arbitrary properties from your xib using ibtool, so maybe you could set the tag of the non-localizable items to a particular value (-1, for example), then extract the tags and use that to filter the strings file and remove the unwanted entries.
check out the man page for ibtool, in particular the -export option.
ibtool doesn't output entries for empty strings. So, for example, if you leave a UILabel's text empty, it won't be included in the output of ibtool --generate-strings-file. You can then set the text of the elements in the view controller.