turquoiseowl / i18n

Smart internationalization for ASP.NET
Other
556 stars 156 forks source link

NullReference Exception if an underscore is used when specificing available languages. #393

Closed estebes closed 3 years ago

estebes commented 4 years ago

When specifying available languages using underscores

<add key="i18n.AvailableLanguages" value="de_DE;en_US;" />

An exception is thrown the first a web page is opened

[NullReferenceException: Object reference not set to an instance of an object.]
   i18n.LanguageTag.Equals(String other) +16
   i18n.TextLocalizer.<GetAppLanguages>b__2(String x) +23
   System.Linq.Enumerable.Any(IEnumerable`1 source, Func`2 predicate) +148
   i18n.TextLocalizer.GetAppLanguages() +505
   i18n.TextLocalizer.GetText(String msgid, String msgcomment, LanguageItem[] languages, LanguageTag& o_langtag, Int32 maxPasses) +112
   i18n.LanguageHelpers.GetMatchingAppLanguage(LanguageItem[] languages, Int32 maxPasses) +53
   i18n.HttpContextExtensions.GetInferredLanguage(HttpContextBase context) +104
   i18n.LocalizingModule.OnBeginRequest(Object sender, EventArgs e) +92
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +144
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +50
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +73

Changing the specified available languages to use a dash solves the problem

<add key="i18n.AvailableLanguages" value="de-DE;en-US;" />

Although this is not a big issue it is annoying for people like me that are used to use the underscore when choosing a name for lang file (en_US, pt_PT, de_DE, etc)

vhatuncev commented 4 years ago

Hello @estebes can you please elaborate the reason you use underscores instead of dashes? Something or someone push you to do way like that?

A bit of background. I would say using dashes is more like requirement. Values from i18n.AvailableLanguages key are parsed with strict rules defined here and then used here. These rules based on general naming conventions for language tags

vhatuncev commented 3 years ago

@turquoiseowl I think this issue can be closed as no response from @estebes and reasons to use underscores unclear.

turquoiseowl commented 3 years ago

OK, closing. Please re-open is still an issue.