user3644877
user3644877

Reputation: 23

How to localize array?

I'm trying to translate my project to another languages, however I'm stuck when localizing my arrays. For example:

tableData = [[NSArray alloc] initWithObjects:
    @"Test1",
    @"Test2",
    @"Test3",
    @"Test4",
    @"Test5",
    nil];

I've tried to

tableData = [[NSArray alloc] initWithObjects:NSLocalizedString
    (@"Test1",@"Test1"),
    (@"Test2",@"Test2"),
    ...

And

tableData = [[NSArray alloc] initWithObjects:NSLocalizedString
    ((@"Test1",@"Test1"),
    (@"Test2",@"Test2")),
    ...

But I get "Expression result unused."

All the procedure to generate an .strings file and localize everything else is good and working, I just need some help to find out how to write it down for an array.

Any tips?

Upvotes: 2

Views: 1740

Answers (1)

trojanfoe
trojanfoe

Reputation: 122381

Shouldn't that be:

tableData = [[NSArray alloc] initWithObjects:
    NSLocalizedString(@"Test1",@"Test1"),
    NSLocalizedString(@"Test2",@"Test2"),
    ...
    NSLocalizedString(@"TestN",@"TestN")
];

or (shorter):

tableData = @[
    NSLocalizedString(@"Test1",@"Test1"),
    NSLocalizedString(@"Test2",@"Test2"),
    ...
    NSLocalizedString(@"TestN",@"TestN")
];

Upvotes: 7

Related Questions