|
| 1 | +# @next-i18n/translate |
| 2 | + |
| 3 | +A utility for translating Nextjs documentation into multiple languages. |
| 4 | + |
| 5 | +## Configuration |
| 6 | + |
| 7 | +Create a `translate.config.mjs` file in your project root with the following structure: |
| 8 | + |
| 9 | +```js |
| 10 | +// Single configuration |
| 11 | +export default { |
| 12 | + langs: { |
| 13 | + // Language configurations |
| 14 | + // Example: 'zh', 'es', 'fr', etc. |
| 15 | + [languageCode]: { |
| 16 | + name: String, // Language name |
| 17 | + guide: String, // Translation guidelines |
| 18 | + terms: { // Dictionary of common terms |
| 19 | + // 'term': 'translation' |
| 20 | + }, |
| 21 | + }, |
| 22 | + }, |
| 23 | + docsRoot: String | String[], // Root directory or array of root directories |
| 24 | + docsContext: String, // Context information for the translator |
| 25 | + pattern: String, // Optional: File pattern to match (same as --pattern) |
| 26 | +} |
| 27 | + |
| 28 | +// OR multiple configurations as an array |
| 29 | +export default [ |
| 30 | + { |
| 31 | + langs: { /* ... */ }, |
| 32 | + docsRoot: String | String[], |
| 33 | + docsContext: String, |
| 34 | + pattern: String, // Optional |
| 35 | + }, |
| 36 | + // ...more configurations |
| 37 | +] |
| 38 | +``` |
| 39 | + |
| 40 | +A sample configuration file (`translation.config.example.mjs`) is included in the repository that demonstrates how to set up translations for multiple languages including Simplified Chinese, Traditional Chinese, Japanese, Spanish, German, French, Russian, and Arabic. You can use this as a starting point for your own translations. |
| 41 | + |
| 42 | +## Usage |
| 43 | + |
| 44 | +Run the translation tool with: |
| 45 | + |
| 46 | +```bash |
| 47 | +OPENAI_API_KEY=your-openai-api-key npx translate-docs |
| 48 | +``` |
| 49 | + |
| 50 | +### Command Line Options |
| 51 | + |
| 52 | +The tool supports the following command line options: |
| 53 | + |
| 54 | +``` |
| 55 | +Options: |
| 56 | + -c, --config <path> Path to configuration file |
| 57 | + --verbose Enable verbose logging |
| 58 | + -p, --pattern <pattern> File pattern to match for updating (e.g., "*.mdx" or "**/*.tsx") |
| 59 | + -d, --docs-path <pattern> File pattern for docs to translate (e.g., "**/*.mdx") |
| 60 | + -l, --list-only Only list file status without updating docs |
| 61 | + -t, --target-language <language> Specify target language code for translation |
| 62 | + -h, --help Display help for command |
| 63 | + -v, --version Show version number |
| 64 | +``` |
| 65 | + |
| 66 | +Examples: |
| 67 | + |
| 68 | +```bash |
| 69 | +# Use a specific configuration file |
| 70 | +npx translate-docs --config ./custom-config.mjs |
| 71 | + |
| 72 | +# Only process markdown files |
| 73 | +npx translate-docs --pattern "**/*.mdx" |
| 74 | + |
| 75 | +# Just check which files would be processed without making changes |
| 76 | +npx translate-docs --list-only |
| 77 | + |
| 78 | +# Enable verbose logging for troubleshooting |
| 79 | +npx translate-docs --verbose |
| 80 | + |
| 81 | +# Translate only to a specific language |
| 82 | +npx translate-docs --target-language "zh-CN" |
| 83 | +``` |
0 commit comments