add-locale
Adds a new language/locale to the application. Involves Strapi admin config, Next.js i18n routing, and translation files. Use this skill whenever the user mentions adding a language, translation, i18n, multilingual support, locale, or internationalization — even if they don't explicitly say 'locale'. Also triggers on: add language, add locale, new language, new translation, support another language.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
Add a new language/locale to the application. Involves Strapi admin config, Next.js i18n routing, and translation files.
Input Validation
Before proceeding, validate inputs:
-
Locale code: must be valid ISO 639-1 (2 letters, lowercase, e.g.
de,fr,sk). Reject uppercase or invalid codes. -
Locale name: capitalized, no special characters (e.g.
German,French,Slovak).
If invalid format provided, ask user to correct before proceeding.
Inputs
Ask the user for:
-
Locale code: ISO 639-1 code (e.g.
de,fr,sk) -
Locale name: human-readable name (e.g.
German,French,Slovak)
Steps
1. Create locale translation file
Copy apps/ui/locales/en.json to apps/ui/locales/{locale}.json.
The file structure must match en.json exactly — same keys, translated values. Initially copy as-is and mark values for translation.
Check apps/ui/locales/ for existing locale files to use as reference.
2. Update routing config
Edit apps/ui/src/lib/navigation.ts.
Add the new locale code to the locales array:
export const routing = defineRouting({
locales: ["cs", "en", "{locale}"],
defaultLocale: "en",
localePrefix: "as-needed",
})
Keep the array sorted alphabetically.
3. Update i18n config (if needed)
The i18n config at apps/ui/src/lib/i18n.ts uses dynamic imports and automatically picks up new locale files:
messages: (
await (locale === "en"
? import("../../locales/en.json")
: import(`../../locales/${locale}.json`))
).default,
No changes needed unless you want HMR support for the new locale during development (currently only en has HMR via static import).
4. Manual steps (inform user)
After the automated steps complete, inform the user:
The translation file and routing config are set up. You need to manually:
- Enable locale in Strapi: Go to Settings > Internationalization > Add new locale > select {locale}
- Translate content: For each content type with i18n enabled, switch to the new locale in Strapi admin and translate
Notes
- The
[locale]route segment inapps/ui/src/app/[locale]/handles locale routing automatically vianext-intl -
generateStaticParamsin the root layout iteratesrouting.locales— new locale pages are generated automatically - The
localePrefix: "as-needed"setting means the default locale (en) has no prefix, all others get/{locale}/prefix
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-03-11
- 索引更新时间
- 2026-03-11
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!