refactor(i18n): extract locale config to shared module
Move locale definitions from astro.config.mjs into a shared website/src/lib/locales.mjs consumed by astro config, build-docs, and 404.astro. Adding a new locale is now a single-file change.
This commit is contained in:
parent
81b3c85521
commit
953652da3e
|
|
@ -14,6 +14,7 @@ import fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import { getSiteUrl } from '../website/src/lib/site-url.mjs';
|
import { getSiteUrl } from '../website/src/lib/site-url.mjs';
|
||||||
|
import { translatedLocales } from '../website/src/lib/locales.mjs';
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
// Configuration
|
// Configuration
|
||||||
|
|
@ -41,10 +42,6 @@ const LLM_EXCLUDE_PATTERNS = [
|
||||||
// Note: Files/dirs starting with _ (like _STYLE_GUIDE.md, _archive/) are excluded in shouldExcludeFromLlm()
|
// Note: Files/dirs starting with _ (like _STYLE_GUIDE.md, _archive/) are excluded in shouldExcludeFromLlm()
|
||||||
];
|
];
|
||||||
|
|
||||||
// Non-root locales — their docs duplicate English content and should not appear in llms-full.txt.
|
|
||||||
// Update this list when adding new i18n locales in website/astro.config.mjs.
|
|
||||||
const LLM_EXCLUDE_LOCALES = ['zh-cn', 'fr'];
|
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
// Main Entry Point
|
// Main Entry Point
|
||||||
/**
|
/**
|
||||||
|
|
@ -293,7 +290,7 @@ function shouldExcludeFromLlm(filePath) {
|
||||||
if (pathParts.some((part) => part.startsWith('_'))) return true;
|
if (pathParts.some((part) => part.startsWith('_'))) return true;
|
||||||
|
|
||||||
// Exclude non-root locale directories (translations duplicate English content)
|
// Exclude non-root locale directories (translations duplicate English content)
|
||||||
if (LLM_EXCLUDE_LOCALES.some((locale) => filePath.startsWith(`${locale}/`) || filePath.startsWith(`${locale}${path.sep}`))) return true;
|
if (translatedLocales.some((locale) => filePath.startsWith(`${locale}/`) || filePath.startsWith(`${locale}${path.sep}`))) return true;
|
||||||
|
|
||||||
// Check configured patterns
|
// Check configured patterns
|
||||||
return LLM_EXCLUDE_PATTERNS.some((pattern) => filePath.includes(pattern));
|
return LLM_EXCLUDE_PATTERNS.some((pattern) => filePath.includes(pattern));
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import sitemap from '@astrojs/sitemap';
|
||||||
import rehypeMarkdownLinks from './src/rehype-markdown-links.js';
|
import rehypeMarkdownLinks from './src/rehype-markdown-links.js';
|
||||||
import rehypeBasePaths from './src/rehype-base-paths.js';
|
import rehypeBasePaths from './src/rehype-base-paths.js';
|
||||||
import { getSiteUrl } from './src/lib/site-url.mjs';
|
import { getSiteUrl } from './src/lib/site-url.mjs';
|
||||||
|
import { locales } from './src/lib/locales.mjs';
|
||||||
|
|
||||||
const siteUrl = getSiteUrl();
|
const siteUrl = getSiteUrl();
|
||||||
const urlParts = new URL(siteUrl);
|
const urlParts = new URL(siteUrl);
|
||||||
|
|
@ -45,22 +46,9 @@ export default defineConfig({
|
||||||
title: 'BMAD Method',
|
title: 'BMAD Method',
|
||||||
tagline: 'AI-driven agile development with specialized agents and workflows that scale from bug fixes to enterprise platforms.',
|
tagline: 'AI-driven agile development with specialized agents and workflows that scale from bug fixes to enterprise platforms.',
|
||||||
|
|
||||||
// i18n: English as root (no URL prefix), Chinese at /zh-cn/, French at /fr/
|
// i18n: locale config from shared module (website/src/lib/locales.mjs)
|
||||||
defaultLocale: 'root',
|
defaultLocale: 'root',
|
||||||
locales: {
|
locales,
|
||||||
root: {
|
|
||||||
label: 'English',
|
|
||||||
lang: 'en',
|
|
||||||
},
|
|
||||||
'zh-cn': {
|
|
||||||
label: '简体中文',
|
|
||||||
lang: 'zh-CN',
|
|
||||||
},
|
|
||||||
fr: {
|
|
||||||
label: 'Français',
|
|
||||||
lang: 'fr-FR',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
logo: {
|
logo: {
|
||||||
light: './public/img/bmad-light.png',
|
light: './public/img/bmad-light.png',
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
/**
|
||||||
|
* Shared i18n locale configuration.
|
||||||
|
*
|
||||||
|
* Single source of truth for locale definitions used by:
|
||||||
|
* - website/astro.config.mjs (Starlight i18n)
|
||||||
|
* - tools/build-docs.mjs (llms-full.txt locale exclusion)
|
||||||
|
* - website/src/pages/404.astro (client-side locale redirect)
|
||||||
|
*
|
||||||
|
* The root locale (English) uses Starlight's 'root' key convention
|
||||||
|
* (no URL prefix). All other locales get a URL prefix matching their key.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const locales = {
|
||||||
|
root: {
|
||||||
|
label: 'English',
|
||||||
|
lang: 'en',
|
||||||
|
},
|
||||||
|
'zh-cn': {
|
||||||
|
label: '简体中文',
|
||||||
|
lang: 'zh-CN',
|
||||||
|
},
|
||||||
|
fr: {
|
||||||
|
label: 'Français',
|
||||||
|
lang: 'fr-FR',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Non-root locale keys (the URL prefixes for translated content).
|
||||||
|
* @type {string[]}
|
||||||
|
*/
|
||||||
|
export const translatedLocales = Object.keys(locales).filter((k) => k !== 'root');
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
---
|
---
|
||||||
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
|
import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
|
||||||
import { getEntry } from 'astro:content';
|
import { getEntry } from 'astro:content';
|
||||||
|
import { translatedLocales } from '../lib/locales.mjs';
|
||||||
|
|
||||||
const entry = await getEntry('docs', '404');
|
const entry = await getEntry('docs', '404');
|
||||||
const { Content } = await entry.render();
|
const { Content } = await entry.render();
|
||||||
|
|
@ -12,12 +13,11 @@ const { Content } = await entry.render();
|
||||||
|
|
||||||
<!-- GitHub Pages serves this single 404.html for all paths.
|
<!-- GitHub Pages serves this single 404.html for all paths.
|
||||||
Redirect to the locale-specific 404 page when the URL has a locale prefix. -->
|
Redirect to the locale-specific 404 page when the URL has a locale prefix. -->
|
||||||
<script is:inline>
|
<script is:inline define:vars={{ translatedLocales }}>
|
||||||
(function () {
|
(function () {
|
||||||
var locales = ['zh-cn', 'fr'];
|
|
||||||
var path = window.location.pathname;
|
var path = window.location.pathname;
|
||||||
for (var i = 0; i < locales.length; i++) {
|
for (var i = 0; i < translatedLocales.length; i++) {
|
||||||
var prefix = '/' + locales[i] + '/';
|
var prefix = '/' + translatedLocales[i] + '/';
|
||||||
if (path.startsWith(prefix) && path !== prefix + '404/') {
|
if (path.startsWith(prefix) && path !== prefix + '404/') {
|
||||||
window.location.replace(prefix + '404/');
|
window.location.replace(prefix + '404/');
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue