-3

I wanted to ask a short question.

Is this possible or do I have to change anything?:

[self.category addObject:NSLocalizedString(@"Accessories", nil)];

This is an object in an tableView that should use the content from a .strings file

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • 1
    Wouldn't this be _very_ simple for you to test if it's possible? ;) – David Rönnqvist Jun 01 '14 at 09:39
  • it doesn't work. That's the problem. I want to know if the error is here or in the .strings file. – user3676993 Jun 01 '14 at 09:42
  • NSLog(@"%@", NSLocalizedString(@"Accessories", nil)); - does it work? – Mike Jun 01 '14 at 09:43
  • then your strings file isn't in the target/corrupt or the string isn't there – Daij-Djan Jun 01 '14 at 10:23
  • according to your strings file (As seen below) "Accessories" = "Accessories"; – Daij-Djan Jun 01 '14 at 11:58
  • 2
    **Don't say "It doesn't work" without describing WHAT doesn't work. Give the error message, at the very least, or describe in detail what expected result does not occur.** – Hot Licks Jun 01 '14 at 12:01
  • OK, there is no error message. Build succeeds. In my tableView, there should be displayed the content of the strings file. But it doesn't show the content, it shows, what I have typed in for key. – user3676993 Jun 01 '14 at 12:24
  • Hey guys, I got it! I don't know what the error was but i have rewritten my code my .strings file and then it worked. Thank you really much for your help! – user3676993 Jun 01 '14 at 19:48

2 Answers2

0

the code works ;)

#import <Foundation/Foundation.h>

int main(int argc, char *argv[]) {
    @autoreleasepool {
        id category = [NSMutableArray array];
        [category addObject:NSLocalizedString(@"Accessories", nil)];
        NSLog(@"%@", category);
    }
}

self.category isn't nil you said and so it must be the strings file:
maybe the file isn't in the target/corrupt or the string isn't there

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
0

Of course.. probably the error is somewhere else. NSLocalizedString is just a macro that at compile time is replace by [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]. As you ca see is a simple method that returns a string for a key at runtime.
There is nothing wrong in your code. Check in your localization file for a key that matches perfectly the one you provide.

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
Andrea
  • 26,120
  • 10
  • 85
  • 131
  • I tried, but it won't work :( I#ve also tried it with different objects but it won't work – user3676993 Jun 01 '14 at 10:49
  • What do you mean by"I've tried with different objects" – Andrea Jun 01 '14 at 11:34
  • Are you sure that you have totally understood how localization process works? – Andrea Jun 01 '14 at 11:36
  • I hope so. I've done it with this tutorial: http://www.raywenderlich.com/64401/internationalization-tutorial-for-ios-2014 – user3676993 Jun 01 '14 at 11:42
  • Ok, restore the simulator to default state, make a clean build of your project (shift+cmd+K), select German in language settings of the SIM, relaunch. If still in english i would check the directories of your project to check if there is a de.lproj directory with inside the localized strings file. – Andrea Jun 01 '14 at 11:49
  • have done everything. Still doesn't work. I have a de.lproj file in my Projects folder. Inside the de.lproj folder the is my Localizable.strings file. All there. But it still doesn't work – user3676993 Jun 01 '14 at 11:57
  • @Daji-Djan What can I do now? – user3676993 Jun 01 '14 at 12:48
  • Hey guys, I got it! I don't know what the error was but i have rewritten my code my .strings file and then it worked. Thank you really much for your help! – user3676993 Jun 01 '14 at 19:49
  • Good! Glad that you find the solution – Andrea Jun 01 '14 at 20:01