> ## 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.

# 打包资源的本地化

> 使用 MicrosoftGame.config、区块布局与 Intelligent Delivery（按区域设置下载）本地化 GDK 包中的字符串、图片与其他资源。

`MicrosoftGame.config` 中引用的字符串与图片可以根据用户区域设置进行本地化。Visual Studio 2019+ 会自动生成一个 `resources.pri` 文件,操作系统会在运行时读取它。

在 GDK 命令行提示符中导出该文件:

```text theme={null}
MakePri.exe dump /if resources.pri /of out.xml
```

## 本地化应用名称与描述

### 添加默认字符串

1. 在解决方案资源管理器中右键单击你的项目,添加一个名为 `Strings` 的**新筛选器**。
2. 右键单击 `Strings`,添加一个**新建项 > 程序集资源文件 (.resx)**。VS 会在包根目录下创建 `resources.resx`。

<Note>
  GDK 要求使用 `.resw`。将 `resources.resx` 重命名为 `resources.resw`。
</Note>

### 在 MicrosoftGame.config 中引用字符串

```xml theme={null}
<ShellVisuals DefaultDisplayName="ms-resource:AppName"
              PublisherDisplayName="Publisher Display name"
              StoreLogo="StoreLogo.png"
              Square150x150Logo="Logo.png"
              Square44x44Logo="SmallLogo.png"
              Description="ms-resource:AppDescription"
              BackgroundColor="#000040"
              SplashScreenImage="SplashScreen.png"/>
```

### 为每种语言添加字符串

为每种受支持的语言创建一个 `Strings/<lang>` 筛选器,在每个筛选器下添加一个程序集资源文件,将**项类型**设置为 **PRI Resource**,并将其重命名为 `.resw`。

### 在 MicrosoftGame.config 中声明语言

```xml theme={null}
<Resources>
    <Resource Language="en-US"/>
    <Resource Language="fr-FR"/>
    <Resource Language="de-DE"/>
</Resources>
```

若要支持繁体中文,还应列出 `zh-SG` 和 `zh-CN` 作为回退。

## 添加可本地化的图片

`Logo`、`SmallLogo`、`SplashScreen`、`StoreLogo` 都可以本地化:

1. 在一个共享文件夹(如 `Images`)下按语言创建子文件夹。
2. 添加图片,**项类型** = **Image**,**内容** = **Yes**。
3. 在根目录下提供默认图片作为回退。

<Note>
  至少包含一个图片资源。否则本地化字符串将无法解析,游戏名称会显示为 `ms-resource:AppName`。
</Note>

## 区块布局

```xml theme={null}
<Chunk Id="1000" Marker="Launch">
    <FileGroup DestinationPath="\Images"       SourcePath="Images"       Include="*.*"/>
    <FileGroup DestinationPath="\Images\en-US" SourcePath="Images\en-US" Include="*.*"/>
    <FileGroup DestinationPath="\Images\fr-FR" SourcePath="Images\fr-FR" Include="*.*"/>
    <FileGroup DestinationPath="\" SourcePath="." Include="resources.pri"/>
</Chunk>
```

## Intelligent Delivery

使用 `Languages` 标记区块:

```xml theme={null}
<Chunk Id="1005" Languages="en-US">
    <FileGroup DestinationPath="\assets\audio" SourcePath="." Include="en_us_commentary.mp3"/>
</Chunk>
<Chunk Id="1008" Languages="es-MX, en-US">
    <FileGroup DestinationPath="\assets" SourcePath="." Include="mixed_content.dat"/>
</Chunk>
```

### 安装行为

* 主机为 `en-US` → 安装 1005 和 1008。
* 主机为 `en-GB` → 回退到 `en-US` → 安装 1005 和 1008。
* 未标记的区块始终会安装。

### 使用 xbapp 测试

* `/Languages` —— 无论主机设置如何,都为列出的语言进行安装。
* `/AllChunks` —— 安装整个包。
* `/w` —— 安装完成后保持连接。

## 另请参阅

* [MicrosoftGame.config 本地化](/build/core-features/common/game-config/MicrosoftGameConfig-Localization)
* [Intelligent Delivery](/build/core-features/common/packaging/intelligentdelivery-features-recipes)

## 相关 API 文档

* [XPackage API reference](/reference/system/xpackage/xpackage_members) —— 挂载/枚举本地化的包区块
* [MicrosoftGame.config elements reference](/reference/system/microsoftgameconfig/elements/gc-microsoftgameconfig-toc) —— 资源 + 区块声明


## Related topics

- [本地化与全球化概览](/zh-CN/build/game-principles/localization.md)
- [MicrosoftGame.config 本地化](/zh-CN/build/core-features/common/game-config/MicrosoftGameConfig-Localization.md)
- [使用 MSIXVC 工具打包 PC 游戏入门](/zh-CN/build/core-features/common/packaging/overviews/packaging-getting-started-for-PC.md)
- [打包概述](/zh-CN/build/core-features/common/packaging/overviews/packaging.md)
- [用于 PC 游戏开发的 Visual Studio 属性](/zh-CN/tools/tools-pc/visualstudio/gr-vs-property-pages.md)
