Skip to content

Commit 68b0edb

Browse files
committed
feat: add translate toggle button
1 parent ad8e7cc commit 68b0edb

File tree

8 files changed

+1084
-76
lines changed

8 files changed

+1084
-76
lines changed

apps/tampermonkey/README.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Next.js Translation Helper - Tampermonkey Script
2+
3+
This Tampermonkey script adds a translation button to nextjs.org that provides quick access to community-maintained translated documentation in multiple languages.
4+
5+
## Features
6+
7+
- 🌐 Adds a globe icon (🌐) next to the "Learn" button on nextjs.org
8+
- 🎯 Click the icon to show a dropdown menu with all available language options
9+
- 🌍 Supports 9 languages: English, Chinese (Simplified & Traditional), Japanese, Spanish, German, French, Russian, and Arabic
10+
- 🚀 Preserves current page path when switching languages
11+
- 💫 Subtle, icon-only design that integrates seamlessly with Next.js UI
12+
-**React-compatible**: Handles SPA navigation and re-renders automatically
13+
- 🔄 **Smart recovery**: Re-adds button if removed by React updates
14+
- 🐛 **Debug mode**: Optional detailed logging for troubleshooting
15+
16+
## Installation
17+
18+
### Method 1: Install Pre-built Script
19+
20+
1. Install [Tampermonkey](https://tampermonkey.net/) browser extension
21+
2. Copy the contents of `dist/script.iife.js`
22+
3. Create a new script in Tampermonkey and paste the content
23+
4. Save and enable the script
24+
5. Visit [nextjs.org](https://nextjs.org) to see the translation button
25+
26+
### Method 2: Development Setup
27+
28+
1. Install dependencies:
29+
```bash
30+
pnpm install
31+
```
32+
33+
2. Start development server:
34+
```bash
35+
pnpm run dev
36+
```
37+
38+
3. Generate development script:
39+
```bash
40+
pnpm run build:dev-script
41+
```
42+
43+
4. Install the generated `tampermonkey.js` file in Tampermonkey
44+
5. The script will automatically reload when you make changes
45+
46+
## Configuration
47+
48+
Edit `tampermonkey.config` to customize the script metadata:
49+
50+
```
51+
// @name Next.js Translation Helper
52+
// @namespace https://github.com/xiaoyu2er/nextjs-i18n-docs
53+
// @version 0.0.1
54+
// @description Adds a translation button to nextjs.org with links to community-maintained translated documentation
55+
// @author next-i18n-docs
56+
// @match https://nextjs.org/*
57+
// @grant GM_xmlhttpRequest
58+
// @run-at document-end
59+
```
60+
61+
### Supported Match Patterns
62+
63+
The script runs on:
64+
- `https://nextjs.org/*` - All Next.js pages
65+
66+
### Required Permissions
67+
68+
- `GM_xmlhttpRequest` - For development mode script loading
69+
70+
## Available Languages
71+
72+
| Language | Flag | Native Name | URL |
73+
|----------|------|-------------|-----|
74+
| English | 🇺🇸 | English | https://en.nextjs.im |
75+
| Simplified Chinese | 🇨🇳 | 简体中文 | https://zh-hans.nextjs.im |
76+
| Traditional Chinese | 🇭🇰 | 繁體中文 | https://zh-hant.nextjs.im |
77+
| Japanese | 🇯🇵 | 日本語 | https://ja.nextjs.im |
78+
| Spanish | 🇪🇸 | Español | https://es.nextjs.im |
79+
| German | 🇩🇪 | Deutsch | https://de.nextjs.im |
80+
| French | 🇫🇷 | Français | https://fr.nextjs.im |
81+
| Russian | 🇷🇺 | Русский | https://ru.nextjs.im |
82+
| Arabic | 🇸🇦 | العربية | https://ar.nextjs.im |
83+
84+
## Development Commands
85+
86+
```bash
87+
# Install dependencies
88+
pnpm install
89+
90+
# Development mode with auto-reload
91+
pnpm run dev
92+
93+
# Build production script
94+
pnpm run build
95+
96+
# Type checking
97+
pnpm run type-check
98+
```
99+
100+
## How It Works
101+
102+
1. **Detection**: Script waits for the "Learn" button to appear on the page
103+
2. **Injection**: Creates a styled translation button next to the Learn button
104+
3. **Dropdown**: Shows a dropdown with flag icons and native language names
105+
4. **Navigation**: Clicking a language redirects to the translated documentation while preserving the current page path
106+
107+
## Browser Compatibility
108+
109+
- ✅ Chrome (with Tampermonkey)
110+
- ✅ Firefox (with Tampermonkey)
111+
- ✅ Safari (with Tampermonkey)
112+
- ✅ Edge (with Tampermonkey)
113+
114+
## Contributing
115+
116+
1. Fork the repository
117+
2. Make your changes in `src/main.ts`
118+
3. Test with `pnpm run dev`
119+
4. Build with `pnpm run build`
120+
5. Submit a pull request
121+
122+
## License
123+
124+
This project is part of the next-i18n-docs ecosystem.

0 commit comments

Comments
 (0)