Chuyển đến nội dung
Skillpedia
Lập trình chung25k · #10099

nocobase-app-plugin-i18n

Skill này làm gì

Skill này hướng dẫn thêm và thay đổi văn bản đã dịch trong ứng dụng hoặc plugin NocoBase 3. Skill dành cho lập trình viên cần ứng dụng hỗ trợ nhiều hơn một ngôn ngữ.

Khi nào nên dùng

  • ✓Khi bạn thêm một nhãn, nút hoặc thông báo mới cần hiển thị bằng nhiều ngôn ngữ.
  • ✓Khi bạn cần dịch lỗi máy chủ hoặc email theo ngôn ngữ của người nhận.
  • ✓Khi bạn muốn thêm một ngôn ngữ mới cho một gói đã có tệp locale.

Liên kết skill

https://github.com/nocobase/nocobase/blob/v3-develop/packages/plugins/app-plugin-i18n/skills/nocobase-app-plugin-i18n/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/nocobase/nocobase/blob/v3-develop/packages/plugins/app-plugin-i18n/skills/nocobase-app-plugin-i18n/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Bạn có thể dịch nút Lưu mới và các thông báo lỗi trong ứng dụng NocoBase của tôi sang tiếng Bồ Đào Nha và tiếng Tây Ban Nha không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

AI đặt văn bản sau một khóa dịch trong tệp locale và namespace đúng. Sau đó nó hiển thị văn bản qua các hàm dịch trên trình duyệt hoặc trên máy chủ.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Goal

Put user-facing text behind a translation key correctly the first time: in the right file, under the right namespace, and in a way that survives a language switch.

Scope

  • Wire locale files into a package that has none yet.
  • Add a string to an application or a plugin and render it translated, in the browser or on the server.
  • Throw an error that callers see in their own language, and translate mail or jobs for their recipient.
  • Add a language to a package that already has locale files.
  • Reword a plugin's copy from the application, without editing the plugin.
  • Translate a menu or breadcrumb title.

Non-Goals

  • Do not build a language picker. useAppLocale() exists; app-template-default already renders one in client/layouts/components/language-switcher.tsx.
  • Do not add i18n machinery to an application. The plugin is registered by default, the client runtime is built by createAppI18nRuntime, and the server's by I18nProvider.
  • Do not configure the list of languages. It is whatever the application's own locales/index.ts declares; configuration names only the default, i18n.defaultLocale (overridden by APP_DEFAULT_LOCALE). The @nocobase/app-plugin-i18n README covers that, useAppLocale(), the endpoints, and useSyncServerLocale(), which the template shell already calls to keep the server's language in step with the browser's.

The one rule that decides everything

A namespace is a package name, and the namespace in scope follows the render tree.

An application's pages get the application's namespace; a plugin's pages get that plugin's, because the host wraps each contribution using the packageName it already records. So a component in its own package's routes translates with no namespace at all.

The exception is what most mistakes come from: a component a plugin exports for the application to render is in the application's scope, not its own. It has to name its namespace.

Procedure

Wiring locales into a package for the first time

A package has a client/locales/ and a server/locales/ tree, each with an en-US.ts, the other languages, and an index.ts mapping every language to a dynamic import:

// client/locales/index.ts, and server/locales/index.ts in the same shape
import type { LocaleLoaders } from '@nocobase/i18n';

const locales: LocaleLoaders = {
  'en-US': () => import('./en-US.js'),
  'zh-CN': () => import('./zh-CN.js'),
};

export default locales;

Import that module and pass it as locales, the same way on both sides:

// client/plugin.ts
import locales from './locales/index.js';

export default defineClientPlugin({
  packageName: '@acme/app-plugin-orders',
  locales,
  routes,
});
// server/plugin.ts
import locales from './locales/index.js';

export default defineServerPlugin({
  baseDir,
  packageName: '@acme/app-plugin-orders',
  locales,
});

Import it statically. Each language is already a separate dynamic import, so a language is loaded only when something needs it; deferring the map as well gains nothing. locales: () => import('./locales/index.js') is still accepted on both sides for code written that way.

Without this step every t() in the package renders its key. An application's own client/runtime.ts and server/runtime.ts pass their locales the same way.

Adding a string

  1. Find the package that owns the text. Application text goes in client/locales/; a plugin's text goes in that plugin's client/locales/.
  2. Add the key to en-US.ts. The structure is written once: the type is derived from the value with LocaleResource<typeof enUS>, and other locales are annotated with it, which is what makes a typo a compile error.
  3. Add the translation to every other locale file. A missing key falls back rather than breaking, so this can lag, and typecheck reports it.
  4. Render it with useTranslation from @nocobase/i18n/client.
import { useTranslation } from '@nocobase/i18n/client';

const { t } = useTranslation();
t('actions.save');

Keys nest and are addressed with dots: t('trigger.types.schedule').

Naming translation keys

Use short semantic keys that describe the purpose of the text and stay valid when its wording changes. Use lower camelCase within each segment and dots for useful feature or context groups, such as files.uploadFailed or demo.pageDescription. A small namespace may use title directly. Do not use complete English sentences as keys or merely convert a sent

Câu hỏi thường gặp

Nó có thêm bộ chọn ngôn ngữ không?

Không. Mẫu ứng dụng đã có sẵn một bộ chọn, và skill không thêm bộ khác.

Các ngôn ngữ được liệt kê ở đâu?

Trong tệp locales của chính ứng dụng.

Skill tập trung vào điều gì?

Đặt văn bản sau các khóa dịch trong đúng tệp, để nó vẫn đúng khi người dùng đổi ngôn ngữ.

Chi tiết

Mô tả gốc của tác giả

Use when adding or changing user-facing text in a NocoBase application or plugin: writing locale files, wiring a package's locales for the first time, translating a component or a menu title, naming a namespace, translating server responses, errors and outbound mail, or adding a language. Not for building page UI around the text (nocobase-app-development) or scaffolding a new plugin (nocobase-app-plugin-development); those Skills hand translation work here.

repo: nocobase/nocobase

Độ phổ biến

Sao GitHub
25k
Vị trí xếp hạng
#10099
Giấy phép
—
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự