Bug 33404 - static method [NSString localizedStringWithFormat:] is not bound in Xamarin iOS
Summary: static method [NSString localizedStringWithFormat:] is not bound in Xamarin iOS
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 8.10
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-08-26 16:36 UTC by Jon Goldberger [MSFT]
Modified: 2016-05-20 21:30 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test Project (2.76 MB, application/zip)
2015-08-26 16:36 UTC, Jon Goldberger [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Jon Goldberger [MSFT] 2015-08-26 16:36:22 UTC
Created attachment 12653 [details]
Test Project

## Description

I can not find any binding for [NSString localizedStringWithFormat:] which seems to be necessary to make localized pluralizations work with a .stringsdict file as outlined in Apple's docs:
https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/StringsdictFileFormat/StringsdictFileFormat.html
and in the "Handling Noun Plurals and Units of Measurement" section of this guide:
https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/LocalizingYourApp/LocalizingYourApp.html#//apple_ref/doc/uid/10000171i-CH5-SW1


I have attached a sample, taken from here:
https://github.com/conceptdev/xamarin-samples/tree/master/TaskyL10n

and added the .stringsdict file (which was present in the project folder in Finder but not in the project) and then tried to set the Title of the main page to use pluralizations but could not make this work and I believe this is due to the missing binding of  [NSString localizedStringWithFormat:]

In obj-C the code to use the pluralization would be:
localizedString = [NSString localizedStringWithFormat:NSLocalizedString(@"%d tasks left", @"Message shown for remaining tasks"), count];

In C# I am trying:
Title = MonoTouch.Foundation.NSBundle.MainBundle.LocalizedString ("%@ tasks left", "Message shown for remaining tasks");

which returns "%#@files@" which is the variable that [NSString localizedStringWithFormat:] should provide a value for and then ultimately return the proper pluralization based on the count value passed into [NSString localizedStringWithFormat:]

The reporting customer has done this many times in Obj-C without issue so is very familiar with the Obj-C API to handle pluralizations. 


## Steps to reproduce.

1. Open or create an iOS project. 

2. Look for NSString.LocalizedStringWithFormat

Expected result: Will find static method.

Actual resultL Can not find static method. 

## Note

See the attached sample for how I have set this up so far... the missing piece seems to be the static method noted above. I tried using String.Format instead, and swapping the %@ for {0} in the Localizable.strings and Localizable.stringsdict files but the problem is that the full formatting string is not returned from MainBundle.LocalizedString but rather only the variable string, %#@files@, is returned. My assumption is that [NSString localizedStringWithFormat:] method would take the count parameter and assign it to the "files" variable which would then be used in the ultimately desired formatting string, which would return proper pluralization based on the value of "files". 


## My environment

=== Xamarin Studio ===

Version 5.9.5 (build 10)
Installation UUID: 8605304c-f21a-4681-be62-702235faa3de
Runtime:
	Mono 4.0.3 ((detached/d6946b4)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400030020

=== Apple Developer Tools ===

Xcode 6.4 (7720)
Build 6E35b

=== Xamarin.iOS ===

Version: 8.10.4.46 (Business Edition)
Hash: 2c66d2f
Branch: master
Build date: 2015-08-04 13:52:25-0400

=== Xamarin.Android ===

Version: 5.1.5.3 (Business Edition)
Android SDK: /Users/apple/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
Java SDK: /usr
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.0.2.111 (Business Edition)

=== Build Information ===

Release ID: 509050010
Git revision: 48d16bc4f12ce3938964fc7c3d72fdc6887ad4ad
Build date: 2015-08-18 16:55:24-04
Xamarin addins: c2d51b360ad9f59e689046d47030df27de28f94a

=== Operating System ===

Mac OS X 10.10.5
Darwin Jons-iMac.local 14.5.0 Darwin Kernel Version 14.5.0
    Wed Jul 29 02:26:53 PDT 2015
    root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
Comment 1 Jon Davis 2015-09-08 17:24:47 UTC
In the meantime, here is a workaround for this missing binding:
https://gist.github.com/jon-davis-xamarin/ba9523272432dc79caff
Comment 2 Miguel de Icaza [MSFT] 2015-09-11 15:32:48 UTC
Implemented NSString.LocalizedFormat () method.
Comment 3 Jon Goldberger [MSFT] 2016-05-19 00:44:47 UTC
I am re-opening this bug as I still do not see the staic method in XI on latest stable version. 

Version info:

=== Xamarin Studio Enterprise ===

Version 5.10.3 (build 51)
Installation UUID: ceaba76c-db06-4fbd-b326-f69ea53c3e01
Runtime:
	Mono 4.2.4 (explicit/71b88f3)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402040004

=== Xamarin.Profiler ===

Not Installed

=== Xamarin.Android ===

Version: 6.0.4.0 (Visual Studio Enterprise)
Android SDK: /Users/jongoldberger/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)
		6.0   (API level 23)

SDK Tools Version: 25.1.3
SDK Platform Tools Version: 23.1
SDK Build Tools Version: 23.0.3

Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

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

=== Xamarin Android Player ===

Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

=== Apple Developer Tools ===

Xcode 7.3.1 (10188.1)
Build 7D1014

=== Xamarin.Mac ===

Version: 2.4.2.3 (Visual Studio Enterprise)

=== Xamarin.iOS ===

Version: 9.6.2.4 (Visual Studio Enterprise)
Hash: d8bedd0
Branch: master
Build date: 2016-05-05 17:43:01-0400

=== Build Information ===

Release ID: 510030051
Git revision: f3c0d982165f785772d125f02668370d929014fb
Build date: 2016-03-24 18:51:31-04
Xamarin addins: ee5cfd3ecb6b20de47c1d25efb9a9abc101e8ce7
Build lane: monodevelop-lion-cycle6-c6sr3

=== Operating System ===

Mac OS X 10.11.5
Darwin Jons-MacBook-Pro.local 15.5.0 Darwin Kernel Version 15.5.0
    Tue Apr 19 18:36:36 PDT 2016
    root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64
Comment 4 Jon Goldberger [MSFT] 2016-05-20 21:30:16 UTC
OK, I am resolving this again as it appears it is in the Beta channel XI 9.8.0.318