Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't retrieve localized strings from Localizable.strings file

I'm unable to get the correct localized german strings from the Localizable.strings file. My app setup looks like this

  • Main.storyboard

    • Main.storyboard (Base)
    • Main.strings (German) -> these strings are translated correctly
  • Localizable.strings

    • Localizable.strings (English)
    • Localizable.strings (German) -> can't get these strings

Inside the app I'm trying to get the string like this

NSString *item = NSLocalizedString(@"Group expenses", @"Menu item");

The Localizable.strings (German) file looks like this

/* Menu item */
"Group expenses" = "Gruppenausgaben";

When I set a breakpoint after item I always get the English string back, however the path for the resource seems correct NSString *path = [[NSBundle mainBundle] pathForResource:[[NSLocale preferredLanguages] objectAtIndex:0] ofType:@"lproj"]; gives me: /data/Containers/Bundle/Application/5E3ED6BF-71E1-4C60-9EDA-610C9A32B8EF/MyApp.app/de.lproj

I also have localized the string file

enter image description here

enter image description here

It's also included in Copy Bundle Resources

enter image description here

I tried several answers from different questions here on stackoverflow, like deleting app and do a clean (shift+cmd+k), setting application language under Edit Scheme, ...

like image 386
gpichler Avatar asked Aug 17 '15 14:08

gpichler


People also ask

How do I localize Xib files?

Right click on the xib file in Xcode, and choose Get Info . Select the General tab and on the bottom click Make File Localizable . Then you will be able to add localizations by clicking Add Localization on that same tab. I would recommend this tutorial for step-by-step information (and pretty pictures).

What is localized string key?

The key used to look up an entry in a strings file or strings dictionary file.


1 Answers

Ok, I think I know the reason for your bug. Parse had an issue with adding Localizable.strings as documented here. This was fixed in 1.8.1 version of their framework:

V1.8.1 — AUGUST 19, 2015

...

Fixed: Overwritten localizations when used via CocoaPods and integrating as static library.

...

You can also check this question.

So, just make sure you use the latest version of the framework and all should work :)

like image 117
Andriy Gordiychuk Avatar answered Oct 19 '22 17:10

Andriy Gordiychuk