Skip to content

Commit 6a697d9

Browse files
authored
Merge pull request #33 from JohanDevl/develop
Release v1.2.0: Internationalization and Docker improvements
2 parents 0017332 + 601e84f commit 6a697d9

File tree

18 files changed

+4558
-379
lines changed

18 files changed

+4558
-379
lines changed

Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ WORKDIR /build
99

1010
# Copy only necessary build files first
1111
COPY lib/ /build/lib/
12+
COPY locales/ /build/locales/
1213
COPY Export_Trakt_4_Letterboxd.sh setup_trakt.sh install.sh /build/
1314

1415
# Make scripts executable
@@ -67,12 +68,9 @@ ENV DOSLOG=/app/logs \
6768
# Set volume for persistent data
6869
VOLUME ["/app/logs", "/app/copy", "/app/backup", "/app/config"]
6970

70-
# Switch to non-root user for normal operation, but keep root for cron
71-
# USER appuser
72-
7371
# Health check
7472
HEALTHCHECK --interval=1m --timeout=10s --start-period=30s --retries=3 \
7573
CMD curl -f http://localhost:8000/health || exit 1
7674

7775
# Set entrypoint
78-
ENTRYPOINT ["/app/docker-entrypoint.sh"]
76+
ENTRYPOINT ["/app/docker-entrypoint.sh"]

Export_Trakt_4_Letterboxd.sh

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ LOG="${SCRIPT_DIR}/logs/Export_Trakt_4_Letterboxd_${LOG_TIMESTAMP}.log"
2727
# Create logs directory if it doesn't exist
2828
mkdir -p "${SCRIPT_DIR}/logs"
2929

30-
# Log header
31-
echo "===============================================================" | tee -a "${LOG}"
32-
echo -e "${GREEN}Export Trakt 4 Letterboxd - Starting script${NC}" | tee -a "${LOG}"
33-
echo "===============================================================" | tee -a "${LOG}"
34-
echo -e "${BLUE}$(date) - Script execution started${NC}" | tee -a "${LOG}"
35-
3630
# Source the main module
3731
if [ -f "${SCRIPT_DIR}/lib/main.sh" ]; then
3832
source "${SCRIPT_DIR}/lib/main.sh"
@@ -41,21 +35,40 @@ else
4135
exit 1
4236
fi
4337

38+
# Import modules
39+
import_modules "$SCRIPT_DIR"
40+
4441
# Default global variables
4542
TEMP_DIR="${SCRIPT_DIR}/TEMP"
4643
DOSLOG="${SCRIPT_DIR}/logs"
4744
DOSCOPY="${SCRIPT_DIR}/copy"
4845
BACKUP_DIR="${SCRIPT_DIR}/backup"
4946

47+
# Load configuration (needed for language settings)
48+
[ -f "${CONFIG_DIR}/.config.cfg" ] && source "${CONFIG_DIR}/.config.cfg"
49+
50+
# Initialize internationalization - use language from config or auto-detect
51+
init_i18n "$SCRIPT_DIR" "$LOG"
52+
53+
# Log header
54+
echo "===============================================================" | tee -a "${LOG}"
55+
echo -e "${GREEN}$(_ "welcome") - $(_ "starting")${NC}" | tee -a "${LOG}"
56+
echo "===============================================================" | tee -a "${LOG}"
57+
echo -e "${BLUE}$(date) - $(_ "script_execution_start")${NC}" | tee -a "${LOG}"
58+
59+
# Example of using internationalization
60+
echo -e "${CYAN}$(_ "WELCOME") - $(_ "running_in") $(hostname)${NC}" | tee -a "${LOG}"
61+
echo -e "${YELLOW}$(_ "language_set"): ${LANGUAGE:-$(_ "auto_detected")}${NC}" | tee -a "${LOG}"
62+
5063
# Check if we are running in Docker
5164
if [ -f "/.dockerenv" ]; then
52-
echo -e "${CYAN}Running in Docker container${NC}" | tee -a "${LOG}"
65+
echo -e "${CYAN}$(_ "running_docker")${NC}" | tee -a "${LOG}"
5366
# Docker-specific settings can be added here
5467
fi
5568

5669
# Parse command line argument (if any)
5770
OPTION="$1"
58-
echo -e "${YELLOW}Script option: ${OPTION:-none}${NC}" | tee -a "${LOG}"
71+
echo -e "${YELLOW}$(_ "script_option"): ${OPTION:-$(_ "none")}${NC}" | tee -a "${LOG}"
5972

6073
# Run the export process
6174
run_export "$SCRIPT_DIR" "$OPTION"

config/.config.cfg.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ REDIRECT_URI="urn:ietf:wg:oauth:2.0:oob"
1414
# User information
1515
USERNAME="YOUR_TRAKT_USERNAME"
1616

17+
############################################################################
18+
# LANGUAGE SETTINGS
19+
############################################################################
20+
# Language for user interface (en, fr, es, de)
21+
# Leave empty to auto-detect from system
22+
LANGUAGE=""
23+
1724
############################################################################
1825
# DIRECTORY PATHS
1926
############################################################################

docs/INTERNATIONALIZATION.md

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
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

Comments
 (0)