kAirPods icon indicating copy to clipboard operation
kAirPods copied to clipboard

Translation support

Open Vistaus opened this issue 4 months ago • 2 comments

It would be great if this awesome plasmoid (thanks for creating it, btw!) could be translated. I will provide the Dutch translation. 🙂

Vistaus avatar Jul 31 '25 19:07 Vistaus

I wanted to setup the templates for this but for some reason had quite a bit of an issue getting i18n's working based on https://develop.kde.org/docs/plasma/widget/translations-i18n/.

If you can set it up I'd be more than happy to merge it.

Here's my attempt:



diff --git a/.gitignore b/.gitignore
index 33cc55e..e6d8896 100644
--- a/.gitignore
+++ b/.gitignore
@@ -52,3 +52,7 @@ re.sh
 /scripts/local/
 /.env
 node_modules/
+
+# Translation files
+*.mo
+plasmoid/contents/locale/*/LC_MESSAGES/
diff --git a/INSTALL.md b/INSTALL.md
index 586d8cf..5c1b610 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -11,17 +11,15 @@
 
   ```bash
   # Debian/Ubuntu
-  sudo apt install build-essential pkg-config libdbus-1-dev libbluetooth-dev
+  sudo apt install build-essential pkg-config libdbus-1-dev libbluetooth-dev gettext
 
   # Fedora
-  sudo dnf install gcc pkg-config dbus-devel bluez-libs-devel
+  sudo dnf install gcc pkg-config dbus-devel bluez-libs-devel gettext
 
   # Arch
-  sudo pacman -S base-devel pkgconf dbus bluez-libs
+  sudo pacman -S base-devel pkgconf dbus bluez-libs gettext
   ```
 
-- Plasma SDK (provides `kpackagetool6` for widget installation)
-
 ## Building from Source
 
 1. **Clone the repository**
@@ -39,7 +37,21 @@
    cd ..
    ```
 
-3. **Install components**
+3. **Compile translations (optional)**
+
+   ```bash
+   cd plasmoid
+   for po_file in contents/locale/*.po; do
+     if [[ -f "$po_file" ]]; then
+       lang=$(basename "$po_file" .po)
+       mkdir -p "contents/locale/$lang/LC_MESSAGES"
+       msgfmt -o "contents/locale/$lang/LC_MESSAGES/kairpods.mo" "$po_file"
+     fi
+   done
+   cd ..
+   ```
+
+4. **Install components**
 
    ```bash
    # Install the service binary
@@ -53,7 +65,7 @@
    kpackagetool6 --type Plasma/Applet --install plasmoid
    ```
 
-4. **Enable and start the service**
+5. **Enable and start the service**
    ```bash
    systemctl --user daemon-reload
    systemctl --user enable --now kairpodsd
diff --git a/README.md b/README.md
index ace6dc9..874c495 100644
--- a/README.md
+++ b/README.md
@@ -74,7 +74,7 @@ The installer will:
 <summary><b>Debian/Ubuntu</b></summary>
 
 ```bash
-sudo apt install build-essential pkg-config libdbus-1-dev libbluetooth-dev
+sudo apt install build-essential pkg-config libdbus-1-dev libbluetooth-dev gettext
 ```
 
 </details>
@@ -83,7 +83,7 @@ sudo apt install build-essential pkg-config libdbus-1-dev libbluetooth-dev
 <summary><b>Fedora</b></summary>
 
 ```bash
-sudo dnf install gcc pkg-config dbus-devel bluez-libs-devel
+sudo dnf install gcc pkg-config dbus-devel bluez-libs-devel gettext
 ```
 
 </details>
@@ -92,7 +92,7 @@ sudo dnf install gcc pkg-config dbus-devel bluez-libs-devel
 <summary><b>Arch Linux</b></summary>
 
 ```bash
-sudo pacman -S base-devel pkgconf dbus bluez-libs
+sudo pacman -S base-devel pkgconf dbus bluez-libs gettext
 ```
 
 </details>
diff --git a/plasmoid/Messages.sh b/plasmoid/Messages.sh
new file mode 100755
index 0000000..8eb106b
--- /dev/null
+++ b/plasmoid/Messages.sh
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+# Extract translatable strings from QML files for kAirPods plasmoid
+
+BASEDIR=$(dirname "$0")
+PROJECT="plasma_applet_org.kairpods.plasma"
+BUGADDR="https://github.com/can1357/kAirPods/issues"
+WDIR="$BASEDIR/contents"
+POTFILE="$BASEDIR/contents/locale/$PROJECT.pot"
+
+echo "Extracting messages from QML files..."
+
+# Extract strings from QML files
+find "$WDIR/ui" -name '*.qml' | sort | xargs xgettext \
+    --from-code=UTF-8 \
+    --language=javascript \
+    --keyword=i18n:1 \
+    --keyword=i18nc:1c,2 \
+    --keyword=i18np:1,2 \
+    --keyword=i18ncp:1c,2,3 \
+    --msgid-bugs-address="$BUGADDR" \
+    --package-name="$PROJECT" \
+    --output="$POTFILE"
+
+# Update metadata in POT file
+sed -i 's/SOME DESCRIPTIVE TITLE./kAirPods Plasmoid Translation File/' "$POTFILE"
+sed -i 's/YEAR THE PACKAGE'"'"'S COPYRIGHT HOLDER/2025 Can Boluk/' "$POTFILE"
+sed -i 's/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR./Can Boluk <[email protected]>, 2025./' "$POTFILE"
+
+echo "POT file generated at: $POTFILE"
+
+# Update existing PO files
+for po in "$BASEDIR/contents/locale/"*.po; do
+    if [ -f "$po" ]; then
+        echo "Updating $(basename "$po")..."
+        msgmerge --update --no-fuzzy-matching "$po" "$POTFILE"
+    fi
+done
+
+echo "Translation extraction complete!"
\ No newline at end of file
diff --git a/plasmoid/contents/locale/es.po b/plasmoid/contents/locale/es.po
new file mode 100644
index 0000000..ad624eb
--- /dev/null
+++ b/plasmoid/contents/locale/es.po
@@ -0,0 +1,91 @@
+# Spanish translations for kairpods package
+# Traducciones al español para el paquete kairpods.
+# Copyright (C) 2025 Can Boluk
+# This file is distributed under the same license as the kairpods package.
+# Translator Name <[email protected]>, 2025.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: plasma_applet_org.kairpods.plasma\n"
+"Report-Msgid-Bugs-To: https://github.com/can1357/kAirPods/issues\n"
+"POT-Creation-Date: 2025-07-31 12:00+0000\n"
+"PO-Revision-Date: 2025-07-31 12:00+0000\n"
+"Last-Translator: Translator Name <[email protected]>\n"
+"Language-Team: Spanish <[email protected]>\n"
+"Language: es\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#: ui/main.qml:184
+msgid "kAirPods Service Unavailable"
+msgstr "Servicio kAirPods no disponible"
+
+#: ui/main.qml:190
+msgid "The kAirPods service is not installed or not running"
+msgstr "El servicio kAirPods no está instalado o no se está ejecutando"
+
+#: ui/main.qml:198
+msgid "Install kAirPods"
+msgstr "Instalar kAirPods"
+
+#: ui/FullView.qml:61
+msgid "Device"
+msgstr "Dispositivo"
+
+#: ui/FullView.qml:125
+msgid "No devices"
+msgstr "Sin dispositivos"
+
+#: ui/FullView.qml:207
+msgid "No device connected"
+msgstr "Ningún dispositivo conectado"
+
+#: ui/BatteryStatus.qml:11
+msgid "Battery"
+msgstr "Batería"
+
+#: ui/BatteryStatus.qml:21
+msgid "~%1m left"
+msgstr "~%1m restantes"
+
+#: ui/BatteryStatus.qml:23
+msgid "~1h left"
+msgstr "~1h restante"
+
+#: ui/BatteryStatus.qml:25
+msgid "~%1h left"
+msgstr "~%1h restantes"
+
+#: ui/BatteryStatus.qml:27
+msgid "~%1h %2m left"
+msgstr "~%1h %2m restantes"
+
+#: ui/BatteryStatus.qml:45
+msgid "L"
+msgstr "I"
+
+#: ui/BatteryStatus.qml:58
+msgid "R"
+msgstr "D"
+
+#: ui/NoiseControlPanel.qml:12
+msgid "Noise Cancellation"
+msgstr "Cancelación de ruido"
+
+#: ui/NoiseControlPanel.qml:25
+msgid "Off"
+msgstr "Apagado"
+
+#: ui/NoiseControlPanel.qml:36
+msgid "Active"
+msgstr "Activo"
+
+#: ui/NoiseControlPanel.qml:47
+msgid "Transparency"
+msgstr "Transparencia"
+
+#: ui/NoiseControlPanel.qml:58
+msgid "Adaptive"
+msgstr "Adaptativo"
\ No newline at end of file
diff --git a/plasmoid/metadata.json b/plasmoid/metadata.json
index dc20ed1..ebb559f 100644
--- a/plasmoid/metadata.json
+++ b/plasmoid/metadata.json
@@ -21,7 +21,7 @@
 		"Source": "https://github.com/can1357/kAirPods",
 		"Contributors": [],
 		"Dependencies": [],
-		"Translations": false
+		"Translations": true
 	},
 	"X-Plasma-API-Minimum-Version": "6.0",
 	"X-Plasma-MainScript": "ui/main.qml",
diff --git a/scripts/install.sh b/scripts/install.sh
index 61e2989..7ec0faa 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -220,11 +220,11 @@ if [[ ${#missing_deps[@]} -gt 0 ]]; then
     log_error "Missing development packages: ${missing_deps[*]}"
     echo -e "\nPlease install them using:"
     if command -v apt &>/dev/null; then
-        log_warn "sudo apt install ${missing_deps[*]}"
+        log_warn "sudo apt install ${missing_deps[*]} gettext"
     elif command -v dnf &>/dev/null; then
-        log_warn "sudo dnf install gcc pkg-config dbus-devel bluez-libs-devel"
+        log_warn "sudo dnf install gcc pkg-config dbus-devel bluez-libs-devel gettext"
     elif command -v pacman &>/dev/null; then
-        log_warn "sudo pacman -S base-devel pkgconf dbus bluez-libs"
+        log_warn "sudo pacman -S base-devel pkgconf dbus bluez-libs gettext"
     fi
     exit 1
 fi
@@ -355,6 +355,23 @@ fi
 if [[ "$INSTALL_WIDGET" == "true" ]]; then
     log_step "Installing Plasma widget..."
     cd "$PROJECT_ROOT"
+    
+    # Compile translations if msgfmt is available
+    if command -v msgfmt &>/dev/null; then
+        log_step "Compiling translations..."
+        for po_file in plasmoid/contents/locale/*.po; do
+            if [[ -f "$po_file" ]]; then
+                lang=$(basename "$po_file" .po)
+                mkdir -p "plasmoid/contents/locale/$lang/LC_MESSAGES"
+                msgfmt -o "plasmoid/contents/locale/$lang/LC_MESSAGES/plasma_applet_org.kairpods.plasma.mo" "$po_file"
+                log_info "✓ Compiled translation for $lang"
+            fi
+        done
+    else
+        log_warn "msgfmt not found - translations will not be compiled"
+        log_warn "Install gettext package for translation support"
+    fi
+    
     kpackagetool6 --type Plasma/Applet --install plasmoid 2>/dev/null || \
         kpackagetool6 --type Plasma/Applet --upgrade plasmoid
     log_info "✓ Plasma widget installed"

can1357 avatar Jul 31 '25 21:07 can1357

Hi, thank you for looking into setting up translations! However, I'm afraid I can't help you as I'm just a translator, not a developer.

Vistaus avatar Aug 01 '25 08:08 Vistaus