Localizing Xcode source files using genstrings? - iphone

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"

Related

what is sharp sign in the name of .cpp files?

Sometimes when I create .cpp or .sh files, for example, a.cpp, I see another file created and named #a.cpp#, I'm using ubuntu, what is that file?
According to http://www.gnu.org/software/emacs/manual/html_node/elisp/Auto_002dSaving.html, this is the notation how emacs handles its autosave files.
After closing and saving the file, it should dissapear.

Splitting Phing build file

I've got a huge phing build file here. Is there a way to put things like filesets into an external file used by the build.xml? Just need some organisation here.
You can try using the import task, which lets you split a build file into multiple files.
You can also look into property files
FileLists also support a listfile property which is a text file with one file per line.
FileSets support the includesfile and excludesfile property which is a text file with a list of patterns.

Automating Localizable.strings?

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

How to find untranslated strings. NSLocalizedString()

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/

tool to extract strings for localization of iPhone/iPad app?

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.