|
| 1 | +# Galio Translation Guide |
| 2 | + |
| 3 | +This guide explains how to manage translations for the Galio Docusaurus project. |
| 4 | + |
| 5 | +## Current Setup |
| 6 | + |
| 7 | +The project is configured with: |
| 8 | +- **Default locale**: English (`en`) |
| 9 | +- **Additional locale**: Spanish (`es`) |
| 10 | +- **Translation system**: Custom hook-based translations |
| 11 | + |
| 12 | +## File Structure |
| 13 | + |
| 14 | +``` |
| 15 | +├── src/ |
| 16 | +│ ├── i18n/ |
| 17 | +│ │ └── translations.ts # Translation keys and values |
| 18 | +│ ├── hooks/ |
| 19 | +│ │ └── useTranslations.ts # Custom hook for translations |
| 20 | +│ ├── pages/ # Original English pages |
| 21 | +│ └── components/ # Components (shared) |
| 22 | +├── i18n/ |
| 23 | +│ └── es/ |
| 24 | +│ └── docusaurus-plugin-content-pages/ # Spanish page translations |
| 25 | +└── docusaurus.config.ts # i18n configuration |
| 26 | +``` |
| 27 | + |
| 28 | +## How to Use Translations |
| 29 | + |
| 30 | +### 1. In Components |
| 31 | + |
| 32 | +```tsx |
| 33 | +import { useTranslations } from '../hooks/useTranslations'; |
| 34 | + |
| 35 | +export default function MyComponent() { |
| 36 | + const { t } = useTranslations(); |
| 37 | + |
| 38 | + return ( |
| 39 | + <div> |
| 40 | + <h1>{t('hero.title')}</h1> |
| 41 | + <p>{t('hero.description')}</p> |
| 42 | + </div> |
| 43 | + ); |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +### 2. Adding New Translation Keys |
| 48 | + |
| 49 | +1. **Add to `src/i18n/translations.ts`**: |
| 50 | + |
| 51 | +```typescript |
| 52 | +export const translations = { |
| 53 | + en: { |
| 54 | + // ... existing translations |
| 55 | + newSection: { |
| 56 | + title: "English Title", |
| 57 | + description: "English description" |
| 58 | + } |
| 59 | + }, |
| 60 | + es: { |
| 61 | + // ... existing translations |
| 62 | + newSection: { |
| 63 | + title: "Título en Español", |
| 64 | + description: "Descripción en español" |
| 65 | + } |
| 66 | + } |
| 67 | +}; |
| 68 | +``` |
| 69 | + |
| 70 | +2. **Use in components**: |
| 71 | + |
| 72 | +```tsx |
| 73 | +{t('newSection.title')} |
| 74 | +{t('newSection.description')} |
| 75 | +``` |
| 76 | + |
| 77 | +### 3. Creating Translated Pages |
| 78 | + |
| 79 | +For each page in `src/pages/`, create a corresponding file in: |
| 80 | +`i18n/es/docusaurus-plugin-content-pages/` |
| 81 | + |
| 82 | +Example: |
| 83 | +- Original: `src/pages/examples.tsx` |
| 84 | +- Spanish: `i18n/es/docusaurus-plugin-content-pages/examples.tsx` |
| 85 | + |
| 86 | +### 4. Adding New Locales |
| 87 | + |
| 88 | +1. **Update `docusaurus.config.ts`**: |
| 89 | + |
| 90 | +```typescript |
| 91 | +i18n: { |
| 92 | + defaultLocale: 'en', |
| 93 | + locales: ['en', 'es', 'fr'], // Add new locale |
| 94 | +}, |
| 95 | +``` |
| 96 | + |
| 97 | +2. **Create translation structure**: |
| 98 | + |
| 99 | +```bash |
| 100 | +mkdir -p i18n/fr/docusaurus-plugin-content-pages |
| 101 | +``` |
| 102 | + |
| 103 | +3. **Add translations to `translations.ts`**: |
| 104 | + |
| 105 | +```typescript |
| 106 | +export const translations = { |
| 107 | + en: { /* English translations */ }, |
| 108 | + es: { /* Spanish translations */ }, |
| 109 | + fr: { /* French translations */ } |
| 110 | +}; |
| 111 | +``` |
| 112 | + |
| 113 | +## Current Translation Keys |
| 114 | + |
| 115 | +### Hero Section (`hero.*`) |
| 116 | +- `waitOver` - "The wait is Over." |
| 117 | +- `galioHere` - "Galio is Here" |
| 118 | +- `description` - Hero description |
| 119 | +- `startBuilding` - "Start Building" |
| 120 | +- `learnMore` - "Learn More →" |
| 121 | + |
| 122 | +### Examples Page (`examples.*`) |
| 123 | +- `title` - "Made with Galio" |
| 124 | +- `subtitle` - "Explore Examples made with Galio-framework" |
| 125 | +- `github` - "Github" |
| 126 | +- `documentation` - "Documentation" |
| 127 | +- `releases` - "Releases" |
| 128 | +- `stars` - "Stars" |
| 129 | +- `fork` - "Fork" |
| 130 | +- `sponsor` - "Sponsor" |
| 131 | +- `chat` - "Chat" |
| 132 | + |
| 133 | +### Navigation (`nav.*`) |
| 134 | +- `getStarted` - "Get Started" |
| 135 | +- `starterKit` - "Starter Kit" |
| 136 | +- `components` - "Components" |
| 137 | +- `examples` - "Examples" |
| 138 | + |
| 139 | +### Footer (`footer.*`) |
| 140 | +- `docs` - "Docs" |
| 141 | +- `galioDocs` - "Galio Docs" |
| 142 | +- `community` - "Community" |
| 143 | +- `previewExpo` - "Preview on Expo" |
| 144 | +- `downloadExpo` - "Download on Expo Client" |
| 145 | +- `scanToView` - "Scan to view on your phone" |
| 146 | +- `downloadApp` - "Download App" |
| 147 | +- `copyright` - Copyright text |
| 148 | +- `communityText` - Community description |
| 149 | + |
| 150 | +## Best Practices |
| 151 | + |
| 152 | +1. **Use descriptive keys**: `hero.title` instead of just `title` |
| 153 | +2. **Group related translations**: All hero-related text under `hero.*` |
| 154 | +3. **Keep translations consistent**: Use the same terminology across components |
| 155 | +4. **Test both languages**: Always test your changes in both English and Spanish |
| 156 | +5. **Fallback gracefully**: The system falls back to English if a translation is missing |
| 157 | + |
| 158 | +## Running the Development Server |
| 159 | + |
| 160 | +```bash |
| 161 | +# Start development server |
| 162 | +npm run start |
| 163 | + |
| 164 | +# Start with Spanish locale |
| 165 | +npm run start -- --locale es |
| 166 | + |
| 167 | +# Build for production |
| 168 | +npm run build |
| 169 | + |
| 170 | +# Build for specific locale |
| 171 | +npm run build -- --locale es |
| 172 | +``` |
| 173 | + |
| 174 | +## Adding More Components |
| 175 | + |
| 176 | +To translate additional components: |
| 177 | + |
| 178 | +1. **Identify hardcoded text** in the component |
| 179 | +2. **Add translation keys** to `translations.ts` |
| 180 | +3. **Update the component** to use `useTranslations()` |
| 181 | +4. **Test** in both languages |
| 182 | + |
| 183 | +## Common Patterns |
| 184 | + |
| 185 | +### Dynamic Content |
| 186 | +```tsx |
| 187 | +// For content that includes variables |
| 188 | +const { t } = useTranslations(); |
| 189 | +const year = new Date().getFullYear(); |
| 190 | +const copyright = t('footer.copyright').replace('{year}', year.toString()); |
| 191 | +``` |
| 192 | + |
| 193 | +### Conditional Translations |
| 194 | +```tsx |
| 195 | +// For different text based on conditions |
| 196 | +const buttonText = isLoggedIn ? t('nav.logout') : t('nav.login'); |
| 197 | +``` |
| 198 | + |
| 199 | +## Troubleshooting |
| 200 | + |
| 201 | +### Translation Not Showing |
| 202 | +1. Check if the key exists in `translations.ts` |
| 203 | +2. Verify the key path is correct (e.g., `hero.title`) |
| 204 | +3. Ensure the component is using `useTranslations()` |
| 205 | + |
| 206 | +### Locale Not Switching |
| 207 | +1. Check `docusaurus.config.ts` i18n configuration |
| 208 | +2. Verify the locale dropdown is in the navbar |
| 209 | +3. Clear browser cache and restart dev server |
| 210 | + |
| 211 | +### Build Errors |
| 212 | +1. Ensure all translation keys exist for all locales |
| 213 | +2. Check for syntax errors in translation files |
| 214 | +3. Verify file paths in i18n directory structure |
| 215 | + |
| 216 | +## Next Steps |
| 217 | + |
| 218 | +1. **Translate remaining components**: Continue adding translations to other components |
| 219 | +2. **Add more locales**: Consider adding French, German, or other languages |
| 220 | +3. **Translate documentation**: Set up translations for the docs section |
| 221 | +4. **Add translation management**: Consider using a translation management system for larger projects |
0 commit comments