summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-04-20 15:18:38 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-06-02 15:12:06 +0200
commit1d3ae5f0e98f252214d20ce8561533891311a71f (patch)
treedf891c981e78bda57cbaccb6fa07e1f4cec2a55a /cmake
parent21000ede374e7efb616c27b26d4490cd65d6da3a (diff)
cmake: Add known translations to CFBundleLocalizations in Info.plist
For untranslated applications we set CFBundleAllowMixedLocalizations to true, so that the application's locale will not be limited to the development region "en". But once we have a set of known translations, added by qt_add_translations, we can turn these into CFBundleLocalizations, which lets macOS/iOS choose a best match between what the app supports and what the user preferences are. [ChangeLog][Internationalization] Translations added via qt_add_translations are now reflected as CFBundleLocalizations entries in the application's Info.plist file on Apple platforms. to disable this behavior, set QT_NO_SET_PLIST_LOCALIZATIONS. Change-Id: I3f7ae1a1884eaf269038fa8ee49dbe6cac855706 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtPublicAppleHelpers.cmake57
1 files changed, 57 insertions, 0 deletions
diff --git a/cmake/QtPublicAppleHelpers.cmake b/cmake/QtPublicAppleHelpers.cmake
index 4de23a00fe..0ae9f249cf 100644
--- a/cmake/QtPublicAppleHelpers.cmake
+++ b/cmake/QtPublicAppleHelpers.cmake
@@ -567,6 +567,62 @@ function(_qt_internal_copy_info_plist target)
set_target_properties("${target}" PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${info_plist_out}")
endfunction()
+function(_qt_internal_plist_buddy plist_file)
+ cmake_parse_arguments(PARSE_ARGV 1 arg
+ "" "OUTPUT_VARIABLE;ERROR_VARIABLE" "COMMANDS")
+ foreach(command ${arg_COMMANDS})
+ execute_process(COMMAND "/usr/libexec/PlistBuddy"
+ -c "${command}" "${plist_file}"
+ OUTPUT_VARIABLE plist_buddy_output
+ ERROR_VARIABLE plist_buddy_error)
+ string(STRIP "${plist_buddy_output}" plist_buddy_output)
+ if(arg_OUTPUT_VARIABLE)
+ list(APPEND ${arg_OUTPUT_VARIABLE} ${plist_buddy_output})
+ set(${arg_OUTPUT_VARIABLE} ${${arg_OUTPUT_VARIABLE}} PARENT_SCOPE)
+ endif()
+ if(arg_ERROR_VARIABLE)
+ list(APPEND ${arg_ERROR_VARIABLE} ${plist_buddy_error})
+ set(${arg_ERROR_VARIABLE} ${${arg_ERROR_VARIABLE}} PARENT_SCOPE)
+ endif()
+ if(plist_buddy_error)
+ return()
+ endif()
+ endforeach()
+endfunction()
+
+function(_qt_internal_set_apple_localizations target)
+ if(QT_NO_SET_PLIST_LOCALIZATIONS)
+ return()
+ endif()
+
+ get_target_property(supported_languages "${target}" _qt_apple_supported_languages)
+ if("${supported_languages}" STREQUAL "supported_languages-NOTFOUND")
+ return()
+ endif()
+ get_target_property(plist_file "${target}" MACOSX_BUNDLE_INFO_PLIST)
+ if (NOT plist_file)
+ return()
+ endif()
+
+ _qt_internal_plist_buddy("${plist_file}"
+ COMMANDS "print CFBundleLocalizations"
+ OUTPUT_VARIABLE existing_localizations
+ )
+ if(existing_localizations)
+ return()
+ endif()
+
+ list(TRANSFORM supported_languages PREPEND
+ "Add CFBundleLocalizations: string ")
+
+ _qt_internal_plist_buddy("${plist_file}"
+ COMMANDS
+ "Add CFBundleLocalizations array"
+ ${supported_languages}
+ "Delete CFBundleAllowMixedLocalizations"
+ )
+endfunction()
+
function(_qt_internal_set_ios_simulator_arch target)
if(CMAKE_XCODE_ATTRIBUTE_ARCHS
OR QT_NO_SET_XCODE_ARCHS)
@@ -597,6 +653,7 @@ function(_qt_internal_finalize_apple_app target)
# Shared between macOS and iOS apps
_qt_internal_copy_info_plist("${target}")
+ _qt_internal_set_apple_localizations("${target}")
# Only set the various properties if targeting the Xcode generator, otherwise the various
# Xcode tokens are embedded as-is instead of being dynamically evaluated.