Skip to content

Latest commit

 

History

History
156 lines (113 loc) · 3.99 KB

File metadata and controls

156 lines (113 loc) · 3.99 KB

Internationalization (i18n) Implementation

Overview

The Notes application has been fully internationalized with support for multiple languages. All user-facing strings have been marked for translation using Qt's translation system.

Supported Languages

  • English (en) - Default language
  • Italian (it) - Full translation included

Files Modified

Main Application

  • main.py - Added i18n support, language detection, and translation loading
    • Added --lang parameter for manual language selection
    • Auto-detection from system locale
    • Translation file loading from i18n/ directory

GUI Components

All GUI widgets updated with self.tr() for translatable strings:

  • gui/notebook_list.py - Notebook list widget
  • gui/note_list.py - Note list widget
  • gui/editor_widget.py - Note editor widget

Backend (Documentation)

Updated all comments and docstrings to English:

  • models/database.py - Database management
  • speech/transcriber.py - Speech-to-text transcription

Translation Files

  • i18n/en.ts - English translation source
  • i18n/it.ts - Italian translation source
  • i18n/en.qm - English compiled (requires Qt tools)
  • i18n/it.qm - Italian compiled (requires Qt tools)

Scripts

  • update_translations.sh - Script to extract and compile translations
  • compile_translations.py - Fallback for systems without Qt tools
  • INSTALL.sh - Updated with translation compilation

Documentation

  • README.md - Fully translated to English with i18n section
  • pyproject.toml - Added translation notes

How It Works

  1. Language Detection:

    • System locale is detected automatically (QLocale.system())
    • Can be overridden with --lang parameter
  2. Translation Loading:

    • Looks for .qm file in i18n/<lang>.qm
    • Loads and installs translator if found
    • Falls back to English if translation not available
  3. String Marking:

    • All UI strings use self.tr("String") for translation
    • Format strings use .arg() method: self.tr("File '%1' saved").arg(filename)

Usage

Running with Different Languages

# Auto-detect (default)
poetry run python main.py

# Force English
poetry run python main.py --lang en

# Force Italian
poetry run python main.py --lang it

Updating Translations

When you modify strings in the code:

# Extract strings and update .ts files
./update_translations.sh

# Or manually:
pylupdate6 main.py gui/*.py -ts i18n/en.ts i18n/it.ts
lrelease i18n/en.ts i18n/it.ts

Adding a New Language

  1. Copy an existing .ts file:

    cp i18n/en.ts i18n/es.ts  # For Spanish
  2. Edit with Qt Linguist (recommended):

    linguist i18n/es.ts

    Or manually edit the XML file.

  3. Compile the translation:

    lrelease i18n/es.ts -qm i18n/es.qm
  4. Test:

    python main.py --lang es

Translation Context

All translatable strings are organized by context (class name):

  • NotesApp - Main window strings
  • NotebookList - Notebook management
  • NoteList - Note list operations
  • EditorWidget - Note editor interface

Technical Details

Qt Translation System

  • Uses QTranslator class
  • .ts files are XML-based translation source files
  • .qm files are compiled binary translation files
  • pylupdate6 extracts strings from Python code
  • lrelease compiles .ts to .qm

String Placeholders

Format: self.tr("Text with %1 placeholder").arg(value)

Example:

self.tr("Notebook '%1' created!").arg(name)

Requirements

For translation compilation:

  • pylupdate6 (included with PyQt6)
  • lrelease (requires Qt tools package)
    • Ubuntu/Debian: qttools5-dev-tools
    • Fedora: qt6-qttools
    • Arch: qt6-tools

Notes

  • All code comments and docstrings are now in English
  • User-facing strings default to English
  • Translation files can be edited without recompiling the application
  • Missing translations fall back to English
  • The application automatically detects the system language on first run