應用程式資源和資源管理系統App resources and the Resource Management System

本節顯示如何製作、封裝及使用您應用程式的字串、影像和檔案資源。This section shows you how to author, package, and consume your app's string, image, and file resources. 例如,您可能會封裝檔案以及包含遊戲層級定義的休閒遊戲,並且載入執行階段的檔案。For example, you might package a file along with your casual game containing a definition of the game's levels, and load the file at run-time. 我們也會向您顯示單獨維護您的應用程式邏輯的資源,如何可讓您輕鬆針對不同地區設定、裝置顯示、協助工具設定以及其他使用者和電腦內容,當地語系化及自訂您的應用程式。We also show you how maintaining your resources independently of the app's logic makes it easy to localize and customize your app for different locales, device displays, accessibility settings, and other user and machine contexts. 諸如字串和影像的資源通常需要存在於多個語言、縮放比例和對比變體中。Resources such as strings and images typically need to exist in multiple language, scale, and contrast variants. 對於這類資源,您有資源管理系統的支援。For resources such as that, you have the support of the Resource Management System.

應用程式資源有兩種類型。There are two types of app resource.

  • 檔案資源是在磁碟上儲存為檔案的資源。A file resource is a resource stored as a file on disk. 檔案資源可以包含點陣圖影像、XAML、XML、HTML 或任何其他類型的資料。A file resource can contain a bitmap image, XAML, XML, HTML, or any other kind of data.
  • 內嵌的資源是內嵌在一些包含資源檔案的資源。An embedded resource is a resource that is embedded within some containing resource file. 最常見的範例是內嵌於資源檔案中的字串資源 (.resw 或 .resjson)。The most common example is a string resource embedded within a Resources File (.resw or .resjson).

如需有關將您的應用程式當地語系化的價值主張的詳細資訊,請參閱全球化和當地語系化For more info about the value proposition of localizing your app, see Globalization and localization.

發行項Article 描述Description
資源管理系統Resource Management System 建置期間,資源管理系統會建立所有不同變體 (使用您的應用程式封裝) 的資源的索引。At build time, the Resource Management System creates an index of all the different variants of the resources that are packaged up with your app. 在執行階段,系統會偵測生效的使用者和電腦設定,並載入這些設定的最佳相符項的資源。At run-time, the system detects the user and machine settings that are in effect and loads the resources that are the best match for those settings.
資源管理系統如何比對和選擇資源How the Resource Management System matches and chooses resources 當要求資源時,也許有幾個某程度符合目前資源內容的候選項目。When a resource is requested, there may be several candidates that match the current resource context to some degree. 資源管理系統將會分析所有的候選項目,並判斷要傳回的最佳候選項目。The Resource Management System will analyze all of the candidates and determine the best candidate to return. 本主題將詳細說明該程序,並且提供範例。This topic describes that process in detail and gives examples.
資源管理系統如何比對語言標記How the Resource Management System matches language tags 上一個主題 (資源管理系統如何比對和選擇資源) 主要綜觀限定詞比對。The previous topic (How the Resource Management System matches and chooses resources) looks at qualifier-matching in general. 本主題著重於語言標記比對的細節。This topic focuses on language-tag-matching in more detail.
針對語言、縮放比例、高對比及其他限定詞量身打造您的資源Tailor your resources for language, scale, high contrast, and other qualifiers 本主題說明資源限定詞的一般概念、其使用方式,以及每個限定詞名稱的用途。This topic explains the general concept of resource qualifiers, how to use them, and the purpose of each of the qualifier names.
當地語系化您的 UI 及應用程式套件資訊清單中的字串Localize strings in your UI and app package manifest 如果希望應用程式支援不同的顯示語言,而且您的程式碼、XAML 標記或應用程式套件資訊清單也含有字串常值時,請將這些字串移入資源檔案 (.resw)。If you want your app to support different display languages, and you have string literals in your code or XAML markup or app package manifest, then move those strings into a Resources File (.resw). 您可以接著針對應用程式支援的每一種語言建立該資源檔案的翻譯複本。You can then make a translated copy of that Resources File for each language that your app supports.
載入針對縮放比例、佈景主題、高對比及其他設定量身打造的影像和資產Load images and assets tailored for scale, theme, high contrast, and others 您的應用程式可以載入包含針對顯示縮放比例、佈景主題、高對比及其他執行階段內容量身打造之影像的影像資源檔案。Your app can load image resource files containing images tailored for display scale factor, theme, high contrast, and other runtime contexts.
URI 配置URI schemes 有幾個可供您用來參考您的應用程式套件、您的應用程式資料的資料夾或雲端之檔案的 URI (統一資源識別項) 配置。There are several URI (Uniform Resource Identifier) schemes that you can use to refer to files that come from your app's package, your app's data folders, or the cloud. 您也可以使用 URI 配置參考從您應用程式的檔案資源 (.resw) 載入的字串。You can also use a URI scheme to refer to strings loaded from your app's Resources Files (.resw).
指定您的應用程式使用的預設資源Specify the default resources that your app uses 如果您的應用程式沒有符合客戶裝置特定設定的資源,則會使用應用程式的預設資源。If your app doesn't have resources that match the particular settings of a customer device, then the app's default resources are used. 本主題說明如何指定這些預設資源的內容。This topic explains how to specify what those default resources are.
將資源建置到您的應用程式套件,而不是資源套件Build resources into your app package, instead of into a resource pack 某些類型的應用程式 (多語系字典、翻譯工具等) 需要覆寫應用程式套件組合的預設行為,並將資源建置到應用程式套件中,而不是讓這些資源分散在不同的資源套件中。Some kinds of apps (multilingual dictionaries, translation tools, etc.) need to override the default behavior of an app bundle, and build resources into the app package instead of having them in separate resource packages. 本主題說明如何執行這個動作。This topic explains how to do that.
套件資源索引 (PRI) API 和自訂建置系統Package resource indexing (PRI) APIs and custom build systems 您可以使用套件資源索引 (PRI) API,開發適用於您的 UWP 應用程式資源的自訂建置系統。With the package resource indexing (PRI) APIs, you can develop a custom build system for your UWP app's resources. 建置系統可以依據 UWP 應用程式所需的任何複雜層級,建立套件資源索引 (PRI) 檔案並對這些檔案進行版本控制和傾印 (為 XML)。The build system will be able to create, version, and dump (as XML) package resource index (PRI) files to whatever level of complexity your UWP app needs.
使用 MakePri.exe 來手動編譯資源Compile resources manually with MakePri.exe MakePri.exe 是一個命令列工具,您可以用來建立和傾印 PRI 檔案。MakePri.exe is a command line tool that you can use to create and dump PRI files. 其做為 MSBuild 的一部分整合到 Microsoft Visual Studio 中,但用於手動建立套件或自訂組建系統也很有用。It is integrated as part of MSBuild within Microsoft Visual Studio, but it could be useful to you for creating packages manually or with a custom build system.
在舊版應用程式或遊戲中使用 Windows 10 資源管理系統Use the Windows 10 Resource Management System in a legacy app or game 將您的 .NET 或 Win32 應用程式或遊戲封裝成 .msix 或 .appx 套件,即可利用「資源管理系統」載入為執行階段內容量身打造的應用程式資源。By packaging your .NET or Win32 app or game as an .msix or .appx package, you can leverage the Resource Management System to load app resources tailored to the run-time context. 這個深入主題說明技術。This in-depth topic describes the techniques.

另請參閱對語言、縮放比例及高對比的磚與快顯通知支援Also see Tile and toast notification support for language, scale, and high contrast.