From 1cb4d55335efcb035c614624481018c5954eac92 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Thu, 24 Sep 2026 16:05:20 +0800 Subject: [PATCH] refactor: use metaglot to take macos bundle i18n over - use metaglot for macos bundle i18n - set macos icon from PUBLIC to PRIVATE - remove CFBundleLongVersionString from Info.plist --- CMakeLists.txt | 37 ++++++++++++++++-- ...ndleInfo.plist.in => Info.plist.in.liquid} | 39 ++++++++----------- dist/Info.plist.in.toml | 26 +++++++++++++ dist/InfoPlist.strings.liquid | 8 ++++ locales/plist/plist.pot | 36 +++++++++++++++++ locales/plist/zh_CN.po | 32 +++++++++++++++ 6 files changed, 151 insertions(+), 27 deletions(-) rename dist/{MacOSXBundleInfo.plist.in => Info.plist.in.liquid} (78%) create mode 100644 dist/Info.plist.in.toml create mode 100644 dist/InfoPlist.strings.liquid create mode 100644 locales/plist/plist.pot create mode 100644 locales/plist/zh_CN.po diff --git a/CMakeLists.txt b/CMakeLists.txt index baded50..1ec3754 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -229,19 +229,48 @@ if (WIN32) WIN32_EXECUTABLE TRUE ) elseif (APPLE) + # Include icon to project set_source_files_properties(dist/sarasacw-picture.icns PROPERTIES MACOSX_PACKAGE_LOCATION "Resources" ) - target_sources(${EXE_NAME} PUBLIC dist/sarasacw-picture.icns) + target_sources(${EXE_NAME} PRIVATE dist/sarasacw-picture.icns) + + # Setup Info.plist related directory. + set (PPIC_PLIST_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/plist-metadata) + # Render Info.plist and its strings. + execute_process ( + COMMAND ${UV_EXECUTABLE} tool run metaglot render plist + --manifest ${CMAKE_SOURCE_DIR}/dist/Info.plist.in.toml + --po ${CMAKE_SOURCE_DIR}/locales/plist/*.po + --plist-template ${CMAKE_SOURCE_DIR}/dist/Info.plist.in.liquid + --strings-template ${CMAKE_SOURCE_DIR}/dist/InfoPlist.strings.liquid + --plist-path Info.plist.in + --strings-path "Resources/{{ lang }}.lproj/InfoPlist.strings" + --output ${PPIC_PLIST_OUTPUT_DIR} + RESULT_VARIABLE METAGLOT_PLIST_RESULT + ) + if (NOT METAGLOT_PLIST_RESULT EQUAL 0) + message (FATAL_ERROR "Failed to render Info.plist metadata via MetaGlot (exit code: ${METAGLOT_PLIST_RESULT}).") + endif () + # Include these to project. + file (GLOB PPIC_PLIST_STRINGS_FILES ${PPIC_PLIST_OUTPUT_DIR}/Resources/*.lproj/InfoPlist.strings) + foreach (plist_strings_file ${PPIC_PLIST_STRINGS_FILES}) + get_filename_component (plist_lproj_dir ${plist_strings_file} DIRECTORY) + get_filename_component (plist_lproj_name ${plist_lproj_dir} NAME) + set_source_files_properties (${plist_strings_file} PROPERTIES + MACOSX_PACKAGE_LOCATION "Resources/${plist_lproj_name}" + ) + target_sources (${EXE_NAME} PRIVATE ${plist_strings_file}) + endforeach () # See https://cmake.org/cmake/help/v3.15/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.html set_target_properties(${EXE_NAME} PROPERTIES MACOSX_BUNDLE TRUE - MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/dist/MacOSXBundleInfo.plist.in - MACOSX_BUNDLE_BUNDLE_NAME "Pineapple Pictures" + MACOSX_BUNDLE_INFO_PLIST ${PPIC_PLIST_OUTPUT_DIR}/Info.plist.in + MACOSX_BUNDLE_INFO_STRING "${PROJECT_VERSION}, Copyright (C) 2026 Gary Wang" MACOSX_BUNDLE_GUI_IDENTIFIER net.blumia.pineapple-pictures MACOSX_BUNDLE_ICON_FILE sarasacw-picture.icns # contains the .icns file name, *without* the path. MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} - MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} + MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} ) elseif (UNIX) if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) diff --git a/dist/MacOSXBundleInfo.plist.in b/dist/Info.plist.in.liquid similarity index 78% rename from dist/MacOSXBundleInfo.plist.in rename to dist/Info.plist.in.liquid index aa1e8f8..14da6f5 100644 --- a/dist/MacOSXBundleInfo.plist.in +++ b/dist/Info.plist.in.liquid @@ -14,10 +14,8 @@ ${MACOSX_BUNDLE_GUI_IDENTIFIER} CFBundleInfoDictionaryVersion 6.0 - CFBundleLongVersionString - ${MACOSX_BUNDLE_LONG_VERSION_STRING} CFBundleName - ${MACOSX_BUNDLE_BUNDLE_NAME} + {{ default.strings.app_name | xml_escape }} CFBundlePackageType APPL CFBundleShortVersionString @@ -29,28 +27,23 @@ CSResourcesFileMapped NSHumanReadableCopyright - ${MACOSX_BUNDLE_COPYRIGHT} - + MIT/Expat License - Copyright (C) 2026 Gary Wang + CFBundleLocalizations - en - ca - de - es - fr - id - it - ja - ko - nb_NO - nl - pa_PK - ru - si - ta - tr - uk - zh_CN +{% for lang in langs %} + {{ lang }} +{% endfor %} CFBundleDocumentTypes diff --git a/dist/Info.plist.in.toml b/dist/Info.plist.in.toml new file mode 100644 index 0000000..128d2a1 --- /dev/null +++ b/dist/Info.plist.in.toml @@ -0,0 +1,26 @@ +version = 1 +source_language = "en" + +[strings.app_name] +msgid = "Pineapple Pictures" +comment = "Display name of the application." + +[strings.file_type_jpeg] +msgid = "JPEG Image" +comment = "Name of the JPEG document type (jpg, jpeg, jfif)." + +[strings.file_type_png] +msgid = "PNG Image" +comment = "Name of the PNG document type." + +[strings.file_type_webp] +msgid = "WebP Image" +comment = "Name of the WebP document type." + +[strings.file_type_gif] +msgid = "GIF Image" +comment = "Name of the GIF document type." + +[strings.file_type_svg] +msgid = "SVG Image" +comment = "Name of the SVG document type." diff --git a/dist/InfoPlist.strings.liquid b/dist/InfoPlist.strings.liquid new file mode 100644 index 0000000..0138d3e --- /dev/null +++ b/dist/InfoPlist.strings.liquid @@ -0,0 +1,8 @@ +/* Application display name. The key is the Info.plist key name. */ +"CFBundleName" = "{{ strings.app_name | plist_strings_escape }}"; +/* File type names. The key is the source text, covering CFBundleTypeName. */ +"{{ sources.file_type_jpeg | plist_strings_escape }}" = "{{ strings.file_type_jpeg | plist_strings_escape }}"; +"{{ sources.file_type_png | plist_strings_escape }}" = "{{ strings.file_type_png | plist_strings_escape }}"; +"{{ sources.file_type_webp | plist_strings_escape }}" = "{{ strings.file_type_webp | plist_strings_escape }}"; +"{{ sources.file_type_gif | plist_strings_escape }}" = "{{ strings.file_type_gif | plist_strings_escape }}"; +"{{ sources.file_type_svg | plist_strings_escape }}" = "{{ strings.file_type_svg | plist_strings_escape }}"; diff --git a/locales/plist/plist.pot b/locales/plist/plist.pot new file mode 100644 index 0000000..6d9eed7 --- /dev/null +++ b/locales/plist/plist.pot @@ -0,0 +1,36 @@ +# +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 "" + +#. Name of the JPEG document type (jpg, jpeg, jfif). +msgid "JPEG Image" +msgstr "" + +#. Name of the PNG document type. +msgid "PNG Image" +msgstr "" + +#. Name of the WebP document type. +msgid "WebP Image" +msgstr "" + +#. Name of the GIF document type. +msgid "GIF Image" +msgstr "" + +#. Name of the SVG document type. +msgid "SVG Image" +msgstr "" diff --git a/locales/plist/zh_CN.po b/locales/plist/zh_CN.po new file mode 100644 index 0000000..372391d --- /dev/null +++ b/locales/plist/zh_CN.po @@ -0,0 +1,32 @@ +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 "菠萝看图" + +#. Name of the JPEG document type (jpg, jpeg, jfif). +msgid "JPEG Image" +msgstr "JPEG 图像" + +#. Name of the PNG document type. +msgid "PNG Image" +msgstr "PNG 图像" + +#. Name of the WebP document type. +msgid "WebP Image" +msgstr "WebP 图像" + +#. Name of the GIF document type. +msgid "GIF Image" +msgstr "GIF 图像" + +#. Name of the SVG document type. +msgid "SVG Image" +msgstr "SVG 图像"