From 22cae20707c7dd460c4f7db8009b51589af10955 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Tue, 22 Sep 2026 15:28:52 +0800 Subject: [PATCH] refactor: use metaglot to take desktop file i18n over --- CMakeLists.txt | 17 +++++++++-- dist/net.blumia.pineapple-pictures.desktop | 16 ---------- ...t.blumia.pineapple-pictures.desktop.liquid | 18 ++++++++++++ ...net.blumia.pineapple-pictures.desktop.toml | 18 ++++++++++++ locales/desktop/desktop.pot | 29 +++++++++++++++++++ locales/desktop/ja.po | 24 +++++++++++++++ locales/desktop/zh_CN.po | 24 +++++++++++++++ 7 files changed, 128 insertions(+), 18 deletions(-) delete mode 100644 dist/net.blumia.pineapple-pictures.desktop create mode 100644 dist/net.blumia.pineapple-pictures.desktop.liquid create mode 100644 dist/net.blumia.pineapple-pictures.desktop.toml create mode 100644 locales/desktop/desktop.pot create mode 100644 locales/desktop/ja.po create mode 100644 locales/desktop/zh_CN.po diff --git a/CMakeLists.txt b/CMakeLists.txt index d622934..0005f10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -256,9 +256,22 @@ elseif (UNIX) RENAME net.blumia.pineapple-pictures.svg ) - # install shortcut + # generate and install desktop entry file + set (PPIC_DESKTOP_FILE ${CMAKE_CURRENT_BINARY_DIR}/net.blumia.pineapple-pictures.desktop) + execute_process ( + COMMAND ${UV_EXECUTABLE} tool run metaglot render desktop + --manifest ${CMAKE_SOURCE_DIR}/dist/net.blumia.pineapple-pictures.desktop.toml + --po ${CMAKE_SOURCE_DIR}/locales/desktop/*.po + --template ${CMAKE_SOURCE_DIR}/dist/net.blumia.pineapple-pictures.desktop.liquid + --output ${PPIC_DESKTOP_FILE} + RESULT_VARIABLE METAGLOT_DESKTOP_RESULT + ) + if (NOT METAGLOT_DESKTOP_RESULT EQUAL 0) + message (FATAL_ERROR "Failed to generate net.blumia.pineapple-pictures.desktop via MetaGlot (exit code: ${METAGLOT_DESKTOP_RESULT}). If it is not installed yet, run: uv tool install git+https://github.com/SarasasChipWorkshop/metaglot.git") + endif () + install ( - FILES dist/net.blumia.pineapple-pictures.desktop + FILES ${PPIC_DESKTOP_FILE} DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications" ) diff --git a/dist/net.blumia.pineapple-pictures.desktop b/dist/net.blumia.pineapple-pictures.desktop deleted file mode 100644 index 42c93a6..0000000 --- a/dist/net.blumia.pineapple-pictures.desktop +++ /dev/null @@ -1,16 +0,0 @@ -[Desktop Entry] -Categories=Graphics; -Comment=Pineapple Pictures is a lightweight image viewer -Comment[zh_CN]=菠萝看图是一个轻量级的图像查看器 -Exec=ppic %F -GenericName=Image Viewer -GenericName[zh_CN]=图像查看器 -GenericName[ja]=画像ビューアー -Icon=net.blumia.pineapple-pictures -Keywords=Picture;Image;Viewer;Jpg;Jpeg;Png; -MimeType=image/bmp;image/bmp24;image/jpg;image/jpe;image/jpeg;image/jpeg24;image/jng;image/pcd;image/pcx;image/png;image/tif;image/tiff;image/tiff24;image/dds;image/gif;image/sgi;image/j2k;image/jp2;image/pct;image/wdp;image/arw;image/icb;image/dng;image/vda;image/vst;image/svg;image/ptif;image/mef;image/xbm;image/svg+xml; -Name=Pineapple Pictures -Name[zh_CN]=菠萝看图 -StartupNotify=false -Type=Application -Terminal=false diff --git a/dist/net.blumia.pineapple-pictures.desktop.liquid b/dist/net.blumia.pineapple-pictures.desktop.liquid new file mode 100644 index 0000000..883d1f0 --- /dev/null +++ b/dist/net.blumia.pineapple-pictures.desktop.liquid @@ -0,0 +1,18 @@ +[Desktop Entry] +Type=Application +Name={{ default.strings.name | desktop_escape }} +GenericName={{ default.strings.generic_name | desktop_escape }} +Comment={{ default.strings.comment | desktop_escape }} +Exec=ppic %F +Icon=net.blumia.pineapple-pictures +Terminal=false +StartupNotify=false +Categories=Graphics; +MimeType=image/bmp;image/bmp24;image/jpg;image/jpe;image/jpeg;image/jpeg24;image/jng;image/pcd;image/pcx;image/png;image/tif;image/tiff;image/tiff24;image/dds;image/gif;image/sgi;image/j2k;image/jp2;image/pct;image/wdp;image/arw;image/icb;image/dng;image/vda;image/vst;image/svg;image/ptif;image/mef;image/xbm;image/svg+xml; +Keywords={{ default.strings.keywords | desktop_escape }} +{% for lang in languages %} +Name[{{ lang.locale }}]={{ lang.strings.name | desktop_escape }} +GenericName[{{ lang.locale }}]={{ lang.strings.generic_name | desktop_escape }} +Comment[{{ lang.locale }}]={{ lang.strings.comment | desktop_escape }} +Keywords[{{ lang.locale }}]={{ lang.strings.keywords | desktop_escape }} +{% endfor %} diff --git a/dist/net.blumia.pineapple-pictures.desktop.toml b/dist/net.blumia.pineapple-pictures.desktop.toml new file mode 100644 index 0000000..3da2b27 --- /dev/null +++ b/dist/net.blumia.pineapple-pictures.desktop.toml @@ -0,0 +1,18 @@ +version = 1 +source_language = "en" + +[strings.name] +msgid = "Pineapple Pictures" +comment = "Display name of the application." + +[strings.generic_name] +msgid = "Image Viewer" +comment = "Generic name describing the application category." + +[strings.comment] +msgid = "Pineapple Pictures is a lightweight image viewer" +comment = "Tooltip-like description of the application." + +[strings.keywords] +msgid = "Picture;Image;Viewer;Jpg;Jpeg;Png;" +comment = "Search keywords. Semicolon separated list; the trailing semicolon is required." diff --git a/locales/desktop/desktop.pot b/locales/desktop/desktop.pot new file mode 100644 index 0000000..f9721f0 --- /dev/null +++ b/locales/desktop/desktop.pot @@ -0,0 +1,29 @@ +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: MetaGlot/polib\n" + +#. Display name of the application. +msgid "Pineapple Pictures" +msgstr "" + +#. Generic name describing the application category. +msgid "Image Viewer" +msgstr "" + +#. Tooltip-like description of the application. +msgid "Pineapple Pictures is a lightweight image viewer" +msgstr "" + +#. Search keywords. Semicolon separated list; the trailing semicolon is +#. required. +msgid "Picture;Image;Viewer;Jpg;Jpeg;Png;" +msgstr "" diff --git a/locales/desktop/ja.po b/locales/desktop/ja.po new file mode 100644 index 0000000..77a48bf --- /dev/null +++ b/locales/desktop/ja.po @@ -0,0 +1,24 @@ +msgid "" +msgstr "" +"Project-Id-Version: pineapple-pictures\n" +"Language: ja\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#. Display name of the application. +msgid "Pineapple Pictures" +msgstr "" + +#. Generic name describing the application category. +msgid "Image Viewer" +msgstr "画像ビューアー" + +#. Tooltip-like description of the application. +msgid "Pineapple Pictures is a lightweight image viewer" +msgstr "" + +#. Search keywords. Semicolon separated list; the trailing semicolon is required. +msgid "Picture;Image;Viewer;Jpg;Jpeg;Png;" +msgstr "" diff --git a/locales/desktop/zh_CN.po b/locales/desktop/zh_CN.po new file mode 100644 index 0000000..6dc171e --- /dev/null +++ b/locales/desktop/zh_CN.po @@ -0,0 +1,24 @@ +msgid "" +msgstr "" +"Project-Id-Version: pineapple-pictures\n" +"Language: zh_CN\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#. Display name of the application. +msgid "Pineapple Pictures" +msgstr "菠萝看图" + +#. Generic name describing the application category. +msgid "Image Viewer" +msgstr "图像查看器" + +#. Tooltip-like description of the application. +msgid "Pineapple Pictures is a lightweight image viewer" +msgstr "菠萝看图是一个轻量级的图像查看器" + +#. Search keywords. Semicolon separated list; the trailing semicolon is required. +msgid "Picture;Image;Viewer;Jpg;Jpeg;Png;" +msgstr ""