Not found localizations should return the key
Compufreak345 opened this issue · 4 comments
Regarding to the MSDN not found keys should return the key and not throw an exception:
If the localized value of "About Title" isn't found, then the indexer key is returned, that is, the string "About Title".
Hi,
As I know, this behavior is implemented is the plugins.
- Look for the current language
- Look for the parent language
- Look for the default language
- Return the key
So if you are looking for a key in en-GB and fr-FR was the default, it should process in this way :
- Search key in en-GB values
- Search key in en values
- Search key in fr-FR values
- Return the key
I will check if is implemented in this way on code, let me know if you already focus the code :)
Thanks for the fast response - You are correct, the behavior is correct for normal strings - but for pluralized strings there is an issue which can be reproduced by deleting the "Users"-mapping from both localization files in TestSample. It will cause a NullPointerException:
System.Linq.Enumerable.Contains<TSource>(IEnumerable<TSource> source, TSource value, IEqualityComparer<TSource> comparer)
Askmethat.Aspnet.JsonLocalizer.Localizer.JsonStringLocalizer.GetPluralLocalization(string name, string format, object[] arguments) in JsonStringLocalizer.cs
+
if (value.Contains(LocalizationOptions.Value.PluralSeparator))
Askmethat.Aspnet.JsonLocalizer.Localizer.JsonStringLocalizer.get_Item(string name, object[] arguments) in JsonStringLocalizer.cs
+
string value = GetPluralLocalization(name, format, arguments);
Microsoft.AspNetCore.Mvc.Localization.HtmlLocalizer.GetString(string name, object[] arguments)
Microsoft.AspNetCore.Mvc.Localization.ViewLocalizer.GetString(string name, object[] values)
AspNetCore.Views_Home_Index.ExecuteAsync() in Index.cshtml
+
<span>@Localizer.GetString("Users", true) </span>
This can be fixed by changing line 57 to check for null-strings:
if (value != null && value.Contains(LocalizationOptions.Value.PluralSeparator))
FYI: I am currently at a deep dive in your code and will try to cherry pick some fixes for PRs to your repository when I'm done, but I won't promise it yet as I am a bit in a hurry and I do some style changes as well that might not be appropriate for your repository so those need to be cleaned up - I've got vacation next week and need to get this project finished, but I'll try to keep you updated. Feel free to give me an opinion on what I am doing there right now:
master...Compufreak345:master
Hi,
Thanks for your contribution. I already did notice that some time's pluralization throw an exception, but I have some work to be done before resuming development of the version 2.1.0.
I will have a look to your changes at lunch times and back to you :)
You can have a look to development...Compufreak345:master