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
This commit is contained in:
2026-09-24 16:05:20 +08:00
parent 9b67599979
commit 1cb4d55335
6 changed files with 151 additions and 27 deletions
+33 -4
View File
@@ -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)
+16 -23
View File
@@ -14,10 +14,8 @@
<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleLongVersionString</key>
<string>${MACOSX_BUNDLE_LONG_VERSION_STRING}</string>
<key>CFBundleName</key>
<string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
<string>{{ default.strings.app_name | xml_escape }}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
@@ -29,28 +27,23 @@
<key>CSResourcesFileMapped</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
<!-- FIXME: this list can't be automatically generated by Qt's CMake API, don't know why. -->
<string>MIT/Expat License - Copyright (C) 2026 Gary Wang</string>
<!--
CFBundleLocalizations is generated from the metadata localization languages (the metaglot
"langs" list), while this field by definition describes the application's language
availability. This deviation works around an upstream Qt bug: since the Qt 6.7.0 refactor,
the CMake function _qt_internal_store_languages_from_ts_files_in_targets loses the parsed
TS language codes (a missing list(APPEND)), so Qt's own CFBundleLocalizations generation
yields an empty list. Consistency between the metadata languages and the application
languages is maintained manually at release time.
TODO: drop this workaround and let Qt generate CFBundleLocalizations itself once the
upstream bug is fixed and the fix ships in the CI toolchain.
-->
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>ca</string>
<string>de</string>
<string>es</string>
<string>fr</string>
<string>id</string>
<string>it</string>
<string>ja</string>
<string>ko</string>
<string>nb_NO</string>
<string>nl</string>
<string>pa_PK</string>
<string>ru</string>
<string>si</string>
<string>ta</string>
<string>tr</string>
<string>uk</string>
<string>zh_CN</string>
{% for lang in langs %}
<string>{{ lang }}</string>
{% endfor %}
</array>
<key>CFBundleDocumentTypes</key>
<array>
+26
View File
@@ -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."
+8
View File
@@ -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 }}";
+36
View File
@@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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 ""
+32
View File
@@ -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 图像"