> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 本地化电子邮件模板

> 创建 PlayFab 电子邮件模板，在一个模板 ID 下包含多个翻译版本，让玩家以其首选语言接收账户电子邮件。

PlayFab 正在推出代表游戏开发者存储本地化字符串的支持。此外，我们添加了必要的逻辑，以便为你的玩家提供他们偏好的语言的正确字符串。

本教程将引导你完成如何使用本地化电子邮件模板。使用本地化电子邮件模板，你可以制作电子邮件的多个翻译版本，并将*所有*版本与一个模板 ID 关联。

<Note>
  在此功能发布之前引入的任何模板将保留其行为。但是，你可以轻松更新它们以使用新电子邮件模板所使用的新本地化格式。
</Note>

## 要求

这是一个*高级*教程。请确保满足所有要求，否则你将*无法*完成本教程。

* 有关电子邮件模板的介绍，请参阅[使用电子邮件模板发送账户恢复电子邮件](/services/playfab/live-service-management/game-configuration/title-communications/emails/using-email-templates-to-send-an-account-recovery-email)教程。
* 请在[设置默认语言](/services/playfab/live-service-management/game-configuration/title-communications/news/setting-default-languages)教程中查看有关如何处理 title 上默认语言以及玩家首选语言的信息。你必须设置 title 默认语言才能继续使用本地化电子邮件模板。

## 更新现有电子邮件模板

我们要做的第一件事是更新在上面提到的[使用电子邮件模板发送账户恢复电子邮件](/services/playfab/live-service-management/game-configuration/title-communications/emails/using-email-templates-to-send-an-account-recovery-email)教程中创建的现有账户恢复电子邮件模板。

1. 从左侧菜单中选择 **Content**。
2. 转到 **Email Templates** 选项卡。
3. 移至 **Template name** 字段，然后选择 **Account Recovery** 模板。

<img src="https://mintcdn.com/microsoft-4404708b/3hg2JQs0m7qmDqay/images/playfab/live-service-management/game-configuration/title-communications/emails/tutorials/game-manager-content-edit-email-template.png?fit=max&auto=format&n=3hg2JQs0m7qmDqay&q=85&s=3ceed3a457f45f85944bb701147296a8" alt="Game Manager - Content - Email Templates - Edit Email Template" width="1366" height="1256" data-path="images/playfab/live-service-management/game-configuration/title-communications/emails/tutorials/game-manager-content-edit-email-template.png" />

在本教程中，我们将假设你的 title 默认语言是英语。你会看到你现有的模板版本显示为默认语言版本。

<img src="https://mintcdn.com/microsoft-4404708b/3hg2JQs0m7qmDqay/images/playfab/live-service-management/game-configuration/title-communications/emails/tutorials/email-template-subject-and-body-default-language.png?fit=max&auto=format&n=3hg2JQs0m7qmDqay&q=85&s=73a86502d9ea115d84cc067bc0de8eff" alt="Edit Email Template - Subject and Body - Default Language" width="989" height="1128" data-path="images/playfab/live-service-management/game-configuration/title-communications/emails/tutorials/email-template-subject-and-body-default-language.png" />

添加更多语言就像选择提供的 **+ ADD LANGUAGE** 链接一样简单，然后选择你要添加到模板的语言，并键入本地化字符串。

在此示例中，我们将向现有模板添加以下法语字符串。

法语邮件主题：

```html theme={null}
Réinitialisation du mot de passe demandée
```

法语邮件正文：

```html theme={null}
<head></head>
<body><p>Vous avez récemment demandé un mot de passe avec nous. </p>
<p>Cliquez <a href="$ConfirmationUrl$">ici</a> s'il vous plaît pour être dirigé vers une page pour réinitialiser votre mot de passe.
```

它应如下所示：

<img src="https://mintcdn.com/microsoft-4404708b/3hg2JQs0m7qmDqay/images/playfab/live-service-management/game-configuration/title-communications/emails/tutorials/email-template-subject-and-body-french-language.png?fit=max&auto=format&n=3hg2JQs0m7qmDqay&q=85&s=dfb61a203ed9ae23c1392bfb93c6247f" alt="Edit Email Template - Subject and Body - French Language" width="981" height="1759" data-path="images/playfab/live-service-management/game-configuration/title-communications/emails/tutorials/email-template-subject-and-body-french-language.png" />

当你选择 **SAVE EMAIL TEMPLATE** 按钮时，你将被重定向回包含电子邮件模板列表的页面。

如你所见，添加了一个新的语言版本，但*没有*添加新模板，因为所有语言版本都存储在同一个模板 ID 下。

## 发送本地化电子邮件

接下来，我们将发送电子邮件的新本地化版本。正如[设置默认语言](/services/playfab/live-service-management/game-configuration/title-communications/news/setting-default-languages)教程中所述，PlayFab 会做繁重的工作来匹配你 title 的支持语言与玩家的首选语言。你需要做的只是告诉我们发送电子邮件。

要验证此行为，请创建两个测试玩家。

将其中一位新玩家保留为没有首选语言。这将演示当未指定语言或 title 的语言与玩家的语言之间没有匹配时，PlayFab 如何回退到 title 的默认语言。

使用 Game Manager 或使用 [SetProfileLanguage](xref:titleid.playfabapi.com.profiles.accountmanagement.setprofilelanguage) API 设置*另一位*新玩家的语言。在此示例中，我们使用了法语。

<Note>
  使用 `SetProfileLanguage` API 时，语言字符串必须以 ISO 639-1 格式指定（例如 "en"、"es" 或 "ja"）。目前，不支持代码 "zh"。
</Note>

在继续下一步之前，请确保按照[使用电子邮件模板发送账户恢复电子邮件教程的步骤 2](/services/playfab/live-service-management/game-configuration/title-communications/emails/using-email-templates-to-send-an-account-recovery-email#step-2---add-username-password-login-email-and-contact-email-to-a-player) 中的说明为两位玩家设置联系电子邮件。

对每位玩家使用 [SendCustomAccountRecoveryEmail](xref:titleid.playfabapi.com.server.accountmanagement.sendcustomaccountrecoveryemail) API 一次以发送此模板：

* 向首选语言为法语的玩家发送一次法语版本。
* 向没有设置首选语言的玩家发送一次默认语言版本。

下面显示向*没有首选语言*的玩家发送的示例电子邮件。

<img src="https://mintcdn.com/microsoft-4404708b/3hg2JQs0m7qmDqay/images/playfab/live-service-management/game-configuration/title-communications/emails/tutorials/email-password-reset-default-language.png?fit=max&auto=format&n=3hg2JQs0m7qmDqay&q=85&s=bb1e0e6cf1614c5e1cf0255ef60fea0e" alt="Email - Password Reset - Default Language" width="1180" height="388" data-path="images/playfab/live-service-management/game-configuration/title-communications/emails/tutorials/email-password-reset-default-language.png" />

下面显示向*首选语言为法语*的玩家发送的示例电子邮件。

<img src="https://mintcdn.com/microsoft-4404708b/3hg2JQs0m7qmDqay/images/playfab/live-service-management/game-configuration/title-communications/emails/tutorials/email-password-reset-french-language.png?fit=max&auto=format&n=3hg2JQs0m7qmDqay&q=85&s=ce1d58bc1351db185ae7aaae37deba3c" alt="Email - Password Reset - French Language" width="1185" height="390" data-path="images/playfab/live-service-management/game-configuration/title-communications/emails/tutorials/email-password-reset-french-language.png" />

## 总结

如你所见，PlayFab 注意到你的模板对法语的支持与玩家的语言偏好之间存在匹配。

在*没有*匹配或*没有*首选语言的情况下，玩家会收到你 title 的默认语言字符串。

如果你对本教程有任何问题或反馈，请通过我们的[论坛](https://community.playfab.com/questions/ask.html)或 Slack 频道联系我们。


## Related topics

- [电子邮件消息快速入门](/zh-CN/services/playfab/live-service-management/game-configuration/title-communications/emails/quickstart.md)
- [PFAccountManagementSendEmailFromTemplateRequest](/zh-CN/services/playfab/api-references/c/pfaccountmanagementtypes/structs/pfaccountmanagementsendemailfromtemplaterequest.md)
- [电子邮件](/zh-CN/services/playfab/live-service-management/game-configuration/title-communications/emails/index.md)
- [PFAccountManagementClientSendAccountRecoveryEmailAsync](/zh-CN/services/playfab/api-references/c/pfaccountmanagement/functions/pfaccountmanagementclientsendaccountrecoveryemailasync.md)
- [sent_email](/zh-CN/services/playfab/api-references/events/TitleCommunications/sent-email.md)
