Skip to content

Commit 6414e53

Browse files
committed
build: update translations tooling
1 parent c12c502 commit 6414e53

24 files changed

Lines changed: 4380 additions & 2104 deletions
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
6+
permissions:
7+
contents: write
8+
pull-requests: write
9+
checks: read
10+
statuses: read
11+
12+
# private repos
13+
# actions: read
14+
# repository-projects: read
15+
16+
name: i18n-extract-translations
17+
18+
jobs:
19+
i18n-extract-translations:
20+
runs-on: ubuntu-latest
21+
env:
22+
BRANCH: action-i18n-extract-translations
23+
TITLE: "ci: extract translations"
24+
BODY: This PR was created by GitHub Actions
25+
26+
steps:
27+
- uses: actions/checkout@v2
28+
29+
- name: Install gettext
30+
run: sudo apt-get install gettext
31+
32+
- name: Branch
33+
run: |
34+
git branch -D "${{ env.BRANCH }}" || true
35+
git checkout -b "${{ env.BRANCH }}"
36+
37+
- name: Extract translations
38+
run: ./bin/i18n extract
39+
40+
- name: Check if there are changes
41+
id: check_changes
42+
run: |
43+
git add .
44+
if git diff-index --quiet HEAD; then
45+
echo "No changes detected."
46+
echo "is_changed=false" >> $GITHUB_OUTPUT
47+
else
48+
echo "Changes detected."
49+
echo "is_changed=true" >> $GITHUB_OUTPUT
50+
fi
51+
52+
- name: Commit changes
53+
if: steps.check_changes.outputs.is_changed == 'true'
54+
run: |
55+
git config --global user.name "github-actions"
56+
git config --global user.email "github-actions@github.com"
57+
git add .
58+
git commit -m "${{ env.TITLE }}"
59+
git push origin "${{ env.BRANCH }}" -f
60+
61+
- name: Create Pull Request
62+
if: steps.check_changes.outputs.is_changed == 'true'
63+
env:
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
run: |
66+
PR_URL="$(gh pr list --head "${{ env.BRANCH }}" --state open --json url --jq .[].url)"
67+
if [[ -n "${PR_URL}" ]]; then
68+
echo "PR already exists -> ${PR_URL}"
69+
gh pr edit "${{ env.BRANCH }}" -t "${{ env.TITLE }}" -b "${{ env.BODY }}"
70+
else
71+
gh pr create -B main -H "${{ env.BRANCH }}" -t "${{ env.TITLE }}" -b "${{ env.BODY }}"
72+
fi
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Validate Translations
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "**/*.po"
7+
8+
jobs:
9+
compile-po:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Install gettext
15+
run: sudo apt-get install gettext
16+
17+
- name: Validate .po files
18+
run: |
19+
./bin/i18n compile

.github/workflows/merge-translations.yml

Lines changed: 0 additions & 76 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ build/
55

66
playground
77
*.mo
8+
*.tar.gz

CMakeLists.txt

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ set(KF6_MIN_VERSION "6.0.0")
99
set(KDE_COMPILERSETTINGS_LEVEL "5.85")
1010

1111
find_package(ECM ${KF6_MIN_VERSION} REQUIRED NO_MODULE)
12-
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
12+
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
13+
14+
include(KDEInstallDirs)
15+
include(KDECMakeSettings)
16+
17+
find_package(KF6 ${KF6_MIN_VERSION} REQUIRED COMPONENTS
18+
I18n
19+
)
1320

1421
# Get id and version from metadata
1522
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/package/metadata.json METADATA)
@@ -21,14 +28,29 @@ message("Version: ${CUR_VERSION}")
2128
if(INSTALL_WALLPAPER)
2229
find_package(Plasma ${PROJECT_DEP_VERSION} REQUIRED)
2330
plasma_install_package(package ${PLUGIN_ID} wallpapers)
31+
add_subdirectory(translate)
2432
endif()
2533

2634
if(PACKAGE_WALLPAPER)
27-
# generate wallpaper package
28-
set(WALLPAPER_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}-v${CUR_VERSION}.zip")
35+
# Translations
36+
# As of 6.5.5 translations of wallpapers from KDE Store are not picked up by Plasma
37+
# https://github.com/luisbocanegra/plasma-smart-video-wallpaper-reborn/issues/84
38+
# upstream report https://bugs.kde.org/show_bug.cgi?id=501400
39+
# But this is here for when they finally support that
40+
add_custom_target(translations ALL
41+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
42+
COMMAND ./bin/i18n compile
43+
COMMENT "Compiling translations"
44+
)
45+
46+
# wallpaper package
47+
set(PACKAGE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}-v${CUR_VERSION}.tar.gz")
2948
add_custom_target(wallpaper ALL
30-
COMMAND rm -rf "${WALLPAPER_FILE}"
31-
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_SOURCE_DIR}/package zip -r ${WALLPAPER_FILE} ./
32-
COMMENT "Generating ${WALLPAPER_FILE}"
49+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/package
50+
COMMAND rm -f "${PACKAGE_FILE}" || true
51+
COMMAND tar -cf "${PACKAGE_FILE}" --auto-compress .
52+
COMMENT "Generating ${PACKAGE_FILE}"
3353
)
54+
55+
add_dependencies(wallpaper translations)
3456
endif()

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ If you enjoy using the plugin consider sponsoring or donating so I can dedicate
2121

2222
[![GitHub Sponsors](https://img.shields.io/badge/Sponsors-%2329313C?logo=githubsponsors&style=for-the-badge)](https://github.com/sponsors/luisbocanegra)
2323
[![Ko-fi](https://img.shields.io/badge/Ko--fi-supporter?logo=ko-fi&logoColor=%23ffffff&color=%23467BEB&style=for-the-badge)](https://ko-fi.com/luisbocanegra)
24-
[!["Buy Me A Coffee"](https://img.shields.io/badge/Buy%20me%20a%20coffe-supporter?logo=buymeacoffee&logoColor=%23282828&color=%23FF803F&style=for-the-badge)](https://www.buymeacoffee.com/luisbocanegra)
24+
[!["Buy Me A Coffee"](https://img.shields.io/badge/Buy%20me%20a%20coffee-supporter?logo=buymeacoffee&logoColor=%23282828&color=%23FF803F&style=for-the-badge)](https://www.buymeacoffee.com/luisbocanegra)
2525
[![PayPal](https://img.shields.io/badge/PayPal-supporter?logo=paypal&logoColor=%23ffffff&color=%23003087&style=for-the-badge)](https://www.paypal.com/donate/?hosted_button_id=Y5TMH3Z4YZRDA)
2626
[![Patreon](https://img.shields.io/badge/Patreon-%23000000?logo=patreon&logoColor=%23ffffff&style=for-the-badge)](https://patreon.com/luisbocanegra?utm_medium=unknown&utm_source=join_link&utm_campaign=creatorshare_creator&utm_content=copyLink)
2727

2828
## Join our Discord / Matrix
2929

30-
Help/Support/Discussion about my projects and other Linux/KDE related topics
30+
Help/Support/Discussion about my projects
3131

3232
[![Discord](https://img.shields.io/badge/Discord-%235865F2.svg?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/ZqD75dzKTe)
3333
[![Discord](https://img.shields.io/badge/Matrix-%23121212.svg?style=for-the-badge&logo=matrix&logoColor=white)](https://matrix.to/#/#kde-plasma-smart-video-wallpaper-reborn:matrix.org)
@@ -217,8 +217,12 @@ then reboot or restart plasmashell `systemctl --user restart plasma-plasmashell.
217217
7. Run `lspci -k | grep -EA3 'VGA|3D|Display' > lspci.txt`
218218
8. Create a new [new issue](https://github.com/luisbocanegra/plasma-smart-video-wallpaper-reborn/issues/new) describing the problem and how to reproduce, and attach those files including wether running the **test.qml** also crashes or not.
219219

220+
### Contributing Translations
221+
222+
See [Translations](https://github.com/luisbocanegra/plasma-smart-video-wallpaper-reborn/blob/main/translate/README.md)
223+
220224
## Acknowledgements
221225

222226
- This project a rewrite based on [adhec/Smart Video Wallpaper](https://github.com/adhec/plasma_tweaks/tree/master/SmartVideoWallpaper) and [PeterTucker/smartER-video-wallpaper](https://github.com/PeterTucker/smartER-video-wallpaper) projects.
223-
- [Zren's kpac](https://github.com/Zren/plasma-applet-lib) to manage translations
227+
- [ccatterina's script](https://github.com/ccatterina) to manage translations
224228
- Brand icons from [Simple Icons](https://simpleicons.org)

bin/i18n

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/bin/bash
2+
set -e
3+
4+
CONTENT_DIR="package/contents"
5+
TRANSLATE_DIR="./translate"
6+
PACKAGE_NAME="luisbocanegra.smart.video.wallpaper.reborn"
7+
8+
# https://api.kde.org/frameworks/ki18n/html/prg_guide.html
9+
EXTOPTS=(
10+
"--from-code=UTF-8 --kde --c++ -ci18n"
11+
"-ki18n:1 -ki18nc:1c,2 -ki18np:1,2 -ki18ncp:1c,2,3"
12+
"-kki18n:1 -kki18nc:1c,2 -kki18np:1,2 -kki18ncp:1c,2,3"
13+
"-kkli18n:1 -kkli18nc:1c,2 -kkli18np:1,2 -kkli18ncp:1c,2,3"
14+
"-kI18N_NOOP:1 -kI18NC_NOOP:1c,2"
15+
"--package-name=$PACKAGE_NAME"
16+
)
17+
18+
extract() {
19+
find "$CONTENT_DIR" -name "*.qml" -print0 | sort -z | xargs -0 xgettext ${EXTOPTS[@]} --sort-by-file --output="$TRANSLATE_DIR/template.pot"
20+
for po in "$TRANSLATE_DIR"/*.po; do
21+
[ -f "$po" ] && msgmerge --quiet --update --backup=off "$po" "$TRANSLATE_DIR/template.pot"
22+
done
23+
24+
echo "✅ Extraction completed!"
25+
}
26+
27+
check() {
28+
if [ ! -f "$TRANSLATE_DIR/template.pot" ]; then
29+
echo "template.pot not found. Run extract first."
30+
exit 1
31+
fi
32+
33+
new_pot=$(mktemp)
34+
find "$CONTENT_DIR" -name "*.qml" -print0 | sort -z | xargs -0 xgettext ${EXTOPTS[@]} --sort-by-file --output="$new_pot"
35+
if ! diff <(grep -v '^"POT-Creation-Date' "$TRANSLATE_DIR/template.pot") <(grep -v '^"POT-Creation-Date' "$new_pot") > /dev/null; then
36+
echo "❌ template.pot is not up to date with the source files. You should run i18n extract."
37+
diff <(grep -v '^"POT-Creation-Date' "$TRANSLATE_DIR/template.pot") <(grep -v '^"POT-Creation-Date' "$new_pot")
38+
rm "$new_pot"
39+
exit 1
40+
fi
41+
echo "✅ template.pot is up to date with the source files."
42+
43+
rm "$new_pot"
44+
for po in "$TRANSLATE_DIR"/*.po; do
45+
if [ -f "$po" ]; then
46+
lang=$(basename "$po" .po)
47+
stats=$(msgfmt --statistics -o /dev/null "$po" 2>&1)
48+
untranslated=$(echo "$stats" | grep -o '[0-9]* untranslated' | cut -d' ' -f1)
49+
[ -z "$untranslated" ] && untranslated=0
50+
fuzzy=$(echo "$stats" | grep -o '[0-9]* fuzzy' | cut -d' ' -f1)
51+
[ -z "$fuzzy" ] && fuzzy=0
52+
53+
if [ "$untranslated" != "0" ] || [ "$fuzzy" != "0" ]; then
54+
echo "⚠️ $lang: $untranslated untranslated, $fuzzy fuzzy"
55+
else
56+
echo "$lang: complete"
57+
fi
58+
fi
59+
done
60+
}
61+
62+
compile() {
63+
for po in "$TRANSLATE_DIR"/*.po; do
64+
if [ -f "$po" ]; then
65+
lang=$(basename "$po" .po)
66+
mkdir -p "$CONTENT_DIR/locale/$lang/LC_MESSAGES"
67+
msgfmt "$po" -o "$CONTENT_DIR/locale/$lang/LC_MESSAGES/plasma_wallpaper_$PACKAGE_NAME.mo"
68+
echo "$lang: compiled"
69+
fi
70+
done
71+
}
72+
73+
init() {
74+
if [ -z "$LANG" ]; then
75+
echo "Usage: $0 init <lang>"
76+
exit 1
77+
fi
78+
if [ ! -f "$TRANSLATE_DIR/template.pot" ]; then
79+
echo "❌ template.pot not found. Run extract first."
80+
exit 1
81+
fi
82+
if [ -f "$TRANSLATE_DIR/$LANG.po" ]; then
83+
echo "⚠️ $LANG.po already exists"
84+
exit 1
85+
fi
86+
msginit --no-translator --input="$TRANSLATE_DIR/template.pot" --locale="$LANG" --output-file="$TRANSLATE_DIR/$LANG.po"
87+
echo "$LANG.po created"
88+
}
89+
90+
COMMAND="$1"
91+
LANG="$2"
92+
93+
if ! command -v xgettext >/dev/null 2>&1; then
94+
echo "❌ xgettext not found. Please install gettext."
95+
exit 1
96+
fi
97+
98+
case "$COMMAND" in
99+
extract) extract ;;
100+
check) check ;;
101+
compile) compile ;;
102+
init) init ;;
103+
*) echo "Usage: $0 {extract|check|compile|init} [lang]" ; exit 1 ;;
104+
esac
File renamed without changes.

package/metadata.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,10 @@
1616
"BugReportUrl": "https://github.com/luisbocanegra/plasma-smart-video-wallpaper-reborn/issues",
1717
"Category": "",
1818
"Description": "Wallpaper plugin to play videos on your desktop",
19-
"Description[el_GR]": "Πρόσθετο ταπετσαρίας για αναπαραγωγή βίντεο στην επιφάνεια εργασίας σας",
20-
"Description[nl]": "Een achtergrondplug-in voor het tonen van video's op je bureaublad",
21-
"Description[pt_BR]": "Plugin de papel de parede para reproduzir vídeos na sua área de trabalho",
2219
"Icon": "preferences-desktop-wallpaper",
2320
"Id": "luisbocanegra.smart.video.wallpaper.reborn",
2421
"License": "GPLv2+",
2522
"Name": "Smart Video Wallpaper Reborn",
26-
"Name[el_GR]": "Smart Video Wallpaper Reborn",
27-
"Name[es]": "Smart Video Wallpaper Reborn",
28-
"Name[nl]": "Slimme videoachtergrond - herboren",
2923
"Version": "2.9.0",
3024
"Website": "https://github.com/luisbocanegra/plasma-smart-video-wallpaper-reborn"
3125
},

0 commit comments

Comments
 (0)