简体   繁体   English

语言文件的最佳做法/设计模式

[英]best practice/design pattern for language files

I'm looking for a good way to have multiple translations in an application. 我正在寻找在应用程序中进行多种翻译的好方法。

Right now I'm using a class that reads the terms from an ini file. 现在,我正在使用从ini文件读取术语的类。 Every term is a variable. 每个术语都是一个变量。 For example: 例如:

string allowed ;
[...]
allowed = config.readString (sectionName,  "allowed") ;

the good of this solution is that it's light, easy to implement and checked at compile time but it's not flexible enough. 该解决方案的优点是它轻巧,易于实现并在编译时检查,但不够灵活。

a more flexible solution could be to use an associative array (or similar) 更为灵活的解决方案可以是使用关联数组(或类似数组)

currLang [ "allowed" ]

Does any-one know any best practice or design pattern or would just disclose his personal way of implementing it? 是否有人知道任何最佳实践或设计模式,或者只是透露自己的实现方式?

It's also welcome a simple description of the way the well known frameworks implement it. 也欢迎对众所周知的框架实现它的方式进行简单描述。

Well, I don't know a specific pattern for your problem. 好吧,我不知道您的问题的具体模式。 However, I implemented a few times translation support in different languages. 但是,我多次实现了不同语言的翻译支持。 The most common one, and language independent, I've seen is with an array. 我见过的最常见的语言独立语言是数组。 You load up the array at the startup and use it in your application. 您可以在启动时加载阵列,并在您的应用程序中使用它。 Based on the current language setting, you load up in that specific language. 根据当前的语言设置,您将以该特定语言加载。

If you want a more dynamic approach, or if it takes too long to read the whole array at startup (or login), check out the Proxy pattern. 如果您想要一种更动态的方法,或者在启动(或登录)时读取整个阵列花费的时间太长,请查看Proxy模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于定义数据库中具有潜在多语言需求的“类型”的最佳实践设计模式? - Best practice design pattern for defining “types” in a database with potential multi language requirement? Web服务客户端设计模式(最佳实践) - Web service client design pattern (best practice) 多动作 API 最佳实践/设计模式 - Multi actions API best Practice / Design Pattern vcard / mecard解析器的最佳实践/设计模式? - Best practice / design pattern for a vcard/mecard parser? 比较Javascript模式/范例/最佳设计实践 - Comparison of Javascript Pattern/Paradigms / Best practice of design 复制和扩充物件的最佳作法(设计模式) - Best Practice (Design Pattern) for copying and augmenting Objects Windows Form App-MVP设计模式最佳实践 - Windows Form App - MVP Design Pattern best practice 构造函数重载 java 以外的最佳实践/设计模式 - best practice/design pattern other than constructor overloading java 最佳实践:2D HUD 屏幕导航的设计模式 - Best practice: Design pattern for 2D HUD screen navigation 尝试使用最佳做法/设计模式无法访问同一物业 - Lost access to same property trying to use best practice / design pattern
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM