快速入门:本地化和格式设置帮助程序

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。

为多种语言定义 Entity Framework Core 模型

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.

设计支持产品本地化的带有空值回退机制的模型

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 响应的想法。