# 以下插值键无效：name

**URL:** <https://meta.discourse.org/t/the-following-interpolation-key-is-invalid-name/264477>\
**Category:** Support\
**Created:** [2023年五月10日 01:29 UTC](https://meta.discourse.org/t/the-following-interpolation-key-is-invalid-name/264477 "2023-05-10T01:29:05Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jordan-violet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jordan-violet/32/281428_2.png) [@jordan-violet](https://meta.discourse.org/u/jordan-violet)\
**Post date:** [2023年五月10日 01:29 UTC](https://meta.discourse.org/t/the-following-interpolation-key-is-invalid-name/264477/1 "2023-05-10T01:29:05Z")

</div>

我正在尝试更新 `system_messages.welcome_tl1_user.text_body_template` 并在消息中处理用户的姓名，但收到错误：“以下插值键无效：name”：

 ![image](https://global.discourse-cdn.com/meta/original/4X/7/a/c/7acdd19ca4f1759e18a5e78fe5c3dd0652b8dde0.png)

是否有我遗漏的库或文档，其中可以看到哪些变量可以在哪些消息中使用？

---

<div class="post-metadata">

**Author:** ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)\
**Post date:** [2023年五月10日 04:11 UTC](https://meta.discourse.org/t/the-following-interpolation-key-is-invalid-name/264477/3 "2023-05-10T04:11:28Z")

</div>

我认为这可能是你的答案：

> [@Available interpolation key(s)](https://meta.discourse.org/t/available-interpolation-key-s/126130/2?u=lillinator):
>
> The only ones available are the ones in the original translation phrase. That’s it.

---

<div class="post-metadata">

**Author:** ![jordan-violet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jordan-violet/32/281428_2.png) [@jordan-violet](https://meta.discourse.org/u/jordan-violet)\
**Post date:** [2023年五月10日 11:13 UTC](https://meta.discourse.org/t/the-following-interpolation-key-is-invalid-name/264477/4 "2023-05-10T11:13:16Z")

</div>

谢谢莉莉，这真令人沮丧。在其中一些地方提及用户的名字会很好。

---

<div class="post-metadata">

**Author:** ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)\
**Post date:** [2023年五月10日 14:58 UTC](https://meta.discourse.org/t/the-following-interpolation-key-is-invalid-name/264477/5 "2023-05-10T14:58:46Z")

</div>

这不是我的领域，但查看 [`ALLOWED_CUSTOM_INTERPOLATION_KEYS`](https://github.com/discourse/discourse/blob/main/app/models/translation_override.rb) 后，似乎您可以在某些消息中使用其他值。

特别是：

```plaintext
    %w[system_messages.welcome_user] => %w[username name name_or_username],

```

我认为如果我们将其更改为：

```plaintext
    %w[system_messages.welcome_] => %w[username name name_or_username],

```

这将允许您将这些用于其他欢迎消息。我将询问一下。

---

<div class="post-metadata">

**Author:** ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)\
**Post date:** [2023年五月10日 17:33 UTC](https://meta.discourse.org/t/the-following-interpolation-key-is-invalid-name/264477/6 "2023-05-10T17:33:06Z")

</div>

理论上，只要所有 `system_messages.*` 键都包含 `subject_template` 和 `text_body_template` 子键，我们就可以添加它们。因为所有这些都应该由 `SystemMessage` 类处理，该类会添加 `username, name, name_or_username` 作为额外的插值键。

> <https://github.com/discourse/discourse/blob/6fa9a8990d07f942ee52b3d721135b84d79d8a7c/lib/system_message.rb#L27-L36>

---

<div class="post-metadata">

**Author:** ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)\
**Post date:** [2023年五月11日 01:09 UTC](https://meta.discourse.org/t/the-following-interpolation-key-is-invalid-name/264477/7 "2023-05-11T01:09:01Z")

</div>

好了 🙂

> [@Interpolation Keys for Customizing Text and System Email Templates](https://meta.discourse.org/t/interpolation-keys-for-customizing-text-and-email-templates/264604?u=lillinator):
>
> bookmark This guide provides a detailed overview of interpolation keys used for customizing text and system email templates in Discourse. person_raising_hand Required user level: Administrator While [Customizing text in Discourse](https://meta.discourse.org/t/customize-any-text-in-discourse/36092) or [Customizing specific email templates](https://meta.discourse.org/t/customize-specific-email-templates/88323) you may have noticed that there are placeholder variables available in some templates. In Discourse we call these Interpolation Keys. Understanding interpolation keys Interpolation keys are placeholders available in cert…

---

<div class="post-metadata">

**Author:** ![jordan-violet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jordan-violet/32/281428_2.png) [@jordan-violet](https://meta.discourse.org/u/jordan-violet)\
**Post date:** [2023年五月11日 01:29 UTC](https://meta.discourse.org/t/the-following-interpolation-key-is-invalid-name/264477/8 "2023-05-11T01:29:36Z")

</div>

这确实是正确的方法！非常感谢你的努力，莉莉——真心感激！

---

<div class="post-metadata">

**Author:** ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)\
**Post date:** [2023年五月11日 01:33 UTC](https://meta.discourse.org/t/the-following-interpolation-key-is-invalid-name/264477/9 "2023-05-11T01:33:04Z")

</div>

嗯，我除了复制粘贴什么都没做。@gerhard、@supermathie 和 @SaraDev 这几位好同事才应该得到赞扬 👏 😅

---

<div class="post-metadata">

**Author:** ![jordan-violet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jordan-violet/32/281428_2.png) [@jordan-violet](https://meta.discourse.org/u/jordan-violet)\
**Post date:** [2023年五月11日 01:33 UTC](https://meta.discourse.org/t/the-following-interpolation-key-is-invalid-name/264477/10 "2023-05-11T01:33:41Z")

</div>

他们说，这需要一个村庄！

---

<div class="post-metadata">

**Author:** ![mjr4684](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@mjr4684](https://meta.discourse.org/u/mjr4684)\
**Post date:** [2023年五月12日 21:07 UTC](https://meta.discourse.org/t/the-following-interpolation-key-is-invalid-name/264477/11 "2023-05-12T21:07:38Z")

</div>

此行为是否可以扩展到聊天，以便通知电子邮件可以在主题中包含用户的姓名而不是用户名？

---

<div class="post-metadata">

**Author:** ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)\
**Post date:** [2023年五月13日 00:06 UTC](https://meta.discourse.org/t/the-following-interpolation-key-is-invalid-name/264477/12 "2023-05-13T00:06:11Z")

</div>

您需要编辑聊天电子邮件文本，并将密钥从用户名更改为他们的全名。但我不知道这是否可能。聊天配置不是我的强项。我会转到 `settings-customize-email`，然后在顶部的下拉菜单中搜索聊天电子邮件模板。所有可编辑的电子邮件模板都在该下拉菜单中。

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)\
**Post date:** [2023年六月12日 00:06 UTC](https://meta.discourse.org/t/the-following-interpolation-key-is-invalid-name/264477/13 "2023-06-12T00:06:55Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
