diff --git a/readme.md b/readme.md
index 1ffae5b1c..1e5aa7447 100644
--- a/readme.md
+++ b/readme.md
@@ -157,6 +157,14 @@ This is an extension method based on `String.Format`, so exact rules applies to
If `format` is null, it'll throw `ArgumentNullException`.
If passed a fewer number for arguments, it'll throw `String.FormatException` exception.
+You also can specify the culture to use explicitly as the first parameter for the `FormatWith()` method:
+
+```c#
+"{0:N2}".FormatWith(new CultureInfo("ru-RU"), 6666.66) => "6 666,66"
+```
+
+If a culture is not specified, current thread's current culture is used.
+
###Humanize Enums
Calling `ToString` directly on enum members usually results in less than ideal output for users. The solution to this is usually to use `DescriptionAttribute` data annotation and then read that at runtime to get a more friendly output. That is a great solution; but more often than not we only need to put some space between words of an enum member - which is what `String.Humanize()` does well. For an enum like:
diff --git a/release_notes.md b/release_notes.md
index 0ca3b37e9..2d0ccf186 100644
--- a/release_notes.md
+++ b/release_notes.md
@@ -1,6 +1,7 @@
###In Development
- [#306](https://github.com/MehdiK/Humanizer/pull/306): Added Singularize/Pluralize overload without using obsolete plurality enum
- [#303](https://github.com/MehdiK/Humanizer/pull/303): Added support for all integer types in ByteSize extensions
+ - [#307](https://github.com/MehdiK/Humanizer/pull/307): string.FormatWith: added support for the explicit culture parameter.
[Commits](https://github.com/MehdiK/Humanizer/compare/v1.27.0...master)
diff --git a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt
index adcf751d7..145de1445 100644
--- a/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt
+++ b/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.approved.txt
@@ -443,6 +443,7 @@ public class StringDehumanizeExtensions
public class StringExentions
{
public string FormatWith(string format, object[] args) { }
+ public string FormatWith(string format, System.IFormatProvider provider, object[] args) { }
}
public class StringHumanizeExtensions
diff --git a/src/Humanizer.Tests/StringExtensionsTests.cs b/src/Humanizer.Tests/StringExtensionsTests.cs
index 811cb9205..101073dd3 100644
--- a/src/Humanizer.Tests/StringExtensionsTests.cs
+++ b/src/Humanizer.Tests/StringExtensionsTests.cs
@@ -1,5 +1,7 @@
using System;
+using System.Globalization;
using Xunit;
+using Xunit.Extensions;
namespace Humanizer.Tests
{
@@ -32,5 +34,13 @@ public void FormatCannotBeNull()
string format = null;
Assert.Throws(() => format.FormatWith(1, 2));
}
+
+ [Theory]
+ [InlineData("en-US", "6,666.66")]
+ [InlineData("ru-RU", "6 666,66")]
+ public void CanSpecifyCultureExplicitly(string culture, string expected)
+ {
+ Assert.Equal(expected, "{0:N2}".FormatWith(new CultureInfo(culture), 6666.66));
+ }
}
-}
+}
\ No newline at end of file
diff --git a/src/Humanizer/StringExentions.cs b/src/Humanizer/StringExentions.cs
index 9b557d7e5..7b119f4bd 100644
--- a/src/Humanizer/StringExentions.cs
+++ b/src/Humanizer/StringExentions.cs
@@ -8,7 +8,7 @@ namespace Humanizer
public static class StringExentions
{
///
- /// Extension method to format string with passed arguments
+ /// Extension method to format string with passed arguments. Current thread's current culture is used
///
/// string format
/// arguments
@@ -17,5 +17,17 @@ public static string FormatWith(this string format, params object[] args)
{
return String.Format(format, args);
}
+
+ ///
+ /// Extension method to format string with passed arguments using specified format provider (i.e. CultureInfo)
+ ///
+ /// string format
+ /// An object that supplies culture-specific formatting information
+ /// arguments
+ ///
+ public static string FormatWith(this string format, IFormatProvider provider, params object[] args)
+ {
+ return String.Format(provider, format, args);
+ }
}
}