Skip to content

Commit bedaa78

Browse files
wquguruclaude
andcommitted
Refactor README and improve locale detection
- Update README with cleaner bilingual structure and improved content organization - Remove unnecessary TRANSLATION_CONSISTENCY_REPORT.md file - Simplify middleware to use next-intl's built-in locale detection - Clean up Navigation component language switching logic Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c3493b4 commit bedaa78

File tree

4 files changed

+112
-181
lines changed

4 files changed

+112
-181
lines changed

README.md

Lines changed: 94 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,125 @@
11
# 12Factor.me
22

3+
[中文版](#中文版) | English
4+
35
<div align="center">
4-
<div style="width: 32px; height: 32px; background-color: #1c1917; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; margin-bottom: 16px;">
5-
<div style="width: 16px; height: 16px; border: 2px solid white; border-radius: 2px;"></div>
6-
</div>
7-
<h3>12 Vibe Coding Factors</h3>
8-
<p><strong>Four-Stage Twelve-Principle methodology for 10x Engineering Efficiency</strong></p>
9-
<p>Visit: <a href="https://12factor.me">https://12factor.me</a></p>
6+
<h3>🎯 12Factor Methodology</h3>
7+
<p><strong>Master AI-Human Collaboration for 10x Engineering Efficiency</strong></p>
8+
<p><a href="https://12factor.me">12factor.me</a> | <a href="https://github.com/wquguru/12factor">GitHub</a></p>
109

1110
[![Build](https://github.com/wquguru/12factor/actions/workflows/build.yml/badge.svg)](https://github.com/wquguru/12factor/actions/workflows/build.yml)
1211
</div>
1312

1413
## Overview
1514

16-
12Factor provides real methodological insights for mastering AI-human collaboration, without the complexity overload. The platform teaches 12 essential principles through an interactive, gamified learning experience with bilingual support.
17-
18-
**Four-Stage Learning Path:**
19-
20-
1. **Prepare** - Single Source of Truth, Prompt First, Context Hygiene
21-
2. **Execute** - Human-in-the-Loop, Chunked Work, Parallel Flow
22-
3. **Collaborate** - Cognitive Load Budget, Flow Protection, Reproducible Sessions
23-
4. **Iterate** - Rest & Reflection, Skill Parity, Culture of Curiosity
15+
Interactive learning platform teaching the Four-Stage Twelve-Principle methodology for AI collaboration era. Features gamified lessons, prompt engineering playground, and bilingual support.
2416

2517
## Quick Start
2618

2719
```bash
2820
npm install
2921
npm run dev # Start at http://localhost:3000
3022
npm run build # Production build
31-
npm run lint # Code quality checks
3223
```
3324

34-
## Key Features
35-
36-
- **Bilingual Learning**: Full English and Chinese localization
37-
- **Interactive Content**: Flashcards with progress tracking
38-
- **Adaptive Quizzes**: Multiple difficulty modes with performance analytics
39-
- **10x Engineering Focus**: Systematic approach to AI collaboration efficiency
40-
- **Open Source**: MIT licensed, community-driven development
41-
42-
## LLM API Configuration
43-
44-
The prompt engineering features support custom LLM providers. Configure your API in `.env.local`:
25+
### Prompt Engineering Setup (Optional)
4526

4627
```bash
47-
# Copy environment template
4828
cp .env.example .env.local
29+
# Add your API key (OpenAI/DeepSeek/Azure)
4930
```
5031

51-
### Using DeepSeek (Recommended)
52-
```env
53-
OPENAI_API_KEY=sk-your-deepseek-key
54-
LLM_API_URL=https://api.deepseek.com/v1/chat/completions
55-
LLM_MODEL=deepseek-chat
56-
```
32+
## Learning Paths
33+
34+
### 🎓 12 Principles Course
35+
**Four Stages:** Prepare → Execute → Collaborate → Iterate
36+
- Interactive flashcards with progress tracking
37+
- Adaptive quizzes with performance analytics
38+
- Real-world examples and anti-patterns
39+
40+
### 🤖 Prompt Engineering Lab
41+
**Three Learning Modes:**
42+
- **Theory**: Core concepts and techniques
43+
- **Practice**: Guided exercises with hints
44+
- **Playground**: Live LLM experimentation
45+
46+
**Course Topics:**
47+
- Fundamentals: Structure, system prompts, role assignment
48+
- Advanced: Few-shot, chain-of-thought, temperature control
49+
- Optimization: Token efficiency, context management
50+
51+
## Features
52+
53+
- ✅ Bilingual (English/中文)
54+
- ✅ Dark mode support
55+
- ✅ Progress persistence
56+
- ✅ Multi-LLM support (OpenAI, DeepSeek, Azure)
57+
- ✅ Rate-limited API with security
58+
- ✅ Mobile responsive
59+
60+
## Tech Stack
61+
62+
Next.js 15 • TypeScript • Tailwind CSS • Zustand • next-intl
63+
64+
---
65+
66+
# 中文版
5767

58-
### Using OpenAI (Default)
59-
```env
60-
OPENAI_API_KEY=sk-your-openai-key
68+
[English](#12factorme) | 中文版
69+
70+
<div align="center">
71+
<h3>🎯 12Factor 方法论</h3>
72+
<p><strong>掌握AI协作,实现10倍工程效率</strong></p>
73+
<p><a href="https://12factor.me">12factor.me</a> | <a href="https://github.com/wquguru/12factor">GitHub</a></p>
74+
</div>
75+
76+
## 概述
77+
78+
互动学习平台,教授AI协作时代的四阶段十二原则方法论。包含游戏化课程、提示工程实验室和双语支持。
79+
80+
## 快速开始
81+
82+
```bash
83+
npm install
84+
npm run dev # 启动开发服务器 http://localhost:3000
85+
npm run build # 生产构建
6186
```
6287

63-
### Health Check
88+
### 提示工程配置(可选)
89+
6490
```bash
65-
curl http://localhost:3000/api/llm/health
91+
cp .env.example .env.local
92+
# 添加您的API密钥(OpenAI/DeepSeek/Azure)
6693
```
6794

68-
> See [LLM_API_SETUP.md](./LLM_API_SETUP.md) for more configuration options.
95+
## 学习路径
96+
97+
### 🎓 十二原则课程
98+
**四个阶段:** 准备 → 执行 → 协作 → 迭代
99+
- 互动闪卡与进度追踪
100+
- 自适应测验与性能分析
101+
- 真实案例与反模式
102+
103+
### 🤖 提示工程实验室
104+
**三种学习模式:**
105+
- **理论**:核心概念与技术
106+
- **练习**:带提示的引导练习
107+
- **实验室**:实时LLM实验
108+
109+
**课程主题:**
110+
- 基础:结构、系统提示、角色分配
111+
- 进阶:少样本学习、思维链、温度控制
112+
- 优化:令牌效率、上下文管理
113+
114+
## 功能特性
115+
116+
- ✅ 双语支持(中文/English)
117+
- ✅ 深色模式
118+
- ✅ 进度持久化
119+
- ✅ 多LLM支持(OpenAI、DeepSeek、Azure)
120+
- ✅ 限流API与安全保护
121+
- ✅ 移动端响应式
69122

70-
## Technology Stack
123+
## 技术栈
71124

72-
- **Framework**: Next.js 15 with App Router
73-
- **Language**: TypeScript (strict mode)
74-
- **Styling**: Tailwind CSS with dark mode
75-
- **State**: Zustand for lightweight management
76-
- **i18n**: next-intl for internationalization
77-
- **Icons**: Heroicons for consistent UI
78-
- **LLM**: OpenAI SDK with custom endpoint support
125+
Next.js 15 • TypeScript • Tailwind CSS • Zustand • next-intl

TRANSLATION_CONSISTENCY_REPORT.md

Lines changed: 0 additions & 87 deletions
This file was deleted.

middleware.ts

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,22 @@
1-
import { NextRequest, NextResponse } from 'next/server';
21
import createMiddleware from 'next-intl/middleware';
32
import { routing } from './src/i18n/routing';
43

5-
// Create the next-intl middleware
6-
const intlMiddleware = createMiddleware(routing);
7-
8-
export default function middleware(request: NextRequest) {
9-
const pathname = request.nextUrl.pathname;
10-
11-
// Check if this is the root path without any locale
12-
if (pathname === '/') {
13-
// Try to get the user's preferred language from cookie (set by client-side)
14-
const preferredLocale = request.cookies.get('preferred-locale')?.value;
15-
16-
if (preferredLocale && (preferredLocale === 'en' || preferredLocale === 'zh')) {
17-
// Redirect to the user's preferred locale
18-
const url = request.nextUrl.clone();
19-
url.pathname = `/${preferredLocale}`;
20-
return NextResponse.redirect(url);
21-
}
22-
23-
// Otherwise, detect from Accept-Language header
24-
const acceptLanguage = request.headers.get('accept-language') || '';
25-
26-
// Check if the browser prefers Chinese
27-
// Common Chinese language codes: zh, zh-CN, zh-TW, zh-HK, etc.
28-
const isChinese = /\bzh\b/i.test(acceptLanguage);
29-
30-
const detectedLocale = isChinese ? 'zh' : 'en';
31-
32-
// Redirect to the detected locale
33-
const url = request.nextUrl.clone();
34-
url.pathname = `/${detectedLocale}`;
35-
return NextResponse.redirect(url);
36-
}
37-
38-
// For all other paths, use the default next-intl middleware
39-
return intlMiddleware(request);
40-
}
4+
export default createMiddleware({
5+
...routing,
6+
// next-intl 会自动:
7+
// 1. 检测用户的语言偏好(从 URL、cookie、Accept-Language header)
8+
// 2. 当用户手动切换语言时,设置 NEXT_LOCALE cookie
9+
// 3. 后续访问时优先使用 cookie 中的语言设置
10+
localeDetection: true // 默认为 true,启用自动语言检测
11+
});
4112

4213
export const config = {
4314
matcher: [
4415
// Match all pathnames except for
4516
// - … if they start with `/api`, `/_next` or `/_vercel`
4617
// - … the ones containing a dot (e.g. `favicon.ico`)
47-
'/((?!api|_next|_vercel|.*\\..*).*)'
18+
'/((?!api|_next|_vercel|.*\\..*).*)',
19+
// However, match all pathnames within `/users`, including ones with a dot
20+
'/([\\w-]+)?/users/(.+)'
4821
]
4922
};

src/components/Navigation.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ export default function Navigation() {
1818
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
1919
const langMenuRef = useRef<HTMLDivElement>(null);
2020

21-
// Save user's language preference when they manually switch
22-
const handleLanguageChange = (newLocale: 'en' | 'zh') => {
23-
// Set a cookie that the middleware can read
24-
document.cookie = `preferred-locale=${newLocale};path=/;max-age=${60 * 60 * 24 * 365}`; // 1 year
21+
// Close language menu when language is changed
22+
// next-intl will automatically handle cookie management
23+
const handleLanguageChange = () => {
2524
setIsLangMenuOpen(false);
2625
};
2726

28-
2927
useEffect(() => {
3028
function handleClickOutside(event: MouseEvent) {
3129
if (langMenuRef.current && !langMenuRef.current.contains(event.target as Node)) {
@@ -145,15 +143,15 @@ export default function Navigation() {
145143
href={getNavigableHref(pathname)}
146144
locale="en"
147145
className="block px-4 py-3 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-800 rounded-t-2xl transition-colors"
148-
onClick={() => handleLanguageChange('en')}
146+
onClick={handleLanguageChange}
149147
>
150148
{t('languageLabels.english')}
151149
</Link>
152150
<Link
153151
href={getNavigableHref(pathname)}
154152
locale="zh"
155153
className="block px-4 py-3 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-800 rounded-b-2xl transition-colors"
156-
onClick={() => handleLanguageChange('zh')}
154+
onClick={handleLanguageChange}
157155
>
158156
{t('languageLabels.chinese')}
159157
</Link>
@@ -204,7 +202,7 @@ export default function Navigation() {
204202
: 'text-gray-600 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700'
205203
}`}
206204
onClick={() => {
207-
handleLanguageChange('en');
205+
handleLanguageChange();
208206
setIsMobileMenuOpen(false);
209207
}}
210208
>
@@ -219,7 +217,7 @@ export default function Navigation() {
219217
: 'text-gray-600 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700'
220218
}`}
221219
onClick={() => {
222-
handleLanguageChange('zh');
220+
handleLanguageChange();
223221
setIsMobileMenuOpen(false);
224222
}}
225223
>

0 commit comments

Comments
 (0)