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?
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.
For the exported XLIFF to contain your localized strings, a few conditions have to be met:
NSLocalizedString
macro. For example:This is the correct way:
NSLocalizedString("some_key", "")
This will not work:
let key = "some_key"
NSLocalizedString(key, "")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With