我正在深入研究Apple开发人员的文档,以了解应该如何实现应用程序的本地化/国际化,我还想了解Interface Builder如何帮助您管理多语言的多个NIB文件……这些文档向我指出了界面生成器用户指南中的“本地化”部分,但我找不到它。我应该在Xcode 4文档中找到它吗?有人能告诉我如何在Interface /XCode中实现本地化的文档吗?“界面生成器用户指南”在哪里?
提前谢谢。
PS:我是否应该从一开始就开始使用本地化字符串/包来实现我的应用程序,即使我只从一种语言开始?如果没有考虑到多语言的支持,那么“国际化”应用程序会不会很痛苦呢?
发布于 2011-10-14 11:14:20
我想你是想找这个:
http://developer.apple.com/internationalization/
(更详细的内容:http://developer.apple.com/library/ios/#documentation/MacOSX/Conceptual/BPInternational/BPInternational.html )
您应该始终铭记在启动应用程序时考虑到这一点。因为稍后,如果您的客户需要添加一种新的语言,您将有大量的工作。即使这是你的应用,你也应该使用它。除了学习如何做到这一点外,您还可以保持代码的灵活性,以应对需求中的突然变化。
发布于 2013-03-19 09:26:50
我同意先前关于这些解决办法的复杂性的意见。正因为如此,我刚刚创建了一个新工具,可以自动本地化您的IB文件。看看这里:https://github.com/angelolloqui/AGi18n
发布于 2014-09-30 20:07:15
我写了一个简单的类别,处理本地化与IB。
头文件如下所示。
@interface UIView (Localization)
@property (nonatomic, strong) NSString *mainTextKey;
@property (nonatomic, strong) NSString *secondaryTextKey;
- (void)updateMainText;
- (void)updateSecondaryText;
@end实现
@implementation UIView (Localization)
- (NSString *)mainTextKey{
return objc_getAssociatedObject(self, @selector(mainTextKey));
}
- (void)setMainTextKey:(NSString *)mainTextKey{
objc_setAssociatedObject(self, @selector(mainTextKey), mainTextKey, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self updateMainText];
}
- (NSString *)secondaryTextKey{
return objc_getAssociatedObject(self, @selector(secondaryTextKey));
}
- (void)setSecondaryTextKey:(NSString *)secondaryTextKey{
objc_setAssociatedObject(self, @selector(secondaryTextKey), secondaryTextKey, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self updateSecondaryText];
}
- (void)updateMainText{
//handle all cases one by one
if([self isKindOfClass:[UILabel class]]){
UILabel *label = (UILabel *)self;
label.text= NSLocalizedString(self.mainTextKey, nil) ;
}else if ([self isKindOfClass:[UIButton class]]){
UIButton *btn = (UIButton *)self;
[btn setTitle:NSLocalizedString(self.mainTextKey, nil) forState:UIControlStateNormal];
}
}
- (void)updateSecondaryText{
//handle all cases one by one
}
@end基本用法:
这是写在没有任何证据阅读,任何愚蠢的错误的借口。
https://stackoverflow.com/questions/7766547
复制相似问题