Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export app for localization not including strings created with NSLocalizedString in Xcode 6 Xliff

I'm trying to localize my app, and I have the following code:

self.arrayLabels = [NSArray arrayWithObjects:NSLocalizedString(@"This is a test", "this is a test"),  NSLocalizedString(@"I want my strings to get added to localizable strings file", "strings comment") , nil];

So, basically, from what I understand, this should be it, I click Editor > Export for Localization and the strings should be there on my XLiff file. But, they aren't.

I have two languages, english and portuguese, both localizable.strings files are empty.

Am I missing something?

like image 984
Jorge Avatar asked Aug 15 '14 19:08

Jorge


2 Answers

I discovered that I had a few errors and that is why I could not export from the menu.

I suspect that the error messages are not being returned.

It turns out that the menu is calling existing command line tools so by a process of elimination you may be able to fix your export.

Here are the steps I took to fix my issues. Hopefully they will help you.

Run the command line equivalent

xcodebuild -exportLocalizations

If you have errors xcodebuild may give file names and line numbers so you should be able to fix the issues.

I had one error that did not have any details.

I then switched to using genstrings as that is what xcodebuild appears to be using in a loop.

find . -name '*.m' | xargs genstrings -o somePath/en.lproj

this gave the same error

To get the file with the problem I ran each file separately in a loop.

for f in `find . -name '*.m'`; do 
    echo "processing $f ...";
    genstrings -o somePath/en.lproj $f
done

That gave me the name of the file that had an issue.

It turned out that genstrings did not like a special character I was trying to print using a unicode character \U000000B2.

like image 124
mick80234 Avatar answered Oct 10 '22 03:10

mick80234


For the exported XLIFF to contain your localized strings, a few conditions have to be met:

  1. The keys must be present in your localized strings file. In your case these files are empty. Which will explain the problem.
  2. You must use the keys as string literal with the NSLocalizedString macro. For example:

This is the correct way:

NSLocalizedString("some_key", "")

This will not work:

let key = "some_key"

NSLocalizedString(key, "")
like image 29
RajV Avatar answered Oct 10 '22 04:10

RajV