xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.48k stars 514 forks source link

NSString.GetLocalizedUserNotificationString not working with .stringsdict files #4694

Closed bradumbaugh closed 6 years ago

bradumbaugh commented 6 years ago

Steps to Reproduce

Sample project (includes both Swift and Xamarin versions):

NotificationSummaryPluralization.zip

  1. See attached samples: Swift version, and line-by-line Xamarin port
  2. Each sample sends 11 local notifications; 9 in one thread, 2 in another
  3. The notifications belong to a category that has a custom summary (text in lower left of the notification group that summarizes the whole group), defined in a .stringsdict file
  4. On the Swift version of the sample, the summary text shows up and pluralizes correctly based on the stringsdict file
  5. On the Xamarin version, the summary text shows a variable from the stringsdict file

I’m wondering if – based on https://bugzilla.xamarin.com/show_bug.cgi?id=41292 / https://github.com/xamarin/xamarin-macios/pull/3266NSString.GetLocalizedUserNotificationString should also return an NSString instead of a string?

NOTE: According to this Apple doc, GetLocalizedUserNotificationString should also be used to localize the notification content itself.

Expected Behavior

Actual Behavior

Environment

=== Visual Studio Enterprise 2017 for Mac ===

Version 7.5.4 (build 7) Installation UUID: 623d8c09-02dc-4241-ad34-5c29ea2d12f7 Runtime: Mono 5.10.1.57 (2017-12/ea8a24b1bbf) (64-bit) GTK+ 2.24.23 (Raleigh theme) Xamarin.Mac 4.4.1.193 (master / 64fece5f)

Package version: 510010057

=== NuGet ===

Version: 4.3.1.4445

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 2.1.2 2.1.1 2.0.5 2.0.3 SDK: /usr/local/share/dotnet/sdk/2.1.302/Sdks SDK Versions: 2.1.302 2.1.301 2.1.4 2.0.3 MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.10.1/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.3 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 10.0 (14320.2.4) Build 10L221o

=== Xamarin.Mac ===

Version: 4.99.2.250 (Visual Studio Enterprise)

=== Xamarin.iOS ===

Version: 11.99.2.130 (Visual Studio Enterprise) Hash: 86e97b10 Branch: HEAD Build date: 2018-08-04 01:01:50-0400

=== Xamarin.Android ===

Version: 9.0.0.18 (Visual Studio Enterprise) Android SDK: /Users/bradumbaugh/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 2.3 (API level 10) 4.0.3 (API level 15) 4.2 (API level 17) 4.4 (API level 19) 5.0 (API level 21) 6.0 (API level 23) 7.0 (API level 24) 7.1 (API level 25) 8.1 (API level 27)

SDK Tools Version: 26.1.1 SDK Platform Tools Version: 28.0.0 SDK Build Tools Version: 28.0.0

Java SDK: /usr java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Inspector ===

Version: 1.4.0 Hash: b3f92f9 Branch: master Build date: Fri, 19 Jan 2018 22:00:34 GMT Client compatibility: 1

=== Build Information ===

Release ID: 705040007 Git revision: 1fcae95fd5b606f806c3b1d445237f675c395fdd Build date: 2018-08-02 18:48:50+00 Xamarin addins: 48a82b251ec0ef78cb92223061ea448f967f4ec2

=== Operating System ===

Mac OS X 10.13.6 Darwin 17.7.0 Darwin Kernel Version 17.7.0 Thu Jun 21 22:53:14 PDT 2018 root:xnu-4570.71.2~1/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

MonoGame Extension 3.7.0.1 Vim 0.61.0 Internet of Things (IoT) development (Preview) 7.5.3

Example Project (If Possible)

NotificationSummaryPluralization.zip

VincentDondain commented 6 years ago

Confirmed, trying a quick fix.

VincentDondain commented 6 years ago

Fixed in https://github.com/xamarin/xamarin-macios/pull/4697.

lbulegato commented 3 years ago

@VincentDondain

Hi I am sorry but it seems that this bug is still not fixed in the following environment: You could easily try with the sample project attached to the top of this thread.

=== Visual Studio Community 2019 for Mac ===

Version 8.7.8 (build 4) Installation UUID: c009ff4a-74b5-4f90-8216-2a745d9b2fb3 GTK+ 2.24.23 (Raleigh theme) Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

Package version: 612000093

=== Mono Framework MDK ===

Runtime: Mono 6.12.0.93 (2020-02/620cf538206) (64-bit) Package version: 612000093

=== Roslyn (Language Service) ===

3.7.0-6.20427.1+18ede13943b0bfae1b44ef078b2f3923159bcd32

=== NuGet ===

Version: 5.7.0.6702

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/3.1.402/Sdks SDK Versions: 3.1.402 3.1.401 3.1.301 3.1.100 3.0.100 MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 3.1.8 3.1.7 3.1.5 3.1.0 3.0.0 2.1.22 2.1.21 2.1.19 2.1.14 2.1.13

=== Xamarin.Profiler ===

Version: 1.6.12.29 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Xamarin.Android ===

Version: 11.0.2.0 (Visual Studio Community) Commit: xamarin-android/d16-7/025fde9 Android SDK: /Users/bule/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 5.1 (API level 22) 7.0 (API level 24) 8.1 (API level 27)

SDK Tools Version: 26.1.1 SDK Platform Tools Version: 30.0.4 SDK Build Tools Version: 29.0.2

Build Information: Mono: 83105ba Java.Interop: xamarin/java.interop/d16-7@1f3388a ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000 SQLite: xamarin/sqlite/3.32.1@1a3276b Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-7@017078f

=== Microsoft OpenJDK for Mobile ===

Java SDK: /Users/bule/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25 1.8.0-25 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.7.0.13 Hash: 8380518 Branch: remotes/origin/d16-7~2 Build date: 2020-09-16 05:12:24 UTC

=== Android Device Manager ===

Version: 16.7.0.24 Hash: bb090a3 Branch: remotes/origin/d16-7 Build date: 2020-09-16 05:12:46 UTC

=== Xamarin Designer ===

Version: 16.7.0.495 Hash: 03d50a221 Branch: remotes/origin/d16-7-vsmac Build date: 2020-08-28 13:12:52 UTC

=== Apple Developer Tools ===

Xcode 12.1 (17222) Build 12A7403

=== Xamarin.Mac ===

Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.

=== Xamarin.iOS ===

Version: 14.0.0.0 (Visual Studio Community) Hash: 7ec3751a1 Branch: xcode12 Build date: 2020-09-16 11:33:15-0400

=== Build Information ===

Release ID: 807080004 Git revision: 9ea7bef96d65cdc3f4288014a799026ccb1993bc Build date: 2020-09-16 17:22:54-04 Build branch: release-8.7 Xamarin extensions: 9ea7bef96d65cdc3f4288014a799026ccb1993bc

=== Operating System ===

Mac OS X 10.15.7 Darwin 19.6.0 Darwin Kernel Version 19.6.0 Mon Aug 31 22:12:52 PDT 2020 root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64

VincentDondain commented 3 years ago

cc @dalexsoto

lbulegato commented 3 years ago

You can make it works only if use the following format, using @ as NSStringFormatValueTypeKey

<key>imagesAdded</key>
        <dict>
            <key>NSStringLocalizedFormatKey</key>
            <string>%#@format@</string>
            <key>format</key>
            <dict>
                <key>NSStringFormatSpecTypeKey</key>
                <string>NSStringPluralRuleType</string>
                <key>NSStringFormatValueTypeKey</key>
                <string>@</string>
                <key>one</key>
                <string>%@ Image Added</string>
                <key>other</key>
                <string>%@ Images Added</string>
            </dict>
        </dict>