0

me need make settings language

I've got:

#define kMenuSettingsHeaderrus @"Настройки"
#define kMenuSettingsHeadereng @"Settings"

and I want use this global variables to set string to label depending on

_language= [[SettingsManager sharedSettingsManager] getLanguage];

_language can be @"rus" or @"eng"

CCLabelTTF *settingsLabel = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"kMenuSettingsHeader%@",_language] fontName:kLabelFontNameTTF fontSize:kMenuHeaderFontSize];

can you help me, in php i do this like $$

one example from php:

$a = "hello";
$$a = "world"; => $hello="world"
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

1

The thing you were doing would have given kMenuSettingsHeadereng or kMenuSettingsHeaderrus as result because instead of macros they will be treated as strings... So Use this

#define kMenuSettingsHeaderrus @"Настройки"
#define kMenuSettingsHeadereng @"Settings"


_language= [[SettingsManager sharedSettingsManager] getLanguage];

CCLabelTTF *settingsLabel;
 if ([_langueage isEqualToString:@"rus"])
{
settingsLabel = [CCLabelTTF labelWithString:kMenuSettingsHeaderrus fontName:kLabelFontNameTTF fontSize:kMenuHeaderFontSize];
}
else if ([_langueage isEqualToString:@"eng"])
{
settingsLabel = [CCLabelTTF labelWithString:kMenuSettingsHeadereng fontName:kLabelFontNameTTF fontSize:kMenuHeaderFontSize];
}

Check for the syntax... I don't have X-code to check for that... Hope this helps.. :)

Nikhil Aneja
  • 1,259
  • 8
  • 13
  • ok, I know this way... but i want something like stringWithFormat:@"kMenuSettingsHeader%@",_language] more shortly – Alexander Sharunov May 04 '12 at 07:44
  • Actually what you are doing is convert this into string rather than macro... You code is not settingsLabel = [CCLabelTTF labelWithString:kMenuSettingsHeaderrus fontName:kLabelFontNameTTF fontSize:kMenuHeaderFontSize]; Its settingsLabel = [CCLabelTTF labelWithString:@"kMenuSettingsHeaderrus" fontName:kLabelFontNameTTF fontSize:kMenuHeaderFontSize]; Now think yourself.. Are they equal? – Nikhil Aneja May 04 '12 at 08:57
  • I'm really understand this and it lead me to the question: How can i concatenate the name of variable from name of the first variable and value of the other variable – Alexander Sharunov May 04 '12 at 09:24
  • I added the example from PHP, to make more clear the meaning my question – Alexander Sharunov May 04 '12 at 09:32
  • 1
    the answer is: http://stackoverflow.com/questions/2283374/objective-c-equivalent-of-phps-variable-variables – Alexander Sharunov May 04 '12 at 10:13