|
| 1 | +# LibreChat Localization Guide |
| 2 | + |
| 3 | +This guide explains how to add new languages to LibreChat's localization system. |
| 4 | + |
| 5 | +## Adding a New Language |
| 6 | + |
| 7 | +To add a new language to LibreChat, follow these steps: |
| 8 | + |
| 9 | +### 1. Add the Language to Locize Project |
| 10 | + |
| 11 | +- Navigate to the [LibreChat locize project](https://www.locize.app/cat/62uyy7c9), |
| 12 | +- Click the "ADD LANGUAGE" button, typically found within the "..." menu of the "Start to translate" card on the project overview page. |
| 13 | + |
| 14 | +### 2. Update the Language Selector Component |
| 15 | + |
| 16 | +Edit `client/src/components/Nav/SettingsTabs/General/General.tsx` and add your new language option to the `languageOptions` array: |
| 17 | + |
| 18 | +```typescript |
| 19 | +{ value: 'language-code', label: localize('com_nav_lang_language_name') }, |
| 20 | +``` |
| 21 | + |
| 22 | +Example: |
| 23 | +```typescript |
| 24 | +{ value: 'bo', label: localize('com_nav_lang_tibetan') }, |
| 25 | +{ value: 'uk-UA', label: localize('com_nav_lang_ukrainian') }, |
| 26 | +``` |
| 27 | + |
| 28 | +**Note:** Use the appropriate language code format: |
| 29 | +- Use simple codes (e.g., `bo`) for languages without regional variants |
| 30 | +- Use region-specific codes (e.g., `uk-UA`) when needed |
| 31 | + |
| 32 | +### 3. Add Localization Keys |
| 33 | + |
| 34 | +In `client/src/locales/en/translation.json`, add the corresponding localization key for your language label: |
| 35 | + |
| 36 | +```json |
| 37 | +"com_nav_lang_language_name": "Native Language Name", |
| 38 | +``` |
| 39 | + |
| 40 | +Example: |
| 41 | +```json |
| 42 | +"com_nav_lang_tibetan": "བོད་སྐད་", |
| 43 | +"com_nav_lang_ukrainian": "Українська", |
| 44 | +``` |
| 45 | + |
| 46 | +**Best Practice:** Use the native language name as the value. |
| 47 | + |
| 48 | +### 4. Create the Translation File |
| 49 | + |
| 50 | +Create a new directory and translation file: |
| 51 | + |
| 52 | +```bash |
| 53 | +mkdir -p client/src/locales/[language-code] |
| 54 | +``` |
| 55 | + |
| 56 | +Create `client/src/locales/[language-code]/translation.json` with an empty JSON object: |
| 57 | + |
| 58 | +```json |
| 59 | +{ |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +Example: |
| 64 | +- `client/src/locales/bo/translation.json` |
| 65 | +- `client/src/locales/uk/translation.json` |
| 66 | + |
| 67 | +### 5. Configure i18n |
| 68 | + |
| 69 | +Update `client/src/locales/i18n.ts`: |
| 70 | + |
| 71 | +1. Import the new translation file: |
| 72 | +```typescript |
| 73 | +import translationLanguageCode from './language-code/translation.json'; |
| 74 | +``` |
| 75 | + |
| 76 | +2. Add it to the `resources` object: |
| 77 | +```typescript |
| 78 | +export const resources = { |
| 79 | + // ... existing languages |
| 80 | + 'language-code': { translation: translationLanguageCode }, |
| 81 | +} as const; |
| 82 | +``` |
| 83 | + |
| 84 | +Example: |
| 85 | +```typescript |
| 86 | +import translationBo from './bo/translation.json'; |
| 87 | +import translationUk from './uk/translation.json'; |
| 88 | + |
| 89 | +export const resources = { |
| 90 | + // ... existing languages |
| 91 | + bo: { translation: translationBo }, |
| 92 | + uk: { translation: translationUk }, |
| 93 | +} as const; |
| 94 | +``` |
| 95 | + |
| 96 | +### 6. Handle Fallback Languages (Optional) |
| 97 | + |
| 98 | +If your language should fall back to a specific language when translations are missing, update the `fallbackLng` configuration in `i18n.ts`: |
| 99 | + |
| 100 | +```typescript |
| 101 | +fallbackLng: { |
| 102 | + 'language-variant': ['fallback-language', 'en'], |
| 103 | + // ... existing fallbacks |
| 104 | +}, |
| 105 | +``` |
| 106 | + |
| 107 | +## Translation Process |
| 108 | + |
| 109 | +After adding a new language: |
| 110 | + |
| 111 | +1. The empty translation file will be populated through LibreChat's automated translation platform |
| 112 | +2. Only the English (`en`) translation file should be manually updated |
| 113 | +3. Other language translations are managed externally |
| 114 | + |
| 115 | +## Language Code Standards |
| 116 | + |
| 117 | +- Use ISO 639-1 codes for most languages (e.g., `en`, `fr`, `de`) |
| 118 | +- Use ISO 639-1 with region codes when needed (e.g., `pt-BR`, `zh-Hans`) |
| 119 | +- Tibetan uses `bo` (Bodic) |
| 120 | +- Ukrainian uses `uk` or `uk-UA` with region |
| 121 | + |
| 122 | +## Testing |
| 123 | + |
| 124 | +After adding a new language: |
| 125 | + |
| 126 | +1. Restart the development server |
| 127 | +2. Navigate to Settings > General |
| 128 | +3. Verify your language appears in the dropdown |
| 129 | +4. Select it to ensure it changes the UI language code |
| 130 | + |
| 131 | +## Notes |
| 132 | + |
| 133 | +- Keep language options alphabetically sorted in the dropdown for better UX |
| 134 | +- Always use native script for language names in the dropdown |
| 135 | +- The system will use English as fallback for any missing translations |
0 commit comments