多语言应用程序by

多语言应用程序by

本文介绍了多语言应用程序by singleton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想转换我的应用程式以支援多种语言。我想要进行切换语言的设置。有一个很好的方法来使一个Singleton类获取字符串和图像?我不想从iPhone本地化,但本地化的应用程序,如果这是有意义的... Thx的回复!

解决方案

是的,你的解决方案是好的(我看到它为许多应用程序实现这种方式)。你需要一个基本的单例类,它将实现一个字典,并且在询问一个本地化字符串的名称时返回正确的字符串。



至少,您可能需要



一些构造函数来读取本地化字符串。 / p>

方法setLanguage(String language)设置当前本地化语言。



方法getLocalizedString: )来获取当前语言的本地化字符串。



这是标题的基本实现:

  @interface LocalizedString:NSObject 

+(void)setLanguage(String language);
+(void)getLocalizedStringForField(String field);

static current_language;

@end


I want to convert my app to support multiple languages. I want make to make settings for switching languages. Is there a good way to make a Singleton class for getting strings and images? I don't want localization from iPhone, but localization for application, if that makes sense... Thx for reply!

解决方案

Yes, your solution is good (and I've seen it implemented this very way for many applications). You need a basic singleton class that will implement a dictionary and will return the correct string when asked for the name of a localized string.

At a bare minimum, you'll probably need

some constructor to read in the localized strings.

a method setLanguage(String language) to set the current localized language.

a method getLocalizedString:(String field) to get the localized string for the current language.

Here's a basic implementation of the header:

@interface LocalizedString : NSObject

+ (void)setLanguage(String language);
+ (void)getLocalizedStringForField(String field);

static current_language;

@end

这篇关于多语言应用程序by singleton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 14:41