单例的多语言应用程序?
我想将我的应用程序转换为支持多种语言。我想要 make 进行切换语言的设置。有没有一个好的方法来创建一个单例类来获取字符串和图像?我不想要 iPhone 的本地化,而是应用程序的本地化,如果这有意义的话......感谢回复!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您的解决方案很好(我已经看到它对于许多应用程序都是以这种方式实现的)。您需要一个基本的单例类,该类将实现一个字典,并在询问本地化字符串的名称时返回正确的字符串。
至少,您可能需要
一些构造函数来读取本地化字符串。
setLanguage(String language) 方法设置当前本地化语言。
getLocalizedString:(String field) 方法获取当前语言的本地化字符串。
这是标头的基本实现:
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: