|
| 1 | +# Internationalization Guide |
| 2 | + |
| 3 | +This document explains how the internationalization (i18n) system works in the Export Trakt 4 Letterboxd project and how to contribute to translation. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The internationalization system allows the script to be displayed in different languages based on user preferences. The process is automated and selects the language based on: |
| 8 | + |
| 9 | +1. The user's explicit configuration in the `.config.cfg` file |
| 10 | +2. The operating system language if no configuration is specified |
| 11 | +3. English as the default language if the system language is not supported |
| 12 | + |
| 13 | +## Supported Languages |
| 14 | + |
| 15 | +Currently, the following languages are supported: |
| 16 | + |
| 17 | +- English (en) - Default language |
| 18 | +- French (fr) |
| 19 | +- Spanish (es) |
| 20 | +- German (de) |
| 21 | +- Italian (it) |
| 22 | + |
| 23 | +## Configuration |
| 24 | + |
| 25 | +To explicitly set the language, edit the `config/.config.cfg` file and set the `LANGUAGE` variable: |
| 26 | + |
| 27 | +```bash |
| 28 | +# Language for user interface (en, fr, es, de, it) |
| 29 | +# Leave empty for automatic detection from the system |
| 30 | +LANGUAGE="en" |
| 31 | +``` |
| 32 | + |
| 33 | +To use the system language, simply leave this value empty: |
| 34 | + |
| 35 | +```bash |
| 36 | +LANGUAGE="" |
| 37 | +``` |
| 38 | + |
| 39 | +## File Structure |
| 40 | + |
| 41 | +The internationalization system is organized according to a standard structure: |
| 42 | + |
| 43 | +``` |
| 44 | +Export_Trakt_4_Letterboxd/ |
| 45 | +├── lib/ |
| 46 | +│ ├── i18n.sh # Main internationalization module |
| 47 | +│ └── ... |
| 48 | +├── locales/ # Directory containing translations |
| 49 | +│ ├── en/ # English |
| 50 | +│ │ └── LC_MESSAGES/ |
| 51 | +│ │ └── messages.sh # English messages file |
| 52 | +│ ├── fr/ # French |
| 53 | +│ │ └── LC_MESSAGES/ |
| 54 | +│ │ └── messages.sh |
| 55 | +│ ├── es/ # Spanish |
| 56 | +│ │ └── LC_MESSAGES/ |
| 57 | +│ │ └── messages.sh |
| 58 | +│ ├── it/ # Italian |
| 59 | +│ │ └── LC_MESSAGES/ |
| 60 | +│ │ └── messages.sh |
| 61 | +│ └── de/ # German |
| 62 | +│ └── LC_MESSAGES/ |
| 63 | +│ └── messages.sh |
| 64 | +├── manage_translations.sh # Translation management utility |
| 65 | +└── ... |
| 66 | +``` |
| 67 | + |
| 68 | +## How It Works |
| 69 | + |
| 70 | +1. At startup, the script initializes the i18n module |
| 71 | +2. The module loads the language specified in the configuration file or detects the system language |
| 72 | +3. It then loads the corresponding messages from the appropriate language file |
| 73 | +4. When displaying text to the user, the script uses the `_()` function to get the translated text |
| 74 | + |
| 75 | +## Translation Management Utility |
| 76 | + |
| 77 | +A translation utility `manage_translations.sh` is provided to help manage language files. It allows you to: |
| 78 | + |
| 79 | +- List available languages |
| 80 | +- Create a template for a new language |
| 81 | +- Update language files with new strings |
| 82 | +- Display translation status for all languages |
| 83 | + |
| 84 | +### Using the Utility |
| 85 | + |
| 86 | +```bash |
| 87 | +# Display help |
| 88 | +./manage_translations.sh help |
| 89 | + |
| 90 | +# List available languages |
| 91 | +./manage_translations.sh list |
| 92 | + |
| 93 | +# Create a template for a new language (ex: Italian) |
| 94 | +./manage_translations.sh create it |
| 95 | + |
| 96 | +# Update all language files with new/missing strings |
| 97 | +./manage_translations.sh update |
| 98 | + |
| 99 | +# Display translation status for all languages |
| 100 | +./manage_translations.sh status |
| 101 | +``` |
| 102 | + |
| 103 | +## Translation Contribution Guide |
| 104 | + |
| 105 | +If you want to contribute to translating the application into a new language or improving an existing translation, follow these steps: |
| 106 | + |
| 107 | +1. **For a new language:** |
| 108 | + |
| 109 | + - Run `./manage_translations.sh create xx` (where `xx` is the 2-letter language code) |
| 110 | + - Edit the generated file in `locales/xx/LC_MESSAGES/messages.sh` |
| 111 | + |
| 112 | +2. **To update an existing translation:** |
| 113 | + - Run `./manage_translations.sh update` to add missing strings |
| 114 | + - Look for comments with `# TODO: Translate this` and translate those strings |
| 115 | + |
| 116 | +### Translation Tips |
| 117 | + |
| 118 | +- Keep special characters like `%s`, `%d`, etc. as they are used for variable insertion |
| 119 | +- Respect case and punctuation when relevant |
| 120 | +- Make sure the translated text has a similar meaning to the original text |
| 121 | +- Test your translation by setting `LANGUAGE="xx"` in the configuration file |
| 122 | + |
| 123 | +## Message File Format |
| 124 | + |
| 125 | +Each message file is a bash script that declares message variables: |
| 126 | + |
| 127 | +```bash |
| 128 | +#!/bin/bash |
| 129 | +# |
| 130 | +# Language: en |
| 131 | +# |
| 132 | + |
| 133 | +# Define messages |
| 134 | +# Variables must start with MSG_ to be recognized by the system |
| 135 | + |
| 136 | +# General messages |
| 137 | +MSG_HELLO="Hello" |
| 138 | +MSG_WELCOME="Welcome to Export Trakt 4 Letterboxd" |
| 139 | +# More translations... |
| 140 | +``` |
| 141 | + |
| 142 | +## Adding New Translatable Strings |
| 143 | + |
| 144 | +If you're developing new features that require adding new translatable strings: |
| 145 | + |
| 146 | +1. First add the string to the English file (`locales/en/LC_MESSAGES/messages.sh`) |
| 147 | +2. Use the `_()` function to reference the string in your code |
| 148 | +3. Run `./manage_translations.sh update` to update all language files |
| 149 | + |
| 150 | +## Debugging |
| 151 | + |
| 152 | +If you encounter issues with translations: |
| 153 | + |
| 154 | +1. Check that the language file exists and is properly formatted |
| 155 | +2. Verify that the message key exists in the message file |
| 156 | +3. If a translation is missing, the system will use the default English text |
| 157 | + |
| 158 | +## Locale-Specific Date and Time Formats |
| 159 | + |
| 160 | +In addition to text translation, the system also supports different date formats based on language. This allows dates to be displayed in a format familiar to users from each region. |
0 commit comments