I\'m trying to find a manageable way to translate every visible string in an iPhone application. The official apple documentation says to use .strings files for programmatic st
The best you can do is recursively loop through each view and then set the text on them:
static void translateView(NSBundle *bundle, UIView *view)
{
id idView = view;
if ([idView respondsToSelector:@selector(text)] && [view respondsToSelector:@selector(setText:)])
[idView setText:[bundle localizedStringForKey:[idView text] value:nil table:nil]];
if ([idView respondsToSelector:@selector(title)] && [view respondsToSelector:@selector(setTitle:)])
[idView setTitle:[bundle localizedStringForKey:[idView title] value:nil table:nil]];
if ([idView respondsToSelector:@selector(placeholder)] && [view respondsToSelector:@selector(setPlaceholder:)])
[idView setPlaceholder:[bundle localizedStringForKey:[idView placeholder] value:nil table:nil]];
if ([idView respondsToSelector:@selector(prompt)] && [view respondsToSelector:@selector(setPrompt:)])
[idView setPrompt:[bundle localizedStringForKey:[idView prompt] value:nil table:nil]];
if ([idView respondsToSelector:@selector(titleForState:)] && [view respondsToSelector:@selector(setTitle:forState:)])
[idView setTitle:[bundle localizedStringForKey:[idView titleForState:UIControlStateNormal] value:nil table:nil] forState:UIControlStateNormal];
if ([idView isKindOfClass:[UITabBar class]] || [idView isKindOfClass:[UIToolbar class]])
for (UIBarItem *item in [idView items])
[item setTitle:[bundle localizedStringForKey:[item title] value:nil table:nil]];
for (UIView *subview in [view subviews])
translateView(bundle, subview);
}
Warning: You may of have to check other sets of selectors to catch everything. This is not a best-practice, but it seems like much less work