在运行时本地化 iPad 应用程序

发布于 2025-01-04 03:24:07 字数 183 浏览 3 评论 0原文

我正在开发一个需要在运行时本地化的应用程序,我的意思是它将是一个立即更改语言的按钮,我搜索了有关本地化的信息,我发现的是如何根据 iPhone 本地化应用程序国际语言。

我已经本地化了我拥有的所有 nib 文件,并根据其语言重新设计了每个 nib 文件,但是当用户单击按钮时如何更改 nib 文件?

任何帮助将不胜感激。

I'm developing an app that require a localization at run time, i mean that it will be a button to change the language instantly, i've searched about localization and what i've found is how to localize the app depend on the iPhone international language.

I've localize all the nib files i have and redesign each nib file according to it's language, but how i can change the nib file when the user click on the button ?

any help will be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

美羊羊 2025-01-11 03:24:07

主要您可以使用某人创建的项目:iOS 应用程序中的高级本地化

或者还有另一种方法,您可以自己实现。您的项目中必须有所有本地化文件:

@implementation Language

static NSBundle *bundle = nil;

+(void)initialize {
 NSArray* languages = [NSLocale preferredLanguages];
 NSString *current = [languages objectAtIndex:0];
 [self setLanguage:current];

}

/*
  example calls:
  [Language setLanguage:@"it"];
  [Language setLanguage:@"de"];
*/
+(void)setLanguage:(NSString *)l {
 NSLog(@"preferredLang: %@", l);
 NSString *path = [[ NSBundle mainBundle ] pathForResource:l ofType:@"lproj" ];
 bundle = [[NSBundle bundleWithPath:path] retain];
}

+(NSString *)get:(NSString *)key alter:(NSString *)alternate {
 return [bundle localizedStringForKey:key value:alternate table:nil];
}

@end

此代码适合您的需要。但这只是基础。因此,每个文本都必须使用 get:alter: 方法加载,以便以正确的语言加载。正如您在初始化时看到的,此类将使用系统语言,但在调用 setLanguage 方法后,它将使用您设置的语言。使用 get:alter: 方法设置语言后,您应该通过为每个文本再次调用 get:alter: 方法来重新加载视图控制器中的所有文本出现并将结果设置为所需的标签或文本字段或任何其他需要 i18n 的 NSString 类型参数。所以还有更多的工作要做,但这是一个非常好的基础。我认为这不会自动发生,你必须编码。

Mainly you can use a project created by someone: Advance Localization in iOS apps

Or there is another method, to implement it by yourself.You must have all localization files in your project:

@implementation Language

static NSBundle *bundle = nil;

+(void)initialize {
 NSArray* languages = [NSLocale preferredLanguages];
 NSString *current = [languages objectAtIndex:0];
 [self setLanguage:current];

}

/*
  example calls:
  [Language setLanguage:@"it"];
  [Language setLanguage:@"de"];
*/
+(void)setLanguage:(NSString *)l {
 NSLog(@"preferredLang: %@", l);
 NSString *path = [[ NSBundle mainBundle ] pathForResource:l ofType:@"lproj" ];
 bundle = [[NSBundle bundleWithPath:path] retain];
}

+(NSString *)get:(NSString *)key alter:(NSString *)alternate {
 return [bundle localizedStringForKey:key value:alternate table:nil];
}

@end

This code is good for what you need. But this is only the base. So each text must be loaded with the get:alter: method, so it will be loaded in the correct language. As you see at initialization this class will use the system language, but after you call the setLanguage method, then it will use the language you've setup. After you set a language with the get:alter: method, you should reload all your text in your view controller, by calling the get:alter: method again for each text that appears and set the result to the desired label or textfield or to any other NSString type parameter that needs i18n. So there is more work, but this is a very good base. I don't think it can happen automatically, you have to code.

梦一生花开无言 2025-01-11 03:24:07

请参阅我对 的回答创建本地化的 iPhone 应用程序,但允许用户更改应用程序的语言

基本上,您将本地化分为表和包,而不是使用内置本地化系统。您可以从每种语言的表中查找字符串,并从每种语言的包中查找 nib 文件。

See my answer to Creating a localized iPhone app but allowing the user to change language for the application.

Basically, you split up your localizations into tables and bundles rather than using the built-in localization system. You look your strings up from per-language tables and your nib files from per-langage bundles.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文