统一多种语言的枚举
我有一个大型项目,其中包含多种语言的组件,每种语言都依赖于一些相同的枚举值。您提出了哪些解决方案来统一多种任意语言的枚举?我可以想到一些,但我正在寻找最好的解决方案。
(在我的实现中,我使用 Php、Java、Javascript 和 SQL。)
I have one large project with components in multiple languages that each depend on some of the same enum values. What solutions have you come up with to unify enums across multiple arbitrary languages? I can think of a few, but I'm looking for the best solution.
(In my implementation, I'm using Php, Java, Javascript, and SQL.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将所有枚举放入一个文本文件中,然后使用代码生成器从该公共文件中为每种语言编写出适当的语法,以便每个组件都有枚举。使该文本文件成为权威的信息来源。
您可以用 XML 表示文本文件,但我认为制表符分隔的平面文件也可以正常工作。
You can put all of the enums in a text file, then use a code generator to write out the appropriate syntax for each language from that common file so that each component has the enums. Make that text file the authoritative source of information.
You can express the text file in XML but I'd think a tab-delimited flat file would work just fine.
将它们设置为每种语言都可以理解或都有库的格式。我目前正在使用 JSON 来实现此目的。
然后您可以通过两种方式包含它:
Make them in a format that every language can understand or has a library for. I am using JSON for this at the moment.
Then you can include it with two ways:
我会应用干原则并使用代码生成器,这样你就可以轻松添加新语言即使它本身不存在枚举。
I would apply the dry principle and using code generator as such you could add anew language easely even if it has not enum natively existing.