领域特定语言 (DSL) 可以本地化(即翻译)吗?

发布于 2024-08-25 13:19:49 字数 395 浏览 4 评论 0原文

我从未编写过 DSL,但我正在将其视为新项目的一项功能(假设)。最终用户将能够用自然语言表达概念,例如工作日 10 点到 11 点(每月第一个星期一除外)

荷兰用户可能会写成 weekdagen tussen 10 en 11 behalve op de eerste maandag van de maand。在这种情况下,单词的位置似乎匹配,但在某些表达方式中,动词/名词等的位置可能在不同语言之间有所不同。

我意识到答案很明显(这取决于)。我是一名 .NET 开发人员,我考虑使用 Boo,但我愿意接受建议。我需要了解每个翻译是否需要重写实现的一部分(哪一部分),或者是否有办法进行实际翻译,也许在某种预处理器中。

I have never written a DSL, but I am considering it as a feature for a new project (hypothetical). It would be for end users to be able to express in natural language concepts such as weekdays between 10 and 11 except on the first monday of the month.

Dutch users might write weekdagen tussen 10 en 11 behalve op de eerste maandag van de maand. In this case the position of the words seems to match, but there may be expressions where the position of verbs/nouns etc. could be different between languages.

I realise the obvious answer (it depends). I am a .NET developer and I consider using Boo but I'm open to suggestions. I need to understand wether each translation requires rewriting a part of the implementation (which part) or if there is a way to do actual translations, maybe in some sort of preprocessor.

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

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

发布评论

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

评论(2

隔岸观火 2024-09-01 13:19:49

您不会找到能够对多种语言(例如一种或两种语言和英语)执行此操作的翻译器,特别是考虑到英语本身至少有 3 种书写方式。

如果你想编写DSL,你需要首先提出产生式规则(你可以写什么),然后将其转化为英语/荷兰语/火星语等表达方式。

例如:
时间表 := 框架包含 [例外]

如下:

  • 框架:月、年、周、工作日、周末、每月的天数、假期等
  • 包含:介于、不在、周围、包含等
  • 例外:除了 [时间表] ,但不是 [Schedule],除非 [Schedule] 然后

您可以担心词法分析器/解析器会纠正特定语法并将其放入该产生式形式中。

这些离我的头顶还很远,但应该足以开始。

Your not going to find a translator that is capable of doing this for more than a few languages (say between one or two languages and English), especially considering English which itself could have at least 3 ways to write it.

If you want to write a DSL, you need to come up with the production rules first (what can you write) and then work it into a way to express it in english/dutch/martian/etc.

For instance:
Schedule := Frame Inclusion [Exception]

which would be:

  • Frame: Month, Year, Week, WeekDays, WeekEnds, Days of the Month, Holidays, etc
  • Inclusion: Between, Not In, Around, Containing, etc
  • Exception: Except [Schedule], But Not [Schedule], Unless [Schedule]

You can then worry about a lexer/parser which corrects a specific grammar and puts it into that form of productions.

These are off the top of my head and not even close, but should be enough to get started.

同展鸳鸯锦 2024-09-01 13:19:49

使用域特定语言工具创建的 DSL 可以进行本地化。他们将所有字符串放入 .resx 文件中。

A DSL created with the Domain-Specific Language Tools can be localized. They place all strings into .resx files.

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