Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
43 changes: 35 additions & 8 deletions .github/scripts/mobile_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
'email': 'mobile-ci@example.test',
'createTime': '2026-01-01T00:00:00Z',
'timeZone': 'America/New_York',
'locale': 'en-US',
'localeRevision': '0',
}


Expand All @@ -50,7 +52,12 @@ async def api(route: Route) -> None:
"""
request = route.request
path = urlparse(request.url).path.removeprefix('/dev-api')
headers = {'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Headers': '*'}
headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': '*',
'Access-Control-Expose-Headers': 'Content-Language',
'Content-Language': request.headers.get('accept-language', 'zh-CN'),
}
if request.method == 'OPTIONS':
await route.fulfill(status=204, headers=headers)
return
Expand All @@ -60,6 +67,7 @@ async def api(route: Route) -> None:
'method': request.method,
'authorization': request.headers.get('authorization'),
'timezone': request.headers.get('x-timezone'),
'locale': request.headers.get('accept-language'),
}
)
payload: dict[str, Any]
Expand Down Expand Up @@ -135,6 +143,21 @@ async def check_login_styles(framework: str, page: Page, login_button: Locator)
return styles


def check_profile_requests(observed: list[dict[str, Any]]) -> None:
"""
验证账号恢复后的认证、时区、语言与初始化请求头。

:param observed: 实际发出的 API 请求记录
:return: None
"""
profile_requests = [request for request in observed if request['path'] == '/system/user/profile']
assert profile_requests, '个人资料页未发送真实 API 请求'
assert all(request['authorization'] == f'Bearer {TOKEN}' for request in profile_requests)
assert all(request['timezone'] == 'America/New_York' for request in profile_requests)
assert all(request['locale'] == 'en-US' for request in profile_requests)
assert all(request['locale'] in {'zh-CN', 'en-US'} for request in observed)


async def run_smoke(framework: str, base_url: str, output: Path) -> None:
"""
使用真实 H5 构建验证登录、持久化身份和个人资料页。
Expand Down Expand Up @@ -165,7 +188,7 @@ async def run_smoke(framework: str, base_url: str, output: Path) -> None:
try:
await page.goto(f'{base_url}/#/pages/login')
await expect(page.locator('input[type="text"]')).to_be_visible(timeout=30000)
await expect(page.locator('input')).to_have_count(2, timeout=15000)
await expect(page.locator('input:visible')).to_have_count(2, timeout=15000)
button = page.get_by_role('button') if framework == 'react' else page.locator('uni-button')
login_button = button.filter(has_text=re.compile(r'登\s*录'))
login_styles = await check_login_styles(framework, page, login_button)
Expand All @@ -176,11 +199,15 @@ async def run_smoke(framework: str, base_url: str, output: Path) -> None:
await expect(page).to_have_url(re.compile(r'/pages/index'), timeout=30000)
await page.goto(f'{base_url}/#/pages/mine/info/index')
await expect(page.get_by_text(USER['nickName'], exact=True)).to_be_visible(timeout=30000)
await expect(page.get_by_text('2025-12-31 19:00:00', exact=True)).to_be_visible(timeout=15000)
profile_requests = [request for request in observed if request['path'] == '/system/user/profile']
assert profile_requests, '个人资料页未发送真实 API 请求'
assert all(request['authorization'] == f'Bearer {TOKEN}' for request in profile_requests)
assert all(request['timezone'] == 'America/New_York' for request in profile_requests)
await expect(page.get_by_text('Nickname', exact=True)).to_be_visible(timeout=15000)
created_at = await page.evaluate(
"""({locale, timeZone, createTime}) => new Intl.DateTimeFormat(locale, {
dateStyle: 'medium', timeStyle: 'medium', timeZone
}).format(new Date(createTime))""",
{key: USER[key] for key in ('locale', 'timeZone', 'createTime')},
)
await expect(page.get_by_text(created_at, exact=True)).to_be_visible(timeout=15000)
check_profile_requests(observed)
assert not errors, errors
(output / 'result.json').write_text(
json.dumps(
Expand All @@ -190,7 +217,7 @@ async def run_smoke(framework: str, base_url: str, output: Path) -> None:
),
encoding='utf-8',
)
print(f'{framework}: H5 login, persisted session and timezone profile PASS')
print(f'{framework}: H5 login, account locale, language headers and timezone profile PASS')
except BaseException:
failed = True
await page.screenshot(path=str(output / 'failure.png'), full_page=True)
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/ci-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,33 @@ jobs:
ruoyi-fastapi-backend/plugins/ai/plugin.yaml
- name: Install MySQL, PostgreSQL and test dependencies
run: python -m pip install -r requirements.txt -r requirements-pg.txt -r requirements-test.txt
- name: Compile and validate gettext catalogs
run: python scripts/compile_i18n.py
- uses: actions/setup-node@v6
with:
node-version: '22'
- uses: pnpm/action-setup@v5
with:
package_json_file: ruoyi-fastapi-frontend/vue2/web/package.json
- name: Locate the pnpm store
id: pnpm-store
run: echo "path=$(pnpm store path --silent)" >> "$GITHUB_OUTPUT"
working-directory: ruoyi-fastapi-frontend/vue2/web
- uses: actions/cache@v5
with:
path: ${{ steps.pnpm-store.outputs.path }}
key: ${{ runner.os }}-generator-web-node22-${{ hashFiles('ruoyi-fastapi-frontend/*/web/pnpm-lock.yaml', 'ruoyi-fastapi-frontend/*/web/pnpm-workspace.yaml', 'ruoyi-fastapi-frontend/*/web/package.json') }}
- name: Install Web dependencies for generator tests
working-directory: ruoyi-fastapi-frontend
run: |
for framework in vue2 vue3 react; do
pnpm --dir "$framework/web" install --frozen-lockfile
done
- name: Install locked backend translation tooling and run read-only checks
run: |
npm ci --prefix .x18n/tooling --ignore-scripts
node .x18n/tooling/check-domains.mjs
npm test --prefix .x18n/tooling
- name: Install AI plugin dependencies from its manifest
run: python ../.github/scripts/install_ai_test_dependencies.py
- name: Check dependency consistency
Expand Down Expand Up @@ -63,6 +90,7 @@ jobs:
cache: pip
cache-dependency-path: ruoyi-fastapi-backend/requirements*.txt
- run: python -m pip install -r requirements.txt -r requirements-test.txt
- run: python scripts/compile_i18n.py
- name: Verify CLI, paths, artifacts and portable runtime contracts
run: >-
python -m pytest tests/cli
Expand Down Expand Up @@ -96,6 +124,7 @@ jobs:
cache: pip
cache-dependency-path: ruoyi-fastapi-backend/requirements*.txt
- run: python -m pip install -r requirements.txt -r requirements-test.txt
- run: python scripts/compile_i18n.py
- name: Verify UTC, Shanghai and New York in separate processes
shell: bash
run: |
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/ci-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ jobs:
if ! pnpm list --depth Infinity --json > test-results/dependency-tree.json; then
echo "Dependency tree includes peer diagnostics; inspect dependency-tree.json." >&2
fi
- name: Verify independent locale resources and runtime contracts
run: |
pnpm run i18n:check > test-results/i18n.json.log
pnpm run test:i18n
- name: Run unit and component behavior tests
run: pnpm run test:unit
- name: Verify time contracts in three host timezones
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
cache: pip
cache-dependency-path: ruoyi-fastapi-backend/requirements*.txt
- run: python -m pip install -r requirements.txt -r requirements-pg.txt -r requirements-test.txt
- run: python scripts/compile_i18n.py
- name: Configure isolated database verification
run: |
mkdir -p target/ci/timezone
Expand Down Expand Up @@ -169,6 +170,7 @@ jobs:
cache: pip
cache-dependency-path: ruoyi-fastapi-backend/requirements*.txt
- run: python -m pip install -r requirements.txt -r requirements-pg.txt
- run: python scripts/compile_i18n.py
- name: Verify MySQL and PostgreSQL maintenance releases
shell: bash
run: |
Expand Down Expand Up @@ -220,6 +222,7 @@ jobs:
path: ${{ steps.pnpm-store.outputs.path }}
key: ${{ runner.os }}-network-${{ matrix.framework }}-${{ hashFiles(format('ruoyi-fastapi-frontend/{0}/web/pnpm-lock.yaml', matrix.framework)) }}
- run: python -m pip install -r requirements.txt -r requirements-test.txt playwright==1.64.0
- run: python scripts/compile_i18n.py
- run: python -m playwright install --with-deps chromium
- name: Install Web dependencies
working-directory: ruoyi-fastapi-frontend/${{ matrix.framework }}/web
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
cache: pip
cache-dependency-path: ruoyi-fastapi-backend/requirements*.txt
- run: python -m pip install -r requirements.txt -r requirements-test.txt 'maturin>=1.15,<2'
- run: python scripts/compile_i18n.py
- run: rustup toolchain install 1.99.0 --profile minimal
- run: rustup default 1.99.0
- uses: actions/cache@v5
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,6 @@ cython_debug/
.opencode/
.qoder/
.trae/

# Backend development-only translation tool dependencies
/ruoyi-fastapi-backend/.x18n/tooling/node_modules/
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,24 @@ RuoYi-FastAPI/
└── ruoyi-fastapi-test/ # 端到端与跨工程契约测试
```

### 国际化词库

六个前端各自在 `src/i18n/locales/<语言>/<命名空间>.json` 维护页面文案。同一功能的中英文使用相同的语义 key,并保留各语言需要的复数形式。新增词条时,按使用它的功能选择文件。

| 文案用途 | 归属与示例 |
| --- | --- |
| 跨功能通用操作 | `common`,如 `common:cancel` |
| 应用登录、注册和密码校验 | `auth`,如 `auth:login.passwordRequired` |
| Web 统一认证中心与 OAuth 后台 | 用户授权页归 `authCenter`;后台应用、授权、密钥等按 `oauth:client.*`、`oauth:grant.*`、`oauth:key.*` 分组 |
| 业务页面与可复用组件 | 菜单、字典等归 `system`;编辑器、Cron 选择器等归 `components`;移动端首页、个人资料等在 `mobile` 下按页面分组 |
| 插件自有文案 | Web 源码插件在自己的 `plugins/<id>/locales` 中维护;宿主的插件管理页面使用宿主词库 |

在对应前端目录运行 `pnpm run i18n:check` 和 `pnpm run test:i18n`。新增命名空间时,同时确认该应用的 `src/i18n/registry.js` 已加载新文件。

后端 API 消息使用 gettext。宿主词库源文件位于 `i18n/catalogs/<语言>/LC_MESSAGES/core/<模块>.po`。例如,用户和角色消息放在 `system.po`,文件服务消息放在 `file.po`,插件运行时消息放在 `plugin_runtime.po`。新增业务模块时,在每个已启用语言下添加同名 PO,保持消息标识、上下文和复数标识一致。代码生成器按业务表输出独立的 `generated.<模块>.<业务>.po`。

在后端目录运行 `python scripts/compile_i18n.py` 会自动发现并校验各模块,每种语言合并生成一份 `LC_MESSAGES/core.mo`。业务代码继续使用原有消息 key。插件专属消息由插件自己的 `i18n/catalogs/<语言>/LC_MESSAGES/plugin.<id>.po` 维护。

### 传输层加解密配置说明

后端密钥配置与轮换说明:[ruoyi-fastapi-backend/docs/transport_crypto_config.md](./ruoyi-fastapi-backend/docs/transport_crypto_config.md)
Expand Down Expand Up @@ -310,7 +328,7 @@ ruoyi plugin install-deps ai
1.新建数据库ruoyi-fastapi(默认,可修改)
2.如果使用的是MySQL数据库,使用命令或数据库连接工具运行sql文件夹下的ruoyi-fastapi.sql;如果使用的是PostgreSQL数据库,使用命令或数据库连接工具运行sql文件夹下的ruoyi-fastapi-pg.sql

# 运行后端
# 启动后端(自动编译语言资源)
ruoyi app run --env=dev
```

Expand Down Expand Up @@ -347,7 +365,7 @@ pnpm run build:prod
# 配置环境
在.env.prod文件中配置生产环境的数据库和redis

# 运行后端
# 在后端目录启动生产服务
ruoyi app run --env=prod
```

Expand Down
2 changes: 2 additions & 0 deletions ruoyi-fastapi-backend/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ target
logs
*.log
*.egg-info

.x18n
4 changes: 4 additions & 0 deletions ruoyi-fastapi-backend/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ APP_DEFAULT_ENABLED_PLUGINS = 'ai'
# 应用业务时区,使用IANA时区名称(如Asia/Shanghai),用于时间展示、日期范围查询和定时任务默认时区
APP_TIMEZONE = 'Asia/Shanghai'

# -------- 国际化配置 --------
# 默认响应语言,必须使用后端语言注册表中已启用的语言标识
I18N_DEFAULT_LOCALE = 'zh-CN'

# -------- Jwt配置 --------
# Jwt秘钥,留空时自动生成,开发环境下不要留空;也可使用 openssl rand -hex 32 手动生成
JWT_SECRET_KEY = 'b01c66dc2c58dc6a0aabfe2144256be36226de378bf87f72c0c795dda67f4d55'
Expand Down
4 changes: 4 additions & 0 deletions ruoyi-fastapi-backend/.env.dockermy
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ APP_DEFAULT_ENABLED_PLUGINS = 'ai'
# 应用业务时区,使用IANA时区名称(如Asia/Shanghai),用于时间展示、日期范围查询和定时任务默认时区
APP_TIMEZONE = 'Asia/Shanghai'

# -------- 国际化配置 --------
# 默认响应语言,必须使用后端语言注册表中已启用的语言标识
I18N_DEFAULT_LOCALE = 'zh-CN'

# -------- Jwt配置 --------
# Jwt秘钥,留空时自动生成;也可使用 openssl rand -hex 32 手动生成
JWT_SECRET_KEY = ''
Expand Down
4 changes: 4 additions & 0 deletions ruoyi-fastapi-backend/.env.dockerpg
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ APP_DEFAULT_ENABLED_PLUGINS = 'ai'
# 应用业务时区,使用IANA时区名称(如Asia/Shanghai),用于时间展示、日期范围查询和定时任务默认时区
APP_TIMEZONE = 'Asia/Shanghai'

# -------- 国际化配置 --------
# 默认响应语言,必须使用后端语言注册表中已启用的语言标识
I18N_DEFAULT_LOCALE = 'zh-CN'

# -------- Jwt配置 --------
# Jwt秘钥,留空时自动生成;也可使用 openssl rand -hex 32 手动生成
JWT_SECRET_KEY = ''
Expand Down
4 changes: 4 additions & 0 deletions ruoyi-fastapi-backend/.env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ APP_DEFAULT_ENABLED_PLUGINS = 'ai'
# 应用业务时区,使用IANA时区名称(如Asia/Shanghai),用于时间展示、日期范围查询和定时任务默认时区
APP_TIMEZONE = 'Asia/Shanghai'

# -------- 国际化配置 --------
# 默认响应语言,必须使用后端语言注册表中已启用的语言标识
I18N_DEFAULT_LOCALE = 'zh-CN'

# -------- Jwt配置 --------
# Jwt秘钥,留空时自动生成;也可使用 openssl rand -hex 32 手动生成
JWT_SECRET_KEY = ''
Expand Down
26 changes: 26 additions & 0 deletions ruoyi-fastapi-backend/.x18n/core.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pythonDomain from './python-domain.mjs'

// https://x18n.dev/raw/presets/python-gettext.md
// PO 的完整语义由 scripts/compile_i18n.py 校验并编译。
export default {
name: 'core',
root: '..',
sourceLocale: 'zh-CN',
presets: ['python-gettext'],
plugins: [pythonDomain('core')],
resources: [{ pattern: 'i18n/catalogs/{locale}/LC_MESSAGES/core/*.po' }],
usage: {
include: ['**/*.py'],
// 这三个文件只生成前端源码,其中的 t() 由目标应用的 x18n 检查。
exclude: [
'tests/**',
'.x18n/**',
'target/**',
'i18n/translator.py',
'cli/runtime/plugin/scaffold/frontend.py',
'cli/runtime/plugin/scaffold/frontend_vue2.py',
'cli/runtime/plugin/scaffold/frontend_react.py',
],
},
checks: { 'missing-translation': 'error', 'empty-translation': 'error', 'unused-key': 'warning' },
}
79 changes: 79 additions & 0 deletions ruoyi-fastapi-backend/.x18n/python-domain.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// 官方 Scanner API:https://x18n.dev/raw/plugins/capabilities.md
import { spawnSync } from 'node:child_process'
import { existsSync } from 'node:fs'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'

const script = fileURLToPath(new URL('./scan_python_domains.py', import.meta.url))
function parse(sources) {
const result = spawnSync(process.env.X18N_PYTHON || 'python', [script], {
input: JSON.stringify(sources),
encoding: 'utf8',
maxBuffer: 32 * 1024 * 1024,
})
if (result.error || result.status !== 0)
throw new Error(`Python domain scan failed: ${result.error?.message || result.stderr}`)
return JSON.parse(result.stdout)
}

function select(usages, domain, root) {
for (const usage of usages) {
if (usage.domain === 'core' || usage.domain === domain) continue
const match = /^plugin\.([a-z][a-z0-9_-]{0,63})$/.exec(usage.domain)
if (
(domain && domain !== 'core') ||
!match ||
!existsSync(join(root, 'plugins', match[1], 'i18n/locale-meta.json'))
)
throw new Error(`Undeclared gettext domain: ${usage.domain}`)
}
return usages
.filter((usage) => !domain || usage.domain === domain)
.map(({ domain: namespace, ...usage }) => (domain ? usage : { ...usage, namespace }))
}

export default function pythonDomain(domain) {
let root
const scans = new Map()
return {
name: 'ruoyi-python-domains',
enforce: 'post',
async config(draft, { host, user }) {
root = host.root
// 保留预设中的其他文件类型;Python 调用通过 AST 分类,支持嵌套参数。
draft.usage.regex = draft.usage.regex
.map((rule) => ({
...rule,
extensions: rule.extensions.filter((extension) => extension !== 'py'),
}))
.filter((rule) => rule.extensions.length)
const include = user.usage?.include || draft.usage.include
const ignore = [...draft.usage.exclude, ...(user.usage?.exclude || [])]
const paths = (await host.glob(include, { ignore })).filter((path) => path.endsWith('.py'))
const sources = await Promise.all(
paths.map(async (path) => ({ path, text: await host.readFile(path) }))
)
const parsed = parse(sources)
parsed.forEach((item, index) =>
scans.set(item.path, {
text: sources[index].text,
usages: select(item.usages, domain, root),
})
)
},
scanners: [
{
id: 'ruoyi-python-domain-calls',
extensions: ['py'],
scan(file) {
let result = scans.get(file.path)
if (result?.text !== file.text) {
result = { text: file.text, usages: select(parse([file])[0].usages, domain, root) }
scans.set(file.path, result)
}
return { usages: result.usages }
},
},
],
}
}
Loading
Loading