快速入門:本地化與格式輔助工具

GitHub Copilot 可透過直接在 SQL 和 ORM 型工作流程中解決當地語系化和格式需求,協助開發人員建置全域感知的應用程式。 無論您是在處理多語言內容、區域特定的日期和數字格式,還是搜尋和排序的排序設定,GitHub Copilot 都提供智慧型、符合情境的協助,使您的資料庫和程式碼能夠面向國際用戶。

開始

確保你連上資料庫,並且開啟一個啟用 MSSQL 擴充功能的編輯器視窗。 當你連線時, @mssql 聊天參與者能理解你資料庫環境的情境,並能提供準確且具情境感知的建議。 如果你沒有連接到資料庫,聊天參與者就沒有足夠的架構或資料脈絡來提供有意義的回應。

下列範例使用 AdventureWorksLT2022 範例資料庫,您可以從 Microsoft SQL Server 範例和社群專案 首頁下載。

為了獲得最佳結果,請調整數據表和架構名稱以符合您自己的環境。

請確保聊天中包含@mssql前綴。 例如,輸入 @mssql ,後面接著您的問題或提示。 這個前綴確保聊天參與者明白你是在尋求 SQL 相關協助。

使用 GitHub Copilot 處理當地語系化和格式設定

GitHub Copilot 可協助 SQL 和 ORM 型工作流程中的當地語系化和格式化工作。 它可協助您設計支援多語系內容的架構、格式化地區標準的查詢,以及產生符合當地語系最佳做法的程式代碼。

以下是您可以透過聊天參與者詢問的常見使用案例和範例:

優化多語言和地區特有的數據

使用 GitHub Copilot 協助格式化地區標準的查詢、選擇正確的定序設定,以及設計架構元素以支援多語系內容,例如以多種語言儲存產品描述。

以多種語言儲存產品描述

Design a localized table to store product descriptions for the `SalesLT.Product` table. Ensure the table supports multiple languages, includes a relationship to `SalesLT.Product`, and allows for efficient querying.

以其他格式顯示日期

Format a query to display dates in Japanese format:

SELECT FORMAT(GETDATE(), 'yyyy/MM/dd') AS CurrentDate;

建議多語言用戶輸入的排序設定

Recommend best practices for choosing collation settings when supporting multilingual user input and search functionality in SQL Server.

建立支援多種語言的模型與查詢

Write Prisma models and queries to store and retrieve multilingual product descriptions for the `SalesLT.Product` table in my database. Ensure the schema supports multiple languages, maintains a foreign key relationship with `SalesLT.Product`, and allows for efficient querying of localized descriptions.

程式代碼優先當地語系化案例

這些範例示範 GitHub Copilot 如何藉由產生 ORM 模型和查詢來儲存和擷取當地語系化數據,以支援程式代碼優先工作流程。 這些範例橫跨熱門 ORM,例如 Prisma、SQLAlchemy、Entity Framework、Sequelize 和 Django。

定義多語言實體框架核心模型

Using Entity Framework Core, define a model for `ProductDescriptionLocalized` that maps to multiple languages and relates to `SalesLT.Product`. Include logic to filter by language code.

產生產品描述的在地化結構

In Prisma, generate a schema that supports localized descriptions for `SalesLT.Product`, and write a query to retrieve the description for a given product in Spanish (`es`).

建立一個資料表來儲存產品描述,並設有預設回退選項

With Sequelize, create a localized table for storing product descriptions with `ProductID`, `LanguageCode`, and `Description`. Write a query to return the Japanese description if available, otherwise fall back to the default language.

根據地點檢索在地產品名稱與描述

Using SQLAlchemy, write a function that retrieves the localized name and description for a given `ProductID` based on a user-specified locale, with fallback logic to default language.

設計模型以支援產品本地化,具備 NULL 備援機制

In Django ORM, design models that support product localization and write a query to retrieve all products with their name and description in French (`fr`), including any missing translations as `NULL`.

分享您的體驗

若要協助我們精簡及改善 MSSQL 延伸模組的 GitHub Copilot,請使用下列 GitHub 問題範本來提交您的意見反應: GitHub Copilot 意見反應

提交意見反應時,請考慮包括:

  • 測試情境:請告訴我們你專注於哪些領域,例如架構建立、查詢產生、安全性、在地化。

  • 有效的方法:描述任何感覺順利、有幫助或超出預期的經驗。

  • 問題或錯誤:包含任何問題、不一致或令人困惑的行為。 螢幕快照或螢幕錄製特別有用。

  • 改進建議:分享提升可用性、擴大覆蓋範圍或強化 GitHub Copilot 回應的點子。