From 92f76a4d36b44f22caf51e8066b787288595ad36 Mon Sep 17 00:00:00 2001 From: Claire Novotny Date: Wed, 5 May 2021 09:17:35 -0400 Subject: [PATCH] Add try/catch around formatter registration to handle OS's that don't support a particular culture. --- src/Humanizer/Configuration/FormatterRegistry.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Humanizer/Configuration/FormatterRegistry.cs b/src/Humanizer/Configuration/FormatterRegistry.cs index da6839ad4..9970c6a21 100644 --- a/src/Humanizer/Configuration/FormatterRegistry.cs +++ b/src/Humanizer/Configuration/FormatterRegistry.cs @@ -1,4 +1,6 @@ -using Humanizer.Localisation.Formatters; +using System.Globalization; + +using Humanizer.Localisation.Formatters; namespace Humanizer.Configuration { @@ -56,7 +58,14 @@ public FormatterRegistry() : base(new DefaultFormatter("en-US")) private void RegisterDefaultFormatter(string localeCode) { - Register(localeCode, new DefaultFormatter(localeCode)); + try + { + Register(localeCode, new DefaultFormatter(localeCode)); + } + catch (CultureNotFoundException) + { + // Some OS's may not support the particular culture. Not much we can do for those. + } } private void RegisterCzechSlovakPolishFormatter(string localeCode)