nullic / DPLocalizationManager

Provides way to change localization inside application
MIT License
81 stars 21 forks source link

DPLocalizedString does not update arguments #8

Closed n1mda closed 9 years ago

n1mda commented 9 years ago

I have a key like "settings.table.version" = "Version %1$@ (Build %2$@)";

That I set like this:

NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString *build = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
myLabel.text = [NSString stringWithFormat:DPLocalizedString(@"settings.table.version", nil), version, build];

It displays fine but when I run dp_set_current_language(@"de"); it updates the language of the Label but does not set the arguments. Like so: Version %1$@ (Build %2$@)

nullic commented 9 years ago

You, probably, missed -[updateAutolocalizationArguments:] call. Your code should look like this:

NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString *build = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
[myLabel.autolocalizationKey updateAutolocalizationArguments:@[version, build]];
myLabel.autolocalizationKey = @"settings.table.version";
n1mda commented 9 years ago

This does not work either, it never uses the arguments. Setting autolocalizationKey calls [self setupAutolocalizationWithKey:autolocalizationKey keyPath:@"text"]; Which in turn calls [self setupAutolocalizationWithKey:key keyPath:keyPath arguments:nil];

That overwrites the arguments to nil..

nullic commented 9 years ago

Sorry, you right. I typically use autolocalizationKey only in Interface Builder. Code should look like this (just different order):

NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString *build = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
myLabel.autolocalizationKey = @"settings.table.version";
[myLabel.autolocalizationKey updateAutolocalizationArguments:@[version, build]];

or

NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString *build = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
[myLabel setupAutolocalizationWithKey:@"settings.table.version" keyPath:@"text" arguments:@[version, build]];