5 | {
6 | public DateToOrdinalWordsConverterRegistry() : base(new DefaultDateToOrdinalWordConverter())
7 | {
8 | Register("en-UK", new DefaultDateToOrdinalWordConverter());
9 | Register("de", new DefaultDateToOrdinalWordConverter());
10 | Register("en-US", new UsDateToOrdinalWordsConverter());
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/Humanizer/GrammaticalGender.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer
2 | {
3 | ///
4 | /// Options for specifying the desired grammatical gender for the output words
5 | ///
6 | public enum GrammaticalGender
7 | {
8 | ///
9 | /// Indicates masculine grammatical gender
10 | ///
11 | Masculine,
12 | ///
13 | /// Indicates feminine grammatical gender
14 | ///
15 | Feminine,
16 | ///
17 | /// Indicates neuter grammatical gender
18 | ///
19 | Neuter
20 | }
21 | }
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/Ordinalizers/DutchOrdinalizer.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer.Localisation.Ordinalizers
2 | {
3 | internal class DutchOrdinalizer : DefaultOrdinalizer
4 | {
5 | public override string Convert(int number, string numberString)
6 | {
7 | return Convert(number, numberString, GrammaticalGender.Masculine);
8 | }
9 |
10 | public override string Convert(int number, string numberString, GrammaticalGender gender)
11 | {
12 | // N/A in Dutch
13 | if (number == 0)
14 | return "0";
15 |
16 | return numberString + "e";
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Shared/Localisation/DefaultFormatterTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using Humanizer.Localisation;
4 | using Humanizer.Localisation.Formatters;
5 | using Xunit;
6 |
7 | namespace Humanizer.Tests.Localisation
8 | {
9 | public class DefaultFormatterTests
10 | {
11 |
12 | [Fact]
13 | [UseCulture("es")]
14 | public void HandlesNotImplementedCollectionFormattersGracefully()
15 | {
16 | var a = new[] {DateTime.UtcNow, DateTime.UtcNow.AddDays(10)};
17 | var b = a.Humanize();
18 |
19 | Assert.Equal(a[0] + " & " + a[1], b);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Shared/Localisation/en/DateToOrdinalWordsTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xunit;
3 |
4 | namespace Humanizer.Tests.Localisation.en
5 | {
6 | public class DateToOrdinalWordsTests
7 | {
8 | [UseCulture("en-GB")]
9 | [Fact]
10 | public void OrdinalizeStringGb()
11 | {
12 | Assert.Equal("1st January 2015", new DateTime(2015, 1, 1).ToOrdinalWords());
13 | }
14 |
15 | [UseCulture("en-US")]
16 | [Fact]
17 | public void OrdinalizeStringUs()
18 | {
19 | Assert.Equal("January 1st, 2015", new DateTime(2015, 1, 1).ToOrdinalWords());
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeHumanizeStrategy.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 |
4 | namespace Humanizer.DateTimeHumanizeStrategy
5 | {
6 | ///
7 | /// Implement this interface to create a new strategy for DateTime.Humanize and hook it in the Configurator.DateTimeHumanizeStrategy
8 | ///
9 | public interface IDateTimeHumanizeStrategy
10 | {
11 | ///
12 | /// Calculates the distance of time in words between two provided dates used for DateTime.Humanize
13 | ///
14 | string Humanize(DateTime input, DateTime comparisonBase, CultureInfo culture);
15 | }
16 | }
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/Formatters/CzechSlovakPolishFormatter.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer.Localisation.Formatters
2 | {
3 | internal class CzechSlovakPolishFormatter : DefaultFormatter
4 | {
5 | private const string PaucalPostfix = "_Paucal";
6 |
7 | public CzechSlovakPolishFormatter(string localeCode)
8 | : base(localeCode)
9 | {
10 | }
11 |
12 | protected override string GetResourceKey(string resourceKey, int number)
13 | {
14 | if (number > 1 && number < 5)
15 | return resourceKey + PaucalPostfix;
16 |
17 | return resourceKey;
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/Formatters/SerbianFormatter.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer.Localisation.Formatters
2 | {
3 | internal class SerbianFormatter : DefaultFormatter
4 | {
5 | private const string PaucalPostfix = "_Paucal";
6 |
7 | public SerbianFormatter(string localeCode)
8 | : base(localeCode)
9 | {
10 | }
11 |
12 | protected override string GetResourceKey(string resourceKey, int number)
13 | {
14 | var mod10 = number % 10;
15 |
16 | if (mod10 > 1 && mod10 < 5)
17 | return resourceKey + PaucalPostfix;
18 |
19 | return resourceKey;
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Humanizer/DateTimeHumanizeStrategy/IDateTimeOffsetHumanizeStrategy.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 |
4 | namespace Humanizer.DateTimeHumanizeStrategy
5 | {
6 | ///
7 | /// Implement this interface to create a new strategy for DateTime.Humanize and hook it in the Configurator.DateTimeOffsetHumanizeStrategy
8 | ///
9 | public interface IDateTimeOffsetHumanizeStrategy
10 | {
11 | ///
12 | /// Calculates the distance of time in words between two provided dates used for DateTimeOffset.Humanize
13 | ///
14 | string Humanize(DateTimeOffset input, DateTimeOffset comparisonBase, CultureInfo culture);
15 | }
16 | }
--------------------------------------------------------------------------------
/src/Humanizer/LetterCasing.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer
2 | {
3 | ///
4 | /// Options for specifying the desired letter casing for the output string
5 | ///
6 | public enum LetterCasing
7 | {
8 | ///
9 | /// SomeString -> Some String
10 | ///
11 | Title,
12 | ///
13 | /// SomeString -> SOME STRING
14 | ///
15 | AllCaps,
16 | ///
17 | /// SomeString -> some string
18 | ///
19 | LowerCase,
20 | ///
21 | /// SomeString -> Some string
22 | ///
23 | Sentence,
24 | }
25 | }
--------------------------------------------------------------------------------
/samples/Humanizer.MvcSample/Views/Shared/_LoginPartial.cshtml:
--------------------------------------------------------------------------------
1 | @if (Request.IsAuthenticated) {
2 |
3 | Hello, @Html.ActionLink(User.Identity.Name, "ChangePassword", "Account", routeValues: null, htmlAttributes: new { @class = "username", title = "Change password" })!
4 | @Html.ActionLink("Log off", "LogOff", "Account")
5 |
6 | } else {
7 |
8 | - @Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink", data_dialog_title = "Registration" })
9 | - @Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink", data_dialog_title = "Identification" })
10 |
11 | }
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/Formatters/CroatianFormatter.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer.Localisation.Formatters
2 | {
3 | internal class CroatianFormatter : DefaultFormatter
4 | {
5 | private const string DualTrialQuadralPostfix = "_DualTrialQuadral";
6 |
7 | public CroatianFormatter()
8 | : base("hr")
9 | {
10 | }
11 |
12 | protected override string GetResourceKey(string resourceKey, int number)
13 | {
14 | if ((number % 10 == 2 || number % 10 == 3 || number % 10 == 4) && number != 12 && number != 13 && number != 14)
15 | return resourceKey + DualTrialQuadralPostfix;
16 |
17 | return resourceKey;
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/samples/Humanizer.MvcSample/Content/themes/base/jquery.ui.all.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Note: While Microsoft is not the author of this file, Microsoft is
3 | * offering you a license subject to the terms of the Microsoft Software
4 | * License Terms for Microsoft ASP.NET Model View Controller 4 Developer Preview.
5 | * Microsoft reserves all other rights. The notices below are provided
6 | * for informational purposes only and are not the license terms under
7 | * which Microsoft distributed this file.
8 | *
9 | * jQuery UI CSS Framework 1.8.11
10 | *
11 | * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
12 | *
13 | * http://docs.jquery.com/UI/Theming
14 | */
15 | @import "jquery.ui.base.css";
16 | @import "jquery.ui.theme.css";
17 |
--------------------------------------------------------------------------------
/src/Humanizer/NoMatchFoundException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Humanizer
4 | {
5 | ///
6 | /// This is thrown on String.DehumanizeTo enum when the provided string cannot be mapped to the target enum
7 | ///
8 | #pragma warning disable 1591
9 | public class NoMatchFoundException : Exception
10 | {
11 | public NoMatchFoundException()
12 | {
13 | }
14 |
15 | public NoMatchFoundException(string message)
16 | : base(message)
17 | {
18 | }
19 |
20 | public NoMatchFoundException(string message, Exception inner)
21 | : base(message, inner)
22 | {
23 | }
24 | }
25 | #pragma warning restore 1591
26 | }
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Shared/FluentDate/OnTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xunit;
3 |
4 | namespace Humanizer.Tests.FluentDate
5 | {
6 | public class OnTests
7 | {
8 | [Fact]
9 | public void OnJanuaryThe23rd()
10 | {
11 | Assert.Equal(new DateTime(DateTime.Now.Year, 1, 23), On.January.The23rd);
12 | }
13 |
14 | [Fact]
15 | public void OnDecemberThe4th()
16 | {
17 | Assert.Equal(new DateTime(DateTime.Now.Year, 12, 4), On.December.The4th);
18 | }
19 |
20 | [Fact]
21 | public void OnFebruaryThe()
22 | {
23 | Assert.Equal(new DateTime(DateTime.Now.Year, 2, 11), On.February.The(11));
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeHumanizeStrategy.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 |
4 | namespace Humanizer.DateTimeHumanizeStrategy
5 | {
6 | ///
7 | /// The default 'distance of time' -> words calculator.
8 | ///
9 | public class DefaultDateTimeHumanizeStrategy : IDateTimeHumanizeStrategy
10 | {
11 | ///
12 | /// Calculates the distance of time in words between two provided dates
13 | ///
14 | public string Humanize(DateTime input, DateTime comparisonBase, CultureInfo culture)
15 | {
16 | return DateTimeHumanizeAlgorithms.DefaultHumanize(input, comparisonBase, culture);
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # editorconfig.org
2 |
3 | # top-most EditorConfig file
4 | root = true
5 |
6 | # Default settings:
7 | # A newline ending every file
8 | # Use 4 spaces as indentation
9 | [*]
10 | insert_final_newline = true
11 | indent_style = space
12 | indent_size = 4
13 |
14 | # C++ Files
15 | [*.{cpp,h,in}]
16 | curly_bracket_next_line = true
17 | indent_brace_style = Allman
18 |
19 | # Xml project files
20 | [*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}]
21 | indent_size = 2
22 |
23 | # Xml files
24 | [*.{xml,stylecop,resx,ruleset}]
25 | indent_size = 2
26 |
27 | # Xml config files
28 | [*.{props,targets,config,nuspec}]
29 | indent_size = 2
30 |
31 | # Shell scripts
32 | [*.sh]
33 | end_of_line = lf
34 | [*.{cmd, bat}]
35 | end_of_line = crlf
36 |
37 |
--------------------------------------------------------------------------------
/samples/Humanizer.MvcSample/Content/themes/base/jquery.ui.selectable.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Note: While Microsoft is not the author of this file, Microsoft is
3 | * offering you a license subject to the terms of the Microsoft Software
4 | * License Terms for Microsoft ASP.NET Model View Controller 4 Developer Preview.
5 | * Microsoft reserves all other rights. The notices below are provided
6 | * for informational purposes only and are not the license terms under
7 | * which Microsoft distributed this file.
8 | *
9 | * jQuery UI Selectable 1.8.11
10 | *
11 | * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
12 | *
13 | * http://docs.jquery.com/UI/Selectable#theming
14 | */
15 | .ui-selectable-helper { position: absolute; z-index: 100; border:1px dotted black; }
16 |
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/Ordinalizers/PortugueseOrdinalizer.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer.Localisation.Ordinalizers
2 | {
3 | internal class PortugueseOrdinalizer : DefaultOrdinalizer
4 | {
5 | public override string Convert(int number, string numberString)
6 | {
7 | return Convert(number, numberString, GrammaticalGender.Masculine);
8 | }
9 |
10 | public override string Convert(int number, string numberString, GrammaticalGender gender)
11 | {
12 | // N/A in Portuguese
13 | if (number == 0)
14 | return "0";
15 |
16 | if (gender == GrammaticalGender.Feminine)
17 | return numberString + "ª";
18 |
19 | return numberString + "º";
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/samples/Humanizer.MvcSample/Content/themes/base/jquery.ui.progressbar.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Note: While Microsoft is not the author of this file, Microsoft is
3 | * offering you a license subject to the terms of the Microsoft Software
4 | * License Terms for Microsoft ASP.NET Model View Controller 4 Developer Preview.
5 | * Microsoft reserves all other rights. The notices below are provided
6 | * for informational purposes only and are not the license terms under
7 | * which Microsoft distributed this file.
8 | *
9 | * jQuery UI Progressbar 1.8.11
10 | *
11 | * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
12 | *
13 | * http://docs.jquery.com/UI/Progressbar#theming
14 | */
15 | .ui-progressbar { height:2em; text-align: left; }
16 | .ui-progressbar .ui-progressbar-value {margin: -1px; height:100%; }
--------------------------------------------------------------------------------
/src/Humanizer/DateTimeHumanizeStrategy/DefaultDateTimeOffsetHumanizeStrategy.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 |
4 | namespace Humanizer.DateTimeHumanizeStrategy
5 | {
6 | ///
7 | /// The default 'distance of time' -> words calculator.
8 | ///
9 | public class DefaultDateTimeOffsetHumanizeStrategy : IDateTimeOffsetHumanizeStrategy
10 | {
11 | ///
12 | /// Calculates the distance of time in words between two provided dates
13 | ///
14 | public string Humanize(DateTimeOffset input, DateTimeOffset comparisonBase, CultureInfo culture)
15 | {
16 | return DateTimeHumanizeAlgorithms.DefaultHumanize(input.UtcDateTime, comparisonBase.UtcDateTime, culture);
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/Ordinalizers/RussianOrdinalizer.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer.Localisation.Ordinalizers
2 | {
3 | internal class RussianOrdinalizer : DefaultOrdinalizer
4 | {
5 | public override string Convert(int number, string numberString)
6 | {
7 | return Convert(number, numberString, GrammaticalGender.Masculine);
8 | }
9 |
10 | public override string Convert(int number, string numberString, GrammaticalGender gender)
11 | {
12 | if (gender == GrammaticalGender.Masculine)
13 | return numberString + "-й";
14 |
15 | if (gender == GrammaticalGender.Feminine)
16 | return numberString + "-я";
17 |
18 | return numberString + "-е";
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/Ordinalizers/ItalianOrdinalizer.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer.Localisation.Ordinalizers
2 | {
3 | internal class ItalianOrdinalizer : DefaultOrdinalizer
4 | {
5 | public override string Convert(int number, string numberString)
6 | {
7 | return Convert(number, numberString, GrammaticalGender.Masculine);
8 | }
9 |
10 | public override string Convert(int number, string numberString, GrammaticalGender gender)
11 | {
12 | // No ordinal for 0 in italian (neologism apart)
13 | if (number == 0)
14 | return "0";
15 |
16 | if (gender == GrammaticalGender.Feminine)
17 | return numberString + "ª";
18 |
19 | return numberString + "°";
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/Ordinalizers/SpanishOrdinalizer.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer.Localisation.Ordinalizers
2 | {
3 | internal class SpanishOrdinalizer : DefaultOrdinalizer
4 | {
5 | public override string Convert(int number, string numberString)
6 | {
7 | return Convert(number, numberString, GrammaticalGender.Masculine);
8 | }
9 |
10 | public override string Convert(int number, string numberString, GrammaticalGender gender)
11 | {
12 | // N/A in Spanish
13 | if (number == 0)
14 | return "0";
15 |
16 | if (gender == GrammaticalGender.Feminine)
17 | return numberString + ".ª";
18 | else
19 | return numberString + ".º";
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/src/Humanizer/Truncation/ITruncator.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer
2 | {
3 | ///
4 | /// Can truncate a string.
5 | ///
6 | public interface ITruncator
7 | {
8 | ///
9 | /// Truncate a string
10 | ///
11 | /// The string to truncate
12 | /// The length to truncate to
13 | /// The string used to truncate with
14 | /// The enum value used to determine from where to truncate the string
15 | /// The truncated string
16 | string Truncate(string value, int length, string truncationString, TruncateFrom truncateFrom = TruncateFrom.Right);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Humanizer/StringDehumanizeExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 |
3 | namespace Humanizer
4 | {
5 | ///
6 | /// Contains extension methods for dehumanizing strings.
7 | ///
8 | public static class StringDehumanizeExtensions
9 | {
10 | ///
11 | /// Dehumanizes a string; e.g. 'some string', 'Some String', 'Some string' -> 'SomeString'
12 | ///
13 | /// The string to be dehumanized
14 | ///
15 | public static string Dehumanize(this string input)
16 | {
17 | var titlizedWords = input.Split(' ').Select(word => word.Humanize(LetterCasing.Title));
18 | return string.Join("", titlizedWords).Replace(" ", "");
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/GrammaticalNumber/RussianGrammaticalNumberDetector.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer.Localisation.GrammaticalNumber
2 | {
3 | internal static class RussianGrammaticalNumberDetector
4 | {
5 | public static RussianGrammaticalNumber Detect(int number)
6 | {
7 | var tens = number % 100 / 10;
8 | if (tens != 1)
9 | {
10 | var unity = number % 10;
11 |
12 | if (unity == 1) // 1, 21, 31, 41 ... 91, 101, 121 ...
13 | return RussianGrammaticalNumber.Singular;
14 |
15 | if (unity > 1 && unity < 5) // 2, 3, 4, 22, 23, 24 ...
16 | return RussianGrammaticalNumber.Paucal;
17 | }
18 |
19 | return RussianGrammaticalNumber.Plural;
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/src/Humanizer/Humanizer.csproj.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | True
3 | True
4 | False
5 | True
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Shared/Localisation/ResourcesTests.cs:
--------------------------------------------------------------------------------
1 | using System.Globalization;
2 | using Humanizer.Localisation;
3 | using Xunit;
4 |
5 | namespace Humanizer.Tests.Localisation
6 | {
7 | public class ResourcesTests
8 | {
9 | [Fact]
10 | [UseCulture("ro")]
11 | public void CanGetCultureSpecificTranslationsWithImplicitCulture()
12 | {
13 | var format = Resources.GetResource("DateHumanize_MultipleYearsAgo");
14 | Assert.Equal("acum {0}{1} ani", format);
15 | }
16 |
17 | [Fact]
18 | public void CanGetCultureSpecificTranslationsWithExplicitCulture()
19 | {
20 | var format = Resources.GetResource("DateHumanize_MultipleYearsAgo", new CultureInfo("ro"));
21 | Assert.Equal("acum {0}{1} ani", format);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/Ordinalizers/EnglishOrdinalizer.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer.Localisation.Ordinalizers
2 | {
3 | internal class EnglishOrdinalizer : DefaultOrdinalizer
4 | {
5 | public override string Convert(int number, string numberString)
6 | {
7 | var nMod100 = number % 100;
8 |
9 | if (nMod100 >= 11 && nMod100 <= 13)
10 | return numberString + "th";
11 |
12 | switch (number % 10)
13 | {
14 | case 1:
15 | return numberString + "st";
16 |
17 | case 2:
18 | return numberString + "nd";
19 |
20 | case 3:
21 | return numberString + "rd";
22 |
23 | default:
24 | return numberString + "th";
25 | }
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/samples/Humanizer.MvcSample/Controllers/HomeController.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Web;
5 | using System.Web.Mvc;
6 |
7 | namespace Humanizer.MvcSample.Controllers
8 | {
9 | public class HomeController : Controller
10 | {
11 | public ActionResult Index()
12 | {
13 | ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
14 |
15 | return View();
16 | }
17 |
18 | public ActionResult About()
19 | {
20 | ViewBag.Message = "Your quintessential app description page.";
21 |
22 | return View();
23 | }
24 |
25 | public ActionResult Contact()
26 | {
27 | ViewBag.Message = "Your quintessential contact page.";
28 |
29 | return View();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Shared/Localisation/de/OrdinalizeTests.cs:
--------------------------------------------------------------------------------
1 | using Xunit;
2 |
3 | namespace Humanizer.Tests.Localisation.de
4 | {
5 | [UseCulture("de-DE")]
6 | public class OrdinalizeTests
7 | {
8 | [Theory]
9 | [InlineData("0", "0.")]
10 | [InlineData("1", "1.")]
11 | [InlineData("2", "2.")]
12 | [InlineData("3", "3.")]
13 | [InlineData("4", "4.")]
14 | [InlineData("5", "5.")]
15 | [InlineData("6", "6.")]
16 | [InlineData("23", "23.")]
17 | [InlineData("100", "100.")]
18 | [InlineData("101", "101.")]
19 | [InlineData("102", "102.")]
20 | [InlineData("103", "103.")]
21 | [InlineData("1001", "1001.")]
22 | public void OrdinalizeString(string number, string ordinalized)
23 | {
24 | Assert.Equal(ordinalized, number.Ordinalize());
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Shared/Localisation/nl/OrdinalizeTests.cs:
--------------------------------------------------------------------------------
1 | using Xunit;
2 |
3 | namespace Humanizer.Tests.Localisation.nl
4 | {
5 | [UseCulture("nl")]
6 | public class OrdinalizeTests
7 | {
8 |
9 | [Theory]
10 | [InlineData("0", "0")]
11 | [InlineData("1", "1e")]
12 | [InlineData("2", "2e")]
13 | [InlineData("3", "3e")]
14 | [InlineData("4", "4e")]
15 | [InlineData("5", "5e")]
16 | [InlineData("6", "6e")]
17 | [InlineData("23", "23e")]
18 | [InlineData("100", "100e")]
19 | [InlineData("101", "101e")]
20 | [InlineData("102", "102e")]
21 | [InlineData("103", "103e")]
22 | [InlineData("1001", "1001e")]
23 | public void OrdinalizeString(string number, string ordinalized)
24 | {
25 | Assert.Equal(number.Ordinalize(), ordinalized);
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Humanizer/Configuration/OrdinalizerRegistry.cs:
--------------------------------------------------------------------------------
1 | using Humanizer.Localisation.Ordinalizers;
2 |
3 | namespace Humanizer.Configuration
4 | {
5 | internal class OrdinalizerRegistry : LocaliserRegistry
6 | {
7 | public OrdinalizerRegistry() : base(new DefaultOrdinalizer())
8 | {
9 | Register("de", new GermanOrdinalizer());
10 | Register("en", new EnglishOrdinalizer());
11 | Register("es", new SpanishOrdinalizer());
12 | Register("it", new ItalianOrdinalizer());
13 | Register("nl", new DutchOrdinalizer());
14 | Register("pt", new PortugueseOrdinalizer());
15 | Register("ro", new RomanianOrdinalizer());
16 | Register("ru", new RussianOrdinalizer());
17 | Register("tr", new TurkishOrdinalizer());
18 | Register("uk", new UkrainianOrdinalizer());
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/Formatters/SlovenianFormatter.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer.Localisation.Formatters
2 | {
3 | internal class SlovenianFormatter : DefaultFormatter
4 | {
5 | private const string DualPostfix = "_Dual";
6 | private const string TrialQuadralPostfix = "_TrialQuadral";
7 |
8 | public SlovenianFormatter()
9 | : base("sl")
10 | {
11 | }
12 |
13 | protected override string GetResourceKey(string resourceKey, int number)
14 | {
15 | if (number == 2)
16 | return resourceKey + DualPostfix;
17 |
18 | // When the count is three or four some some words have a different form when counting in Slovenian language
19 | if (number == 3 || number == 4)
20 | return resourceKey + TrialQuadralPostfix;
21 |
22 | return resourceKey;
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/DateToOrdinalWords/IDateToOrdinalWordConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Humanizer.Localisation.DateToOrdinalWords
4 | {
5 | ///
6 | /// The interface used to localise the ToOrdinalWords method.
7 | ///
8 | public interface IDateToOrdinalWordConverter
9 | {
10 | ///
11 | /// Converts the date to Ordinal Words
12 | ///
13 | ///
14 | ///
15 | string Convert(DateTime date);
16 |
17 | ///
18 | /// Converts the date to Ordinal Words using the provided grammatical case
19 | ///
20 | ///
21 | ///
22 | ///
23 | string Convert(DateTime date, GrammaticalCase grammaticalCase);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/scripts/Sign-Package.ps1:
--------------------------------------------------------------------------------
1 | $currentDirectory = split-path $MyInvocation.MyCommand.Definition
2 |
3 | # See if we have the ClientSecret available
4 | if([string]::IsNullOrEmpty($env:SignClientSecret)){
5 | Write-Host "Client Secret not found, not signing packages"
6 | return;
7 | }
8 |
9 | # Setup Variables we need to pass into the sign client tool
10 |
11 | $appSettings = "$currentDirectory\SignClient.json"
12 |
13 | $appPath = "$currentDirectory\..\packages\SignClient\tools\netcoreapp2.0\SignClient.dll"
14 |
15 | $nupgks = ls $currentDirectory\..\*.nupkg | Select -ExpandProperty FullName
16 |
17 | foreach ($nupkg in $nupgks){
18 | Write-Host "Submitting $nupkg for signing"
19 |
20 | dotnet $appPath 'sign' -c $appSettings -i $nupkg -r $env:SignClientUser -s $env:SignClientSecret -n 'Humanizer' -d 'Humanizer' -u 'https://github.com/Humanizr/Humanizer'
21 |
22 | Write-Host "Finished signing $nupkg"
23 | }
24 |
25 | Write-Host "Sign-package complete"
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/Formatters/ArabicFormatter.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer.Localisation.Formatters
2 | {
3 | internal class ArabicFormatter : DefaultFormatter
4 | {
5 | private const string DualPostfix = "_Dual";
6 | private const string PluralPostfix = "_Plural";
7 |
8 | public ArabicFormatter()
9 | : base("ar")
10 | {
11 | }
12 |
13 | protected override string GetResourceKey(string resourceKey, int number)
14 | {
15 | //In Arabic pluralization 2 entities gets a different word.
16 | if (number == 2)
17 | return resourceKey + DualPostfix;
18 |
19 | //In Arabic pluralization entities where the count is between 3 and 10 gets a different word.
20 | if (number >= 3 && number <= 10 )
21 | return resourceKey + PluralPostfix;
22 |
23 | return resourceKey;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Shared/Localisation/es/NumberToWordsFeminineTest.cs:
--------------------------------------------------------------------------------
1 | using Xunit;
2 |
3 | namespace Humanizer.Tests.Localisation.es
4 | {
5 | [UseCulture("es-ES")]
6 | public class NumberToWordsFeminineTests
7 | {
8 |
9 | [Theory]
10 | [InlineData(1, "una")]
11 | [InlineData(21, "veintiuna")]
12 | [InlineData(31, "treinta y una")]
13 | [InlineData(81, "ochenta y una")]
14 | [InlineData(500, "quinientas")]
15 | [InlineData(701, "setecientas una")]
16 | [InlineData(3500, "tres mil quinientas")]
17 | [InlineData(200121, "doscientas mil ciento veintiuna")]
18 | [InlineData(200000121, "doscientos millones ciento veintiuna")]
19 | [InlineData(1000001, "un millón una")]
20 | public void ToWords(int number, string expected)
21 | {
22 | Assert.Equal(expected, number.ToWords(GrammaticalGender.Feminine));
23 | }
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/Ordinalizers/IOrdinalizer.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer.Localisation.Ordinalizers
2 | {
3 | ///
4 | /// The interface used to localise the Ordinalize method
5 | ///
6 | public interface IOrdinalizer
7 | {
8 | ///
9 | /// Ordinalizes the number
10 | ///
11 | ///
12 | ///
13 | ///
14 | string Convert(int number, string numberString);
15 |
16 | ///
17 | /// Ordinalizes the number using the provided grammatical gender
18 | ///
19 | ///
20 | ///
21 | ///
22 | ///
23 | string Convert(int number, string numberString, GrammaticalGender gender);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/NumberToWords/RomanianNumberToWordsConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Humanizer.Localisation.NumberToWords.Romanian;
3 |
4 | namespace Humanizer.Localisation.NumberToWords
5 | {
6 | internal class RomanianNumberToWordsConverter : GenderedNumberToWordsConverter
7 | {
8 | public override string Convert(long number, GrammaticalGender gender)
9 | {
10 | if (number > Int32.MaxValue || number < Int32.MinValue)
11 | {
12 | throw new NotImplementedException();
13 | }
14 | var converter = new RomanianCardinalNumberConverter();
15 | return converter.Convert((int)number, gender);
16 | }
17 |
18 | public override string ConvertToOrdinal(int number, GrammaticalGender gender)
19 | {
20 | var converter = new RomanianOrdinalNumberConverter();
21 | return converter.Convert(number, gender);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Humanizer/Transformer/ToTitleCase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace Humanizer
6 | {
7 | class ToTitleCase : IStringTransformer
8 | {
9 | public string Transform(string input)
10 | {
11 | var words = input.Split(' ');
12 | var result = new List();
13 | foreach (var word in words)
14 | {
15 | if (word.Length == 0 || AllCapitals(word))
16 | result.Add(word);
17 | else if(word.Length == 1)
18 | result.Add(word.ToUpper());
19 | else
20 | result.Add(char.ToUpper(word[0]) + word.Remove(0, 1).ToLower());
21 | }
22 |
23 | return string.Join(" ", result);
24 | }
25 |
26 | static bool AllCapitals(string input)
27 | {
28 | return input.ToCharArray().All(char.IsUpper);
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/Formatters/RussianFormatter.cs:
--------------------------------------------------------------------------------
1 | using Humanizer.Localisation.GrammaticalNumber;
2 |
3 | namespace Humanizer.Localisation.Formatters
4 | {
5 | internal class RussianFormatter : DefaultFormatter
6 | {
7 | public RussianFormatter()
8 | : base("ru")
9 | {
10 | }
11 |
12 | protected override string GetResourceKey(string resourceKey, int number)
13 | {
14 | var grammaticalNumber = RussianGrammaticalNumberDetector.Detect(number);
15 | var suffix = GetSuffix(grammaticalNumber);
16 | return resourceKey + suffix;
17 | }
18 |
19 | private string GetSuffix(RussianGrammaticalNumber grammaticalNumber)
20 | {
21 | if (grammaticalNumber == RussianGrammaticalNumber.Singular)
22 | return "_Singular";
23 | if (grammaticalNumber == RussianGrammaticalNumber.Paucal)
24 | return "_Paucal";
25 | return "";
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Shared/FluentDate/PrepositionTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xunit;
3 |
4 | namespace Humanizer.Tests.FluentDate
5 | {
6 | public class PrepositionTests
7 | {
8 | [Fact]
9 | public void AtMidnight()
10 | {
11 | var now = DateTime.Now;
12 | var midnight = now.AtMidnight();
13 | Assert.Equal(new DateTime(now.Year, now.Month, now.Day), midnight);
14 | }
15 |
16 | [Fact]
17 | public void AtNoon()
18 | {
19 | var now = DateTime.Now;
20 | var noon = now.AtNoon();
21 | Assert.Equal(new DateTime(now.Year, now.Month, now.Day, 12, 0, 0), noon);
22 | }
23 |
24 | [Fact]
25 | public void InYear()
26 | {
27 | var now = DateTime.Now;
28 | var in2011 = now.In(2011);
29 | Assert.Equal(new DateTime(2011, now.Month, now.Day, now.Hour, now.Minute, now.Second, now.Millisecond), in2011);
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/Formatters/HebrewFormatter.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer.Localisation.Formatters
2 | {
3 | internal class HebrewFormatter : DefaultFormatter
4 | {
5 | private const string DualPostfix = "_Dual";
6 | private const string PluralPostfix = "_Plural";
7 |
8 | public HebrewFormatter()
9 | : base("he")
10 | {
11 | }
12 |
13 | protected override string GetResourceKey(string resourceKey, int number)
14 | {
15 | //In Hebrew pluralization 2 entities gets a different word.
16 | if (number == 2)
17 | return resourceKey + DualPostfix;
18 |
19 | //In Hebrew pluralization entities where the count is between 3 and 10 gets a different word.
20 | //See http://lib.cet.ac.il/pages/item.asp?item=21585 for explanation
21 | if (number >= 3 && number <= 10)
22 | return resourceKey + PluralPostfix;
23 |
24 | return resourceKey;
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/Formatters/UkrainianFormatter.cs:
--------------------------------------------------------------------------------
1 | using Humanizer.Localisation.GrammaticalNumber;
2 |
3 | namespace Humanizer.Localisation.Formatters
4 | {
5 | internal class UkrainianFormatter : DefaultFormatter
6 | {
7 | public UkrainianFormatter()
8 | : base("uk")
9 | {
10 | }
11 |
12 | protected override string GetResourceKey(string resourceKey, int number)
13 | {
14 | var grammaticalNumber = RussianGrammaticalNumberDetector.Detect(number);
15 | var suffix = GetSuffix(grammaticalNumber);
16 | return resourceKey + suffix;
17 | }
18 |
19 | private string GetSuffix(RussianGrammaticalNumber grammaticalNumber)
20 | {
21 | if (grammaticalNumber == RussianGrammaticalNumber.Singular)
22 | return "_Singular";
23 | if (grammaticalNumber == RussianGrammaticalNumber.Paucal)
24 | return "_Paucal";
25 | return "";
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Shared/Localisation/sv/CollectionFormatterTests.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Xunit;
3 |
4 | namespace Humanizer.Tests.Localisation.sv
5 | {
6 | [UseCulture("sv-SE")]
7 | public class CollectionFormatterTests
8 | {
9 | [Fact]
10 | public void MoreThanTwoItems()
11 | {
12 | var collection = new List(new[] {1, 2, 3});
13 | var humanized = "1, 2 och 3";
14 | Assert.Equal(humanized, collection.Humanize());
15 | }
16 |
17 | [Fact]
18 | public void OneItem()
19 | {
20 | var collection = new List(new[] {1});
21 | var humanized = "1";
22 | Assert.Equal(humanized, collection.Humanize());
23 | }
24 |
25 | [Fact]
26 | public void TwoItems()
27 | {
28 | var collection = new List(new[] {1, 2});
29 | var humanized = "1 och 2";
30 | Assert.Equal(humanized, collection.Humanize());
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/src/Humanizer/GrammaticalCase.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer
2 | {
3 | ///
4 | /// Options for specifying the desired grammatical case for the output words
5 | ///
6 | public enum GrammaticalCase
7 | {
8 | ///
9 | /// Indicates the subject of a finite verb
10 | ///
11 | Nominative,
12 | ///
13 | /// Indicates the possessor of another noun
14 | ///
15 | Genitive,
16 | ///
17 | /// Indicates the indirect object of a verb
18 | ///
19 | Dative,
20 | ///
21 | /// Indicates the direct object of a verb
22 | ///
23 | Accusative,
24 | ///
25 | /// Indicates an object used in performing an action
26 | ///
27 | Instrumental,
28 | ///
29 | /// Indicates the object of a preposition
30 | ///
31 | Prepositional,
32 | }
33 | }
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/NumberToWords/FrenchBelgianNumberToWordsConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace Humanizer.Localisation.NumberToWords
5 | {
6 | internal class FrenchBelgianNumberToWordsConverter : FrenchNumberToWordsConverterBase
7 | {
8 | protected override void CollectPartsUnderAHundred(ICollection parts, ref int number, GrammaticalGender gender, bool pluralize)
9 | {
10 | if (number == 80)
11 | parts.Add(pluralize ? "quatre-vingts" : "quatre-vingt");
12 | else if (number == 81)
13 | parts.Add(gender == GrammaticalGender.Feminine ? "quatre-vingt-une" : "quatre-vingt-un");
14 | else
15 | base.CollectPartsUnderAHundred(parts, ref number, gender, pluralize);
16 | }
17 |
18 | protected override string GetTens(int tens)
19 | {
20 | if (tens == 8)
21 | return "quatre-vingt";
22 |
23 | return base.GetTens(tens);
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Shared/Localisation/it/CollectionFormatterTests.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Xunit;
3 |
4 | namespace Humanizer.Tests.Localisation.it
5 | {
6 | [UseCulture("it")]
7 | public class CollectionFormatterTests
8 | {
9 |
10 | [Fact]
11 | public void OneItem()
12 | {
13 | var collection = new List(new int[] {1});
14 | var humanized = "1";
15 | Assert.Equal(humanized, collection.Humanize());
16 | }
17 |
18 | [Fact]
19 | public void TwoItems()
20 | {
21 | var collection = new List(new int[] {1, 2});
22 | var humanized = "1 e 2";
23 | Assert.Equal(humanized, collection.Humanize());
24 | }
25 |
26 | [Fact]
27 | public void MoreThanTwoItems()
28 | {
29 | var collection = new List(new int[] {1, 2, 3});
30 | var humanized = "1, 2 e 3";
31 | Assert.Equal(humanized, collection.Humanize());
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Shared/Localisation/de/CollectionFormatterTests.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Xunit;
3 |
4 | namespace Humanizer.Tests.Localisation.de
5 | {
6 | [UseCulture("de")]
7 | public class CollectionFormatterTests
8 | {
9 |
10 | [Fact]
11 | public void OneItem()
12 | {
13 | var collection = new List(new int[] {1});
14 | var humanized = "1";
15 | Assert.Equal(humanized, collection.Humanize());
16 | }
17 |
18 | [Fact]
19 | public void TwoItems()
20 | {
21 | var collection = new List(new int[] {1, 2});
22 | var humanized = "1 und 2";
23 | Assert.Equal(humanized, collection.Humanize());
24 | }
25 |
26 | [Fact]
27 | public void MoreThanTwoItems()
28 | {
29 | var collection = new List(new int[] {1, 2, 3});
30 | var humanized = "1, 2 und 3";
31 | Assert.Equal(humanized, collection.Humanize());
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.af.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.af
5 | $version$
6 | Humanizer Locale (af)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (af)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | af
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.ar.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.ar
5 | $version$
6 | Humanizer Locale (ar)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (ar)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | ar
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.bg.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.bg
5 | $version$
6 | Humanizer Locale (bg)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (bg)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | bg
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.cs.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.cs
5 | $version$
6 | Humanizer Locale (cs)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (cs)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | cs
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.da.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.da
5 | $version$
6 | Humanizer Locale (da)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (da)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | da
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.de.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.de
5 | $version$
6 | Humanizer Locale (de)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (de)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | de
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.el.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.el
5 | $version$
6 | Humanizer Locale (el)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (el)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | el
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.es.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.es
5 | $version$
6 | Humanizer Locale (es)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (es)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | es
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.fa.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.fa
5 | $version$
6 | Humanizer Locale (fa)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (fa)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | fa
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.fr.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.fr
5 | $version$
6 | Humanizer Locale (fr)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (fr)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | fr
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.he.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.he
5 | $version$
6 | Humanizer Locale (he)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (he)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | he
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.hr.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.hr
5 | $version$
6 | Humanizer Locale (hr)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (hr)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | hr
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.hu.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.hu
5 | $version$
6 | Humanizer Locale (hu)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (hu)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | hu
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.id.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.id
5 | $version$
6 | Humanizer Locale (id)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (id)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | id
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.it.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.it
5 | $version$
6 | Humanizer Locale (it)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (it)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | it
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.ja.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.ja
5 | $version$
6 | Humanizer Locale (ja)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (ja)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | ja
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.lv.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.lv
5 | $version$
6 | Humanizer Locale (lv)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (lv)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | lv
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.nb.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.nb
5 | $version$
6 | Humanizer Locale (nb)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (nb)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | nb
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.nl.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.nl
5 | $version$
6 | Humanizer Locale (nl)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (nl)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | nl
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.pl.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.pl
5 | $version$
6 | Humanizer Locale (pl)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (pl)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | pl
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.pt.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.pt
5 | $version$
6 | Humanizer Locale (pt)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (pt)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | pt
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.ro.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.ro
5 | $version$
6 | Humanizer Locale (ro)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (ro)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | ro
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.ru.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.ru
5 | $version$
6 | Humanizer Locale (ru)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (ru)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | ru
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.sk.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.sk
5 | $version$
6 | Humanizer Locale (sk)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (sk)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | sk
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.sl.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.sl
5 | $version$
6 | Humanizer Locale (sl)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (sl)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | sl
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.sr.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.sr
5 | $version$
6 | Humanizer Locale (sr)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (sr)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | sr
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.sv.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.sv
5 | $version$
6 | Humanizer Locale (sv)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (sv)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | sv
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.tr.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.tr
5 | $version$
6 | Humanizer Locale (tr)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (tr)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | tr
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.uk.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.uk
5 | $version$
6 | Humanizer Locale (uk)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (uk)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | uk
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.vi.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.vi
5 | $version$
6 | Humanizer Locale (vi)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (vi)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | vi
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Shared/Localisation/ro-Ro/CollectionFormatterTests.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Xunit;
3 |
4 | namespace Humanizer.Tests.Localisation.roRO
5 | {
6 | [UseCulture("ro-RO")]
7 | public class CollectionFormatterTests
8 | {
9 |
10 | [Fact]
11 | public void OneItem()
12 | {
13 | var collection = new List(new int[] { 1 });
14 | var humanized = "1";
15 | Assert.Equal(humanized, collection.Humanize());
16 | }
17 |
18 | [Fact]
19 | public void TwoItems()
20 | {
21 | var collection = new List(new int[] { 1, 2 });
22 | var humanized = "1 și 2";
23 | Assert.Equal(humanized, collection.Humanize());
24 | }
25 |
26 | [Fact]
27 | public void MoreThanTwoItems()
28 | {
29 | var collection = new List(new int[] { 1, 2, 3 });
30 | var humanized = "1, 2 și 3";
31 | Assert.Equal(humanized, collection.Humanize());
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Uwp.Runner/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Reflection;
6 | using System.Runtime.InteropServices.WindowsRuntime;
7 | using Windows.ApplicationModel;
8 | using Windows.ApplicationModel.Activation;
9 | using Windows.Foundation;
10 | using Windows.Foundation.Collections;
11 | using Windows.UI.Xaml;
12 | using Windows.UI.Xaml.Controls;
13 | using Windows.UI.Xaml.Controls.Primitives;
14 | using Windows.UI.Xaml.Data;
15 | using Windows.UI.Xaml.Input;
16 | using Windows.UI.Xaml.Media;
17 | using Windows.UI.Xaml.Navigation;
18 | using Xunit.Runners.UI;
19 |
20 | namespace Humanizer.Tests.Uwp.Runner
21 | {
22 | ///
23 | /// Provides application-specific behavior to supplement the default Application class.
24 | ///
25 | sealed partial class App : RunnerApplication
26 | {
27 | protected override void OnInitializeRunner()
28 | {
29 | AddTestAssembly(typeof(App).GetTypeInfo().Assembly);
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/Ordinalizers/UkrainianOrdinalizer.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer.Localisation.Ordinalizers
2 | {
3 | internal class UkrainianOrdinalizer : DefaultOrdinalizer
4 | {
5 | public override string Convert(int number, string numberString)
6 | {
7 | return Convert(number, numberString, GrammaticalGender.Masculine);
8 | }
9 |
10 | public override string Convert(int number, string numberString, GrammaticalGender gender)
11 | {
12 |
13 | if (gender == GrammaticalGender.Masculine)
14 | return numberString + "-й";
15 |
16 | if (gender == GrammaticalGender.Feminine)
17 | {
18 | if (number % 10 == 3)
19 | return numberString + "-я";
20 | return numberString + "-а";
21 | }
22 |
23 | if (gender == GrammaticalGender.Neuter)
24 | if (number % 10 == 3)
25 | return numberString + "-є";
26 |
27 | return numberString + "-е";
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Humanizer/Configuration/CollectionFormatterRegistry.cs:
--------------------------------------------------------------------------------
1 | using Humanizer.Localisation.CollectionFormatters;
2 |
3 | namespace Humanizer.Configuration
4 | {
5 | internal class CollectionFormatterRegistry : LocaliserRegistry
6 | {
7 | public CollectionFormatterRegistry()
8 | : base(new DefaultCollectionFormatter("&"))
9 | {
10 | Register("en", new OxfordStyleCollectionFormatter("and"));
11 | Register("it", new DefaultCollectionFormatter("e"));
12 | Register("de", new DefaultCollectionFormatter("und"));
13 | Register("dk", new DefaultCollectionFormatter("og"));
14 | Register("nl", new DefaultCollectionFormatter("en"));
15 | Register("pt", new DefaultCollectionFormatter("e"));
16 | Register("ro", new DefaultCollectionFormatter("și"));
17 | Register("nn", new DefaultCollectionFormatter("og"));
18 | Register("nb", new DefaultCollectionFormatter("og"));
19 | Register("sv", new DefaultCollectionFormatter("och"));
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.bn-BD.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.bn-BD
5 | $version$
6 | Humanizer Locale (bn-BD)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (bn-BD)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | bn-BD
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.fi-FI.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.fi-FI
5 | $version$
6 | Humanizer Locale (fi-FI)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (fi-FI)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | fi-FI
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.fr-BE.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.fr-BE
5 | $version$
6 | Humanizer Locale (fr-BE)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (fr-BE)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | fr-BE
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.ko-KR.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.ko-KR
5 | $version$
6 | Humanizer Locale (ko-KR)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (ko-KR)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | ko-KR
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.ms-MY.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.ms-MY
5 | $version$
6 | Humanizer Locale (ms-MY)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (ms-MY)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | ms-MY
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.nb-NO.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.nb-NO
5 | $version$
6 | Humanizer Locale (nb-NO)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (nb-NO)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | nb-NO
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.th-TH.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.th-TH
5 | $version$
6 | Humanizer Locale (th-TH)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (th-TH)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | th-TH
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.zh-CN.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.zh-CN
5 | $version$
6 | Humanizer Locale (zh-CN)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (zh-CN)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | zh-CN
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.fil-PH.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.fil-PH
5 | $version$
6 | Humanizer Locale (fil-PH)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (fil-PH)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | fil-PH
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.sr-Latn.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.sr-Latn
5 | $version$
6 | Humanizer Locale (sr-Latn)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (sr-Latn)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | sr-Latn
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.zh-Hans.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.zh-Hans
5 | $version$
6 | Humanizer Locale (zh-Hans)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (zh-Hans)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | zh-Hans
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.zh-Hant.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.zh-Hant
5 | $version$
6 | Humanizer Locale (zh-Hant)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (zh-Hant)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | zh-Hant
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Shared/FluentDate/InTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xunit;
3 |
4 | namespace Humanizer.Tests.FluentDate
5 | {
6 | public class InTests
7 | {
8 | [Fact]
9 | public void InJanuary()
10 | {
11 | Assert.Equal(new DateTime(DateTime.Now.Year, 1, 1), In.January);
12 | }
13 |
14 | [Fact]
15 | public void InJanuaryOf2009()
16 | {
17 | Assert.Equal(new DateTime(2009, 1, 1), In.JanuaryOf(2009));
18 | }
19 |
20 | [Fact]
21 | public void InFebruary()
22 | {
23 | Assert.Equal(new DateTime(DateTime.Now.Year, 2, 1), In.February);
24 | }
25 |
26 | [Fact]
27 | public void InTheYear()
28 | {
29 | Assert.Equal(new DateTime(2009, 1, 1), In.TheYear(2009));
30 | }
31 |
32 | [Fact]
33 | public void InFiveDays()
34 | {
35 | var baseDate = On.January.The21st;
36 | var date = In.Five.DaysFrom(baseDate);
37 | Assert.Equal(baseDate.AddDays(5), date);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | Here is a checklist you should tick through before submitting a pull request:
2 | - [ ] Implementation is clean
3 | - [ ] Code adheres to the existing coding standards; e.g. no curlies for one-line blocks, no redundant empty lines between methods or code blocks, spaces rather than tabs, etc.
4 | - [ ] No ReSharper warnings
5 | - [ ] There is proper unit test coverage
6 | - [ ] If the code is copied from StackOverflow (or a blog or OSS) full disclosure is included. That includes required license files and/or file headers explaining where the code came from with proper attribution
7 | - [ ] There are very few or no comments (because comments shouldn't be needed if you write clean code)
8 | - [ ] Xml documentation is added/updated for the addition/change
9 | - [ ] Your PR is (re)based on top of the latest commits from the `dev` branch (more info below)
10 | - [ ] Link to the issue(s) you're fixing from your PR description. Use `fixes #`
11 | - [ ] Readme is updated if you change an existing feature or add a new one
12 | - [ ] Run either `build.cmd` or `build.ps1` and ensure there are no test failures
13 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.uz-Cyrl-UZ.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.uz-Cyrl-UZ
5 | $version$
6 | Humanizer Locale (uz-Cyrl-UZ)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (uz-Cyrl-UZ)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | uz-Cyrl-UZ
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.uz-Latn-UZ.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core.uz-Latn-UZ
5 | $version$
6 | Humanizer Locale (uz-Latn-UZ)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer Locale (uz-Latn-UZ)
13 | Copyright 2012-2015 Mehdi Khalili
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | uz-Latn-UZ
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/Resources.cs:
--------------------------------------------------------------------------------
1 | using System.Globalization;
2 | using System.Reflection;
3 | using System.Resources;
4 |
5 | namespace Humanizer.Localisation
6 | {
7 | ///
8 | /// Provides access to the resources of Humanizer
9 | ///
10 | public static class Resources
11 | {
12 | static readonly ResourceManager ResourceManager = new ResourceManager("Humanizer.Properties.Resources", typeof(Resources).GetTypeInfo().Assembly);
13 |
14 | ///
15 | /// Returns the value of the specified string resource
16 | ///
17 | /// The name of the resource to retrieve.
18 | /// The culture of the resource to retrieve. If not specified, current thread's UI culture is used.
19 | /// The value of the resource localized for the specified culture.
20 | public static string GetResource(string resourceKey, CultureInfo culture = null)
21 | {
22 | return ResourceManager.GetString(resourceKey, culture);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Humanizer/Truncation/Truncator.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer
2 | {
3 | ///
4 | /// Gets a ITruncator
5 | ///
6 | public static class Truncator
7 | {
8 | ///
9 | /// Fixed length truncator
10 | ///
11 | public static ITruncator FixedLength
12 | {
13 | get
14 | {
15 | return new FixedLengthTruncator();
16 | }
17 | }
18 |
19 | ///
20 | /// Fixed number of characters truncator
21 | ///
22 | public static ITruncator FixedNumberOfCharacters
23 | {
24 | get
25 | {
26 | return new FixedNumberOfCharactersTruncator();
27 | }
28 | }
29 |
30 | ///
31 | /// Fixed number of words truncator
32 | ///
33 | public static ITruncator FixedNumberOfWords
34 | {
35 | get
36 | {
37 | return new FixedNumberOfWordsTruncator();
38 | }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/NumberToWords/ItalianNumberToWordsConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Humanizer.Localisation.NumberToWords.Italian;
3 |
4 | namespace Humanizer.Localisation.NumberToWords
5 | {
6 | internal class ItalianNumberToWordsConverter : GenderedNumberToWordsConverter
7 | {
8 | public override string Convert(long input, GrammaticalGender gender)
9 | {
10 | if (input > Int32.MaxValue || input < Int32.MinValue)
11 | {
12 | throw new NotImplementedException();
13 | }
14 | var number = (int)input;
15 |
16 | if (number < 0)
17 | return "meno " + Convert(Math.Abs(number), gender);
18 |
19 | var cruncher = new ItalianCardinalNumberCruncher(number, gender);
20 |
21 | return cruncher.Convert();
22 | }
23 |
24 | public override string ConvertToOrdinal(int number, GrammaticalGender gender)
25 | {
26 | var cruncher = new ItalianOrdinalNumberCruncher(number, gender);
27 |
28 | return cruncher.Convert();
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Shared/StringDehumanizeTests.cs:
--------------------------------------------------------------------------------
1 | using Xunit;
2 |
3 | namespace Humanizer.Tests
4 | {
5 | public class StringDehumanizeTests
6 | {
7 | [Theory]
8 | [InlineData("Pascal case sentence is camelized", "PascalCaseSentenceIsCamelized")]
9 | [InlineData("Title Case Sentence Is Camelized", "TitleCaseSentenceIsCamelized")]
10 | [InlineData("Mixed case sentence Is Camelized", "MixedCaseSentenceIsCamelized")]
11 | [InlineData("lower case sentence is camelized", "LowerCaseSentenceIsCamelized")]
12 | [InlineData("AlreadyDehumanizedStringIsUntouched", "AlreadyDehumanizedStringIsUntouched")]
13 | [InlineData("", "")]
14 | [InlineData("A special character is removed?", "ASpecialCharacterIsRemoved")]
15 | [InlineData("A special character is removed after a space ?", "ASpecialCharacterIsRemovedAfterASpace")]
16 | [InlineData("Internal special characters ?)@ are removed", "InternalSpecialCharactersAreRemoved")]
17 | public void CanDehumanizeIntoAPascalCaseWord(string input, string expectedResult)
18 | {
19 | Assert.Equal(expectedResult, input.Dehumanize());
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Shared/Humanizer.Tests.Shared.shproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | fdec244b-f07e-4a5e-bb80-fbc6ac77a9aa
5 | 14.0
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Uwp.Runner/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Humanizer.Tests.Uwp.Runner")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Humanizer.Tests.Uwp.Runner")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Version information for an assembly consists of the following four values:
18 | //
19 | // Major Version
20 | // Minor Version
21 | // Build Number
22 | // Revision
23 | //
24 | // You can specify all the values or you can default the Build and Revision Numbers
25 | // by using the '*' as shown below:
26 | // [assembly: AssemblyVersion("1.0.*")]
27 | [assembly: AssemblyVersion("1.0.0.0")]
28 | [assembly: AssemblyFileVersion("1.0.0.0")]
29 | [assembly: ComVisible(false)]
--------------------------------------------------------------------------------
/src/Humanizer/Truncation/FixedLengthTruncator.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer
2 | {
3 | ///
4 | /// Truncate a string to a fixed length
5 | ///
6 | class FixedLengthTruncator : ITruncator
7 | {
8 | public string Truncate(string value, int length, string truncationString, TruncateFrom truncateFrom = TruncateFrom.Right)
9 | {
10 | if (value == null)
11 | return null;
12 |
13 | if (value.Length == 0)
14 | return value;
15 |
16 | if (truncationString == null || truncationString.Length > length)
17 | return truncateFrom == TruncateFrom.Right
18 | ? value.Substring(0, length)
19 | : value.Substring(value.Length - length);
20 |
21 |
22 | if (truncateFrom == TruncateFrom.Left)
23 | return value.Length > length
24 | ? truncationString + value.Substring(value.Length - length + truncationString.Length)
25 | : value;
26 |
27 | return value.Length > length
28 | ? value.Substring(0, length - truncationString.Length) + truncationString
29 | : value;
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/NumberToWords/FrenchNumberToWordsConverter.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace Humanizer.Localisation.NumberToWords
4 | {
5 | class FrenchNumberToWordsConverter : FrenchNumberToWordsConverterBase
6 | {
7 | protected override void CollectPartsUnderAHundred(ICollection parts, ref int number, GrammaticalGender gender, bool pluralize)
8 | {
9 | if (number == 71)
10 | parts.Add("soixante et onze");
11 | else if (number == 80)
12 | parts.Add(pluralize ? "quatre-vingts" : "quatre-vingt");
13 | else if (number >= 70)
14 | {
15 | var @base = number < 80 ? 60 : 80;
16 | int units = number - @base;
17 | var tens = @base/10;
18 | parts.Add($"{GetTens(tens)}-{GetUnits(units, gender)}");
19 | }
20 | else
21 | base.CollectPartsUnderAHundred(parts, ref number, gender, pluralize);
22 | }
23 |
24 | protected override string GetTens(int tens)
25 | {
26 | if (tens == 8)
27 | return "quatre-vingt";
28 |
29 | return base.GetTens(tens);
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Uwp/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Humanizer.Tests.Uwp")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Humanizer.Tests.Uwp")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 | [assembly: AssemblyMetadata("TargetPlatform","UAP")]
17 |
18 | // Version information for an assembly consists of the following four values:
19 | //
20 | // Major Version
21 | // Minor Version
22 | // Build Number
23 | // Revision
24 | //
25 | // You can specify all the values or you can default the Build and Revision Numbers
26 | // by using the '*' as shown below:
27 | // [assembly: AssemblyVersion("1.0.*")]
28 | [assembly: AssemblyVersion("1.0.0.0")]
29 | [assembly: AssemblyFileVersion("1.0.0.0")]
30 | [assembly: ComVisible(false)]
--------------------------------------------------------------------------------
/src/Humanizer/CasingExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Humanizer
4 | {
5 | ///
6 | /// ApplyCase method to allow changing the case of a sentence easily
7 | ///
8 | public static class CasingExtensions
9 | {
10 | ///
11 | /// Changes the casing of the provided input
12 | ///
13 | ///
14 | ///
15 | ///
16 | public static string ApplyCase(this string input, LetterCasing casing)
17 | {
18 | switch (casing)
19 | {
20 | case LetterCasing.Title:
21 | return input.Transform(To.TitleCase);
22 |
23 | case LetterCasing.LowerCase:
24 | return input.Transform(To.LowerCase);
25 |
26 | case LetterCasing.AllCaps:
27 | return input.Transform(To.UpperCase);
28 |
29 | case LetterCasing.Sentence:
30 | return input.Transform(To.SentenceCase);
31 |
32 | default:
33 | throw new ArgumentOutOfRangeException(nameof(casing));
34 | }
35 | }
36 | }
37 | }
--------------------------------------------------------------------------------
/src/Humanizer/FluentDate/In.Months.tt:
--------------------------------------------------------------------------------
1 | <#@ template debug="true" hostSpecific="true" #>
2 | <#@ output extension=".cs" #>
3 | <#@ Assembly Name="System.Core" #>
4 | <#@ Assembly Name="System.Windows.Forms" #>
5 | <#@ import namespace="System" #>
6 | <#@ import namespace="System.IO" #>
7 | <#@ import namespace="System.Diagnostics" #>
8 | <#@ import namespace="System.Linq" #>
9 | <#@ import namespace="System.Collections" #>
10 | <#@ import namespace="System.Collections.Generic" #>
11 | using System;
12 |
13 | namespace Humanizer
14 | {
15 | public partial class In
16 | {
17 | <#var now = DateTime.Now;
18 | for (int i = 0; i < 12; i++){
19 | var monthName = new DateTime(now.Year, i + 1, 1).ToString("MMMM");
20 | #>
21 | ///
22 | /// Returns 1st of <#= monthName #> of the current year
23 | ///
24 | public static DateTime <#= monthName #>
25 | {
26 | get { return new DateTime(DateTime.UtcNow.Year, <#= i + 1 #>, 1); }
27 | }
28 |
29 | ///
30 | /// Returns 1st of <#= monthName #> of the year passed in
31 | ///
32 | public static DateTime <#= monthName#>Of(int year)
33 | {
34 | return new DateTime(year, <#= i + 1 #>, 1);
35 | }
36 | <#
37 | }
38 |
39 | #>
40 | }
41 | }
--------------------------------------------------------------------------------
/NuSpecs/Humanizer.Core.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Humanizer.Core
5 | $version$
6 | Humanizer Locale (en)
7 | Mehdi Khalili, Oren Novotny
8 | Mehdi Khalili, onovotny
9 | https://github.com/Humanizr/Humanizer
10 | https://raw.github.com/Humanizr/Humanizer/master/logo.png
11 | false
12 | Humanizer core package that contains the library and the neutral language (English) resources
13 | Copyright 2012-2016
14 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
15 | en
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeHumanizeStrategy.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 |
4 | namespace Humanizer.DateTimeHumanizeStrategy
5 | {
6 | ///
7 | /// Precision-based calculator for distance between two times
8 | ///
9 | public class PrecisionDateTimeHumanizeStrategy : IDateTimeHumanizeStrategy
10 | {
11 | private readonly double _precision;
12 |
13 | ///
14 | /// Constructs a precision-based calculator for distance of time with default precision 0.75.
15 | ///
16 | /// precision of approximation, if not provided 0.75 will be used as a default precision.
17 | public PrecisionDateTimeHumanizeStrategy(double precision = .75)
18 | {
19 | _precision = precision;
20 | }
21 |
22 | ///
23 | /// Returns localized & humanized distance of time between two dates; given a specific precision.
24 | ///
25 | public string Humanize(DateTime input, DateTime comparisonBase, CultureInfo culture)
26 | {
27 | return DateTimeHumanizeAlgorithms.PrecisionHumanize(input, comparisonBase, _precision, culture);
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.cs:
--------------------------------------------------------------------------------
1 | #if NET46
2 | using System.IO;
3 | using ApiApprover;
4 | using ApprovalTests;
5 | using ApprovalTests.Reporters;
6 | using Mono.Cecil;
7 | using Xunit;
8 |
9 | namespace Humanizer.Tests.ApiApprover
10 | {
11 |
12 | public class PublicApiApprovalTest
13 | {
14 | [Fact]
15 | [UseCulture("en-US")]
16 | [UseReporter(typeof(DiffReporter))]
17 | [IgnoreLineEndings(true)]
18 | public void approve_public_api()
19 | {
20 | var assemblyPath = typeof(StringHumanizeExtensions).Assembly.Location;
21 |
22 | var assemblyResolver = new DefaultAssemblyResolver();
23 | assemblyResolver.AddSearchDirectory(Path.GetDirectoryName(assemblyPath));
24 |
25 | var readSymbols = File.Exists(Path.ChangeExtension(assemblyPath, ".pdb"));
26 | var asm = AssemblyDefinition.ReadAssembly(assemblyPath, new ReaderParameters(ReadingMode.Deferred)
27 | {
28 | ReadSymbols = readSymbols,
29 | AssemblyResolver = assemblyResolver
30 | });
31 |
32 | var publicApi = PublicApiGenerator.CreatePublicApiForAssembly(asm);
33 | Approvals.Verify(publicApi);
34 | }
35 | }
36 | }
37 | #endif
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Shared/BitFieldEnumUnderTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.ComponentModel.DataAnnotations;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace Humanizer.Tests
10 | {
11 | [Flags]
12 | public enum BitFieldEnumUnderTest : int
13 | {
14 | [Display( Description = BitFlagEnumTestsResources.MemberWithSingleWordDisplayAttribute)]
15 | RED = 1,
16 | [Display( Description = BitFlagEnumTestsResources.MemberWithMultipleWordDisplayAttribute)]
17 | DARK_GRAY = 2
18 | }
19 |
20 | [Flags]
21 | public enum ShortBitFieldEnumUnderTest : short
22 | {
23 | [Display( Description = BitFlagEnumTestsResources.MemberWithSingleWordDisplayAttribute)]
24 | RED = 1,
25 | [Display( Description = BitFlagEnumTestsResources.MemberWithMultipleWordDisplayAttribute)]
26 | DARK_GRAY = 2
27 | }
28 |
29 | public class BitFlagEnumTestsResources
30 | {
31 | public const string MemberWithSingleWordDisplayAttribute = "Red";
32 | public const string MemberWithMultipleWordDisplayAttribute = "Dark Gray";
33 |
34 | public const string ExpectedResultWhenBothValuesXored = "Red and Dark Gray";
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/Ordinalizers/RomanianOrdinalizer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace Humanizer.Localisation.Ordinalizers
5 | {
6 |
7 | internal class RomanianOrdinalizer : DefaultOrdinalizer
8 | {
9 | public override string Convert(int number, string numberString)
10 | {
11 | return Convert(number, numberString, GrammaticalGender.Masculine);
12 | }
13 |
14 | public override string Convert(int number, string numberString, GrammaticalGender gender)
15 | {
16 | // No ordinal for 0 (zero) in Romanian.
17 | if (number == 0)
18 | {
19 | return "0";
20 | }
21 |
22 | // Exception from the rule.
23 | if (number == 1)
24 | {
25 | if (gender == GrammaticalGender.Feminine)
26 | {
27 | return "prima"; // întâia
28 | }
29 |
30 | return "primul"; // întâiul
31 | }
32 |
33 | if (gender == GrammaticalGender.Feminine)
34 | {
35 | return string.Format("a {0}-a", numberString);
36 | }
37 |
38 | return string.Format("al {0}-lea", numberString);
39 |
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Shared/Localisation/invariant/NumberToWordsTests.cs:
--------------------------------------------------------------------------------
1 | using System.Globalization;
2 | using Xunit;
3 |
4 | namespace Humanizer.Tests.Localisation.invariant
5 | {
6 | [UseCulture("")]
7 | public class NumberToWordsTests
8 | {
9 |
10 | [Theory]
11 | [InlineData(1)]
12 | [InlineData(10)]
13 | [InlineData(11)]
14 | [InlineData(122)]
15 | [InlineData(3501)]
16 | [InlineData(100)]
17 | [InlineData(1000)]
18 | [InlineData(100000)]
19 | [InlineData(1000000)]
20 | [InlineData(10000000)]
21 | [InlineData(100000000)]
22 | [InlineData(1000000000)]
23 | [InlineData(111)]
24 | [InlineData(1111)]
25 | [InlineData(111111)]
26 | [InlineData(1111111)]
27 | [InlineData(11111111)]
28 | [InlineData(111111111)]
29 | [InlineData(1111111111)]
30 | [InlineData(123)]
31 | [InlineData(1234)]
32 | [InlineData(12345)]
33 | [InlineData(123456)]
34 | [InlineData(1234567)]
35 | [InlineData(12345678)]
36 | [InlineData(123456789)]
37 | [InlineData(1234567890)]
38 | public void ToWords(int number)
39 | {
40 | Assert.Equal(number.ToString(), number.ToWords());
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/NumberToWords/DefaultNumberToWordsConverter.cs:
--------------------------------------------------------------------------------
1 | using System.Globalization;
2 |
3 | namespace Humanizer.Localisation.NumberToWords
4 | {
5 | internal class DefaultNumberToWordsConverter : GenderlessNumberToWordsConverter
6 | {
7 | private readonly CultureInfo _culture;
8 |
9 | ///
10 | /// Constructor.
11 | ///
12 | /// Culture to use.
13 | public DefaultNumberToWordsConverter(CultureInfo culture)
14 | {
15 | _culture = culture;
16 | }
17 |
18 | ///
19 | /// 3501.ToWords() -> "three thousand five hundred and one"
20 | ///
21 | /// Number to be turned to words
22 | ///
23 | public override string Convert(long number)
24 | {
25 | return number.ToString(_culture);
26 | }
27 |
28 | ///
29 | /// 1.ToOrdinalWords() -> "first"
30 | ///
31 | /// Number to be turned to ordinal words
32 | ///
33 | public override string ConvertToOrdinal(int number)
34 | {
35 | return number.ToString(_culture);
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/src/Humanizer/DateTimeHumanizeStrategy/PrecisionDateTimeOffsetHumanizeStrategy.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 |
4 | namespace Humanizer.DateTimeHumanizeStrategy
5 | {
6 | ///
7 | /// Precision-based calculator for distance between two times
8 | ///
9 | public class PrecisionDateTimeOffsetHumanizeStrategy : IDateTimeOffsetHumanizeStrategy
10 | {
11 | private readonly double _precision;
12 |
13 | ///
14 | /// Constructs a precision-based calculator for distance of time with default precision 0.75.
15 | ///
16 | /// precision of approximation, if not provided 0.75 will be used as a default precision.
17 | public PrecisionDateTimeOffsetHumanizeStrategy(double precision = .75)
18 | {
19 | _precision = precision;
20 | }
21 |
22 | ///
23 | /// Returns localized & humanized distance of time between two dates; given a specific precision.
24 | ///
25 | public string Humanize(DateTimeOffset input, DateTimeOffset comparisonBase, CultureInfo culture)
26 | {
27 | return DateTimeHumanizeAlgorithms.PrecisionHumanize(input.UtcDateTime, comparisonBase.UtcDateTime, _precision, culture);
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/src/Humanizer/DateToOrdinalWordsExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using Humanizer.Configuration;
4 |
5 | namespace Humanizer
6 | {
7 | ///
8 | /// Humanizes DateTime into human readable sentence
9 | ///
10 | public static class DateToOrdinalWordsExtensions
11 | {
12 | ///
13 | /// Turns the provided date into ordinal words
14 | ///
15 | /// The date to be made into ordinal words
16 | /// The date in ordinal words
17 | public static string ToOrdinalWords(this DateTime input)
18 | {
19 | return Configurator.DateToOrdinalWordsConverter.Convert(input);
20 | }
21 | ///
22 | /// Turns the provided date into ordinal words
23 | ///
24 | /// The date to be made into ordinal words
25 | /// The grammatical case to use for output words
26 | /// The date in ordinal words
27 | public static string ToOrdinalWords(this DateTime input, GrammaticalCase grammaticalCase)
28 | {
29 | return Configurator.DateToOrdinalWordsConverter.Convert(input, grammaticalCase);
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Humanizer/StringExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Humanizer
4 | {
5 | ///
6 | /// Extension methods for String type.
7 | ///
8 | public static class StringExtensions
9 | {
10 | ///
11 | /// Extension method to format string with passed arguments. Current thread's current culture is used
12 | ///
13 | /// string format
14 | /// arguments
15 | ///
16 | public static string FormatWith(this string format, params object[] args)
17 | {
18 | return string.Format(format, args);
19 | }
20 |
21 | ///
22 | /// Extension method to format string with passed arguments using specified format provider (i.e. CultureInfo)
23 | ///
24 | /// string format
25 | /// An object that supplies culture-specific formatting information
26 | /// arguments
27 | ///
28 | public static string FormatWith(this string format, IFormatProvider provider, params object[] args)
29 | {
30 | return string.Format(provider, format, args);
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Humanizer/Humanizer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | netstandard1.0
4 | Mehdi Khalili, Oren Novotny
5 | https://raw.githubusercontent.com/Humanizr/Humanizer/master/LICENSE
6 | https://github.com/Humanizr/Humanizer
7 | 2.12
8 | A micro-framework that turns your normal strings, type names, enum fields, date fields ETC into a human friendly format
9 | Copyright © 2012-2017 Mehdi Khalili
10 | Humanizer ($(TargetFramework))
11 | true
12 | true
13 | Humanizer.snk
14 | embedded
15 | latest
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/samples/Humanizer.MvcSample/Views/Home/Contact.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | ViewBag.Title = "Contact";
3 | }
4 |
5 |
6 | @ViewBag.Title.
7 | @ViewBag.Message
8 |
9 |
10 |
23 |
24 |
41 |
42 |
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Uwp/Properties/UnitTestApp.rd.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/samples/Humanizer.MvcSample/Web.Debug.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
17 |
18 |
29 |
30 |
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Uwp.Runner/Properties/Default.rd.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/samples/Humanizer.MvcSample/Web.Release.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
17 |
18 |
19 |
30 |
31 |
--------------------------------------------------------------------------------
/samples/Humanizer.MvcSample/Views/Account/Login.cshtml:
--------------------------------------------------------------------------------
1 | @model Humanizer.MvcSample.Models.LoginModel
2 |
3 | @{
4 | ViewBag.Title = "Log in";
5 | }
6 |
7 |
8 | @ViewBag.Title.
9 | Enter your user name and password below.
10 |
11 |
12 |
13 |
14 |
15 | @using (Html.BeginForm((string)ViewBag.FormAction, "Account")) {
16 | @Html.ValidationSummary(true, "Log in was unsuccessful. Please correct the errors and try again.")
17 |
18 |
38 |
39 | @Html.ActionLink("Register", "Register") if you don't have an account.
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/ResourceKeys.TimeSpanHumanize.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer.Localisation
2 | {
3 | public partial class ResourceKeys
4 | {
5 | ///
6 | /// Encapsulates the logic required to get the resource keys for TimeSpan.Humanize
7 | ///
8 | public static class TimeSpanHumanize
9 | {
10 | ///
11 | /// Examples: TimeSpanHumanize_SingleMinute, TimeSpanHumanize_MultipleHours.
12 | /// Note: "s" for plural served separately by third part.
13 | ///
14 | private const string TimeSpanFormat = "TimeSpanHumanize_{0}{1}{2}";
15 | private const string Zero = "TimeSpanHumanize_Zero";
16 |
17 | ///
18 | /// Generates Resource Keys according to convention.
19 | ///
20 | /// Time unit, .
21 | /// Number of units, default is One.
22 | /// Resource key, like TimeSpanHumanize_SingleMinute
23 | public static string GetResourceKey(TimeUnit unit, int count = 1)
24 | {
25 | ValidateRange(count);
26 |
27 | if (count == 0)
28 | return Zero;
29 |
30 | return TimeSpanFormat.FormatWith(count == 1 ? Single : Multiple, unit, count == 1 ? "" : "s");
31 | }
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/samples/Humanizer.MvcSample/Content/themes/base/jquery.ui.accordion.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Note: While Microsoft is not the author of this file, Microsoft is
3 | * offering you a license subject to the terms of the Microsoft Software
4 | * License Terms for Microsoft ASP.NET Model View Controller 4 Developer Preview.
5 | * Microsoft reserves all other rights. The notices below are provided
6 | * for informational purposes only and are not the license terms under
7 | * which Microsoft distributed this file.
8 | *
9 | * jQuery UI Accordion 1.8.11
10 | *
11 | * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
12 | *
13 | * http://docs.jquery.com/UI/Accordion#theming
14 | */
15 | /* IE/Win - Fix animation bug - #4615 */
16 | .ui-accordion { width: 100%; }
17 | .ui-accordion .ui-accordion-header { cursor: pointer; position: relative; margin-top: 1px; zoom: 1; }
18 | .ui-accordion .ui-accordion-li-fix { display: inline; }
19 | .ui-accordion .ui-accordion-header-active { border-bottom: 0 !important; }
20 | .ui-accordion .ui-accordion-header a { display: block; font-size: 1em; padding: .5em .5em .5em .7em; }
21 | .ui-accordion-icons .ui-accordion-header a { padding-left: 2.2em; }
22 | .ui-accordion .ui-accordion-header .ui-icon { position: absolute; left: .5em; top: 50%; margin-top: -8px; }
23 | .ui-accordion .ui-accordion-content { padding: 1em 2.2em; border-top: 0; margin-top: -2px; position: relative; top: 1px; margin-bottom: 2px; overflow: auto; display: none; zoom: 1; }
24 | .ui-accordion .ui-accordion-content-active { display: block; }
25 |
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Shared/StringExtensionsTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using Xunit;
4 |
5 | namespace Humanizer.Tests
6 | {
7 | public class StringExtensionsTests
8 | {
9 | private const string Format = "This is a format with three numbers: {0}-{1}-{2}.";
10 | private const string Expected = "This is a format with three numbers: 1-2-3.";
11 |
12 | [Fact]
13 | public void CanFormatStringWithExactNumberOfArguments()
14 | {
15 | Assert.Equal(Expected, Format.FormatWith(1, 2, 3));
16 | }
17 |
18 | [Fact]
19 | public void CanFormatStringWithMoreArguments()
20 | {
21 | Assert.Equal(Expected, Format.FormatWith(1, 2, 3, 4, 5));
22 | }
23 |
24 | [Fact]
25 | public void CannotFormatStringWithLessArguments()
26 | {
27 | Assert.Throws(() => Format.FormatWith(1, 2));
28 | }
29 |
30 | [Fact]
31 | public void FormatCannotBeNull()
32 | {
33 | string format = null;
34 | Assert.Throws(() => format.FormatWith(1, 2));
35 | }
36 |
37 | [Theory]
38 | [InlineData("en-US", "6,666.66")]
39 | [InlineData("ru-RU", "6 666,66")]
40 | public void CanSpecifyCultureExplicitly(string culture, string expected)
41 | {
42 | Assert.Equal(expected, "{0:N2}".FormatWith(new CultureInfo(culture), 6666.66));
43 | }
44 | }
45 | }
--------------------------------------------------------------------------------
/src/Humanizer.Tests/Humanizer.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | net46;netcoreapp1.1
4 |
5 |
6 |
7 | $(DefineConstants);NETFX_CORE
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | %(RecursiveDir)%(Filename)%(Extension)
23 |
24 |
25 |
26 |
27 |
28 | PreserveNewest
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/samples/Humanizer.MvcSample/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Humanizer.MvcSample")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Humanizer.MvcSample")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("d6f0a3c8-d4d2-4adf-8480-2689e4f83154")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Revision and Build Numbers
33 | // by using the '*' as shown below:
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/CollectionFormatters/ICollectionFormatter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace Humanizer.Localisation.CollectionFormatters
5 | {
6 | ///
7 | /// An interface you should implement to localize Humanize for collections
8 | ///
9 | public interface ICollectionFormatter
10 | {
11 | ///
12 | /// Formats the collection for display, calling ToString() on each object.
13 | ///
14 | ///
15 | string Humanize(IEnumerable collection);
16 |
17 | ///
18 | /// Formats the collection for display, calling `objectFormatter` on each object.
19 | ///
20 | ///
21 | string Humanize(IEnumerable collection, Func objectFormatter);
22 |
23 | ///
24 | /// Formats the collection for display, calling ToString() on each object
25 | /// and using `separator` before the final item.
26 | ///
27 | ///
28 | string Humanize(IEnumerable collection, string separator);
29 |
30 | ///
31 | /// Formats the collection for display, calling `objectFormatter` on each object
32 | /// and using `separator` before the final item.
33 | ///
34 | ///
35 | string Humanize(IEnumerable collection, Func objectFormatter, string separator);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/NumberToWords/INumberToWordsConverter.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer.Localisation.NumberToWords
2 | {
3 | ///
4 | /// An interface you should implement to localise ToWords and ToOrdinalWords methods
5 | ///
6 | public interface INumberToWordsConverter
7 | {
8 | ///
9 | /// Converts the number to string using the locale's default grammatical gender
10 | ///
11 | ///
12 | ///
13 | string Convert(long number);
14 |
15 | ///
16 | /// Converts the number to string using the provided grammatical gender
17 | ///
18 | ///
19 | ///
20 | ///
21 | string Convert(long number, GrammaticalGender gender);
22 |
23 | ///
24 | /// Converts the number to ordinal string using the locale's default grammatical gender
25 | ///
26 | ///
27 | ///
28 | string ConvertToOrdinal(int number);
29 |
30 | ///
31 | /// Converts the number to ordinal string using the provided grammatical gender
32 | ///
33 | ///
34 | ///
35 | ///
36 | string ConvertToOrdinal(int number, GrammaticalGender gender);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Humanizer/Localisation/NumberToWords/GenderlessNumberToWordsConverter.cs:
--------------------------------------------------------------------------------
1 | namespace Humanizer.Localisation.NumberToWords
2 | {
3 | abstract class GenderlessNumberToWordsConverter : INumberToWordsConverter
4 | {
5 | ///
6 | /// Converts the number to string
7 | ///
8 | ///
9 | ///
10 | public abstract string Convert(long number);
11 |
12 | ///
13 | /// Converts the number to string ignoring the provided grammatical gender
14 | ///
15 | ///
16 | ///
17 | ///
18 | public string Convert(long number, GrammaticalGender gender)
19 | {
20 | return Convert(number);
21 | }
22 |
23 | ///
24 | /// Converts the number to ordinal string
25 | ///
26 | ///
27 | ///
28 | public abstract string ConvertToOrdinal(int number);
29 |
30 | ///
31 | /// Converts the number to ordinal string ignoring the provided grammatical gender
32 | ///
33 | ///
34 | ///
35 | ///
36 | public string ConvertToOrdinal(int number, GrammaticalGender gender)
37 | {
38 | return ConvertToOrdinal(number);
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Shared/EnumHumanizeWithCustomDescriptionPropertyNamesTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Humanizer.Configuration;
3 | using Xunit;
4 |
5 | namespace Humanizer.Tests
6 | {
7 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly",
8 | Justification = "This is a test only class, and doesn't need a 'proper' IDisposable implementation.")]
9 | public class EnumHumanizeWithCustomDescriptionPropertyNamesTests : IDisposable
10 | {
11 | public EnumHumanizeWithCustomDescriptionPropertyNamesTests()
12 | {
13 | Configurator.EnumDescriptionPropertyLocator = p => p.Name == "Info";
14 | }
15 |
16 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly",
17 | Justification = "This is a test only class, and doesn't need a 'proper' IDisposable implementation.")]
18 | public void Dispose()
19 | {
20 | Configurator.EnumDescriptionPropertyLocator = null;
21 | }
22 |
23 | [Fact]
24 | public void HonorsCustomPropertyAttribute()
25 | {
26 | Assert.Equal(EnumTestsResources.MemberWithCustomPropertyAttribute, EnumUnderTest.MemberWithCustomPropertyAttribute.Humanize());
27 | }
28 |
29 | [Fact]
30 | public void CanHumanizeMembersWithoutDescriptionAttribute()
31 | {
32 | Assert.Equal(EnumTestsResources.MemberWithoutDescriptionAttributeSentence, EnumUnderTest.MemberWithoutDescriptionAttribute.Humanize());
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/samples/Humanizer.MvcSample/Content/themes/base/jquery.ui.slider.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Note: While Microsoft is not the author of this file, Microsoft is
3 | * offering you a license subject to the terms of the Microsoft Software
4 | * License Terms for Microsoft ASP.NET Model View Controller 4 Developer Preview.
5 | * Microsoft reserves all other rights. The notices below are provided
6 | * for informational purposes only and are not the license terms under
7 | * which Microsoft distributed this file.
8 | *
9 | * jQuery UI Slider 1.8.11
10 | *
11 | * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
12 | *
13 | * http://docs.jquery.com/UI/Slider#theming
14 | */
15 | .ui-slider { position: relative; text-align: left; }
16 | .ui-slider .ui-slider-handle { position: absolute; z-index: 2; width: 1.2em; height: 1.2em; cursor: default; }
17 | .ui-slider .ui-slider-range { position: absolute; z-index: 1; font-size: .7em; display: block; border: 0; background-position: 0 0; }
18 |
19 | .ui-slider-horizontal { height: .8em; }
20 | .ui-slider-horizontal .ui-slider-handle { top: -.3em; margin-left: -.6em; }
21 | .ui-slider-horizontal .ui-slider-range { top: 0; height: 100%; }
22 | .ui-slider-horizontal .ui-slider-range-min { left: 0; }
23 | .ui-slider-horizontal .ui-slider-range-max { right: 0; }
24 |
25 | .ui-slider-vertical { width: .8em; height: 100px; }
26 | .ui-slider-vertical .ui-slider-handle { left: -.3em; margin-left: 0; margin-bottom: -.6em; }
27 | .ui-slider-vertical .ui-slider-range { left: 0; width: 100%; }
28 | .ui-slider-vertical .ui-slider-range-min { bottom: 0; }
29 | .ui-slider-vertical .ui-slider-range-max { top: 0; }
--------------------------------------------------------------------------------
/src/Humanizer.Tests.Shared/Localisation/hr/TimeSpanHumanizeTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Xunit;
3 |
4 | namespace Humanizer.Tests.Localisation.hr
5 | {
6 | [UseCulture("hr-HR")]
7 | public class TimeSpanHumanizeTests
8 | {
9 |
10 | [Theory]
11 | [Trait("Translation", "Google")]
12 | [InlineData(366, "1 godina")]
13 | [InlineData(731, "2 godine")]
14 | [InlineData(1096, "3 godine")]
15 | [InlineData(4018, "11 godina")]
16 | public void Years(int days, string expected)
17 | {
18 | Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year));
19 | }
20 |
21 | [Theory]
22 | [Trait("Translation", "Google")]
23 | [InlineData(31, "1 mjesec")]
24 | [InlineData(61, "2 mjeseca")]
25 | [InlineData(92, "3 mjeseca")]
26 | [InlineData(335, "11 mjeseci")]
27 | public void Months(int days, string expected)
28 | {
29 | Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: Humanizer.Localisation.TimeUnit.Year));
30 | }
31 |
32 | [Theory]
33 | [InlineData(1, "1 dan")]
34 | [InlineData(2, "2 dana")]
35 | [InlineData(3, "3 dana")]
36 | [InlineData(4, "4 dana")]
37 | [InlineData(5, "5 dana")]
38 | [InlineData(7, "1 tjedan")]
39 | [InlineData(14, "2 tjedna")]
40 | public void Days(int days, string expected)
41 | {
42 | Assert.Equal(expected, TimeSpan.FromDays(days).Humanize());
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/samples/Humanizer.MvcSample/Content/themes/base/jquery.ui.resizable.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Note: While Microsoft is not the author of this file, Microsoft is
3 | * offering you a license subject to the terms of the Microsoft Software
4 | * License Terms for Microsoft ASP.NET Model View Controller 4 Developer Preview.
5 | * Microsoft reserves all other rights. The notices below are provided
6 | * for informational purposes only and are not the license terms under
7 | * which Microsoft distributed this file.
8 | *
9 | * jQuery UI Resizable 1.8.11
10 | *
11 | * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)]
12 | *
13 | * http://docs.jquery.com/UI/Resizable#theming
14 | */
15 | .ui-resizable { position: relative;}
16 | .ui-resizable-handle { position: absolute;font-size: 0.1px;z-index: 99999; display: block;}
17 | .ui-resizable-disabled .ui-resizable-handle, .ui-resizable-autohide .ui-resizable-handle { display: none; }
18 | .ui-resizable-n { cursor: n-resize; height: 7px; width: 100%; top: -5px; left: 0; }
19 | .ui-resizable-s { cursor: s-resize; height: 7px; width: 100%; bottom: -5px; left: 0; }
20 | .ui-resizable-e { cursor: e-resize; width: 7px; right: -5px; top: 0; height: 100%; }
21 | .ui-resizable-w { cursor: w-resize; width: 7px; left: -5px; top: 0; height: 100%; }
22 | .ui-resizable-se { cursor: se-resize; width: 12px; height: 12px; right: 1px; bottom: 1px; }
23 | .ui-resizable-sw { cursor: sw-resize; width: 9px; height: 9px; left: -5px; bottom: -5px; }
24 | .ui-resizable-nw { cursor: nw-resize; width: 9px; height: 9px; left: -5px; top: -5px; }
25 | .ui-resizable-ne { cursor: ne-resize; width: 9px; height: 9px; right: -5px; top: -5px;}
--------------------------------------------------------------------------------
/samples/Humanizer.MvcSample/HumanizerMetadataProvider.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.ComponentModel.DataAnnotations;
5 | using System.Linq;
6 | using System.Web.Mvc;
7 |
8 | namespace Humanizer.MvcSample
9 | {
10 | public class HumanizerMetadataProvider : DataAnnotationsModelMetadataProvider
11 | {
12 | protected override ModelMetadata CreateMetadata(
13 | IEnumerable attributes,
14 | Type containerType,
15 | Func