I'm using NSLocalizedString() for all localization stuff. The project is very big. We support many languages. Is there a way that I can easily extract strings that are not in the Localizable.strings but were wrapped with NSLocalizedString.
Example.
Let's say I have somewhere in my code:
NSString *message = NSLocalizedString(#"Sample message");
But developer forgot to put this string in Localizable.strings files, so it won't be translated. Is there a way to extract untranslated strings from the source code?
Also, I don't want to use genstrings tool. I already have a very big NSLocalizable.strings files. genstrings tool generates a new one with all strings wrapped with NSLocalizedString removing all former translations, which I do not want. I just want to extract untranslated strings and NOT ALL the strings marked with NSLocalizedString().
Thanks,
Rafal
Check out the genstrings tool, that does exactly this.
EDIT:
Try merging the genstrings generatet strings file with your existing one using the FileMerge tool in XCode (XCode > Open Developer Tool).
Generate Localizable.strings from XCode project http://xcode.fabriziobernasconi.it/
Related
So, in my project I have 10 languages, and 10 Localizable.strings files.
I just created Localizable.strings files, a file for each language. Now they contain "key" = "value" pairs, and both keys and values are in English (default language).
My languages are all translated and stay in Excel files.
The question is, how can I insert all my languages in those files faster than just copying each word manually or writing a script for that?
Maybe there is a existing tool for this already?
Thanks.
I found an easy way to compose localizable.strings files from Excel documents.
In the Excel document, in specific columns I insert " " = " " symbols. It's easy to do for all the words by dragging Excel cell down from the corner, so that it copies stuff from that cell to all the cells you drag it to. (sorry for messy explanation)
Thus the document contains the same symbols and words as localizable.strings does.
Than I just copy everything to the text file, remove tabs, change extension to .strings.
(no comments saved unfortunately).
EDIT:
You can copy the stuff from Excel to Sublime Text, then Find & Replace tabs if any. Copy resulted stuff into proper Xcode .string file.
One application that will really save you a lot of time by automating and streamlining localization procedure is Localization Suite. I do not know if they support importing from excel (to save you time transferring your string pairs) but it's free and seems like a complete solution.
I had an internal script at work for doing that tasks in iOS and Android, and I've just opensourced it as a Gem. You can take a look at it here: http://github.com/mrmans0n/localio
It can open spreadsheets from Google Drive and local Excel files as well, like requested.
You just would have to install the gem
gem install localio
And have a custom DSL file in your project directory, called Locfile, with the info referring to your project and the localization files. An example in your case, where an Excel file is used, could be as simple as:
platform :ios
source :xls, :path => 'YourExcelFileGoesInHere.xls'
output_path 'Resources/Localizables/'
The .xls file should have a certain format, that probably is very similar to what you have right now. You just have to clone the contents of this one and fill it with your translations: https://docs.google.com/spreadsheet/ccc?key=0AmX_w4-5HkOgdFFoZ19iSUlRSERnQTJ4NVZiblo2UXc
Hope this helps.
Here are the steps i followed:
change the extension of .strings to .txt on windows
open excel and go to File > Open
Choose the file to open. This should present an import wizard
Follow the steps and specify the delimiting character as =
You're done
Is there a tool that will extract strings from my source code, and replace them with constant names so that I can auto-generate the strings file I need to translate?
Or do I need to search my project for #" and evaluate each string to see if it should be localized, and then move it by hand to a strings.h file?
I have read about two tools to help localization:
ibtool, to deal with xib files
genstrings to generate a strings table
As far as I know, both are included in Mac OSX, but I didn't use any of them.
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"
I created a View-Based project in Xcode, but I find no Localizeable.strings file for doing my localization. Must I run genstrings first to create this? Or did I do something wrong?
You need to declare all your localizable text with NSLocalizedString before running genstrings will produce anything useful.
I would recommend declaring all your text definitions with NSLocalizedString instead of inside Interface Builder XIBs as it is easier to get a text file translated than a XIB file.
Just make sure to allow 50% more space than you need for your English strings, as English is generally more concise.
Yes, genstrings creates the Localizeable.strings file. You can run it from the command line like this:
genstrings Classes/*.m
I found this tutorial to be helpful.
Indeed, you must run generate strings,
ibtool --generate-strings-file Example.strings en.lpoj/Example.xib
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.