Allow outputting the key itself (without "Key: ") if missing from localization dictionary
Opened this issue · 7 comments
Hello,
Many times there're texts coming from a remote system, then you would want to localize if possible (by using the text as key) else if it doesn't exist as key - output it as is (without the "Key: " prefix).
I don't see an easy workaround, will be very helpful to add this property per usage (and not in dictionary instance etc.):
if (!OutputKeyAsFallback)
{
if (LocalizeDictionary.Instance.OutputMissingKeys
&& !string.IsNullOrEmpty(_key) && (targetType == typeof(String) || targetType == typeof(object)))
{
if (missingKeyEventResult.MissingKeyResult != null)
result = missingKeyEventResult.MissingKeyResult;
else
result = "Key: " + _key;
}
}
else
{
result = _key;
}
Thank you for this amazing package.
Hello, @superware!
You can try to use LocalizeDictionary.Instance.MissingKeyEvent
. Here the sample how you can set any string what you want:
WPFLocalizeExtension/tests/HelloWorldWPF/MainWindow.xaml.cs
Lines 49 to 52 in 3b350eb
Hi @Karnah!
Your suggestion is per dictionary (and requires coding), what about per usage?
<StackPanel>
<TextBlock Text="{lex:Loc Product_name}" />
<TextBlock Text="{lex:Loc {Binding Item.ProductName}, OutputKeyAsFallback=True}" />
</StackPanel>
It's a very powerful feature. You're not always localizing known/static strings, sometimes you have a string (usually from an external source) which you might have localized, but if not then your only true fallback is the string itself.
This should be a simple non-breaking feature...
Thanks!
I see here three possible ways:
- Add just property
OutputKeyAsFallback
. This is quick and easy - Add property and enum
FallbackBehavior
. Possible values: Default ("Key: " + _key
), Key (_key
), EmptyString (string.Emty
). It's also easy and a bit more flexible. - Add property
FallbackValue
. It can be really hard, because it should supportBinding
. But it can be really powerful feature.
@konne , @superware, what do you think?
Hello, @superware.
I have some ideas about refactoring XAMLMarkupExtensions
which will allow implementing the third option. I think it's the beast solution, because it's the most powerful feature.
If it doesn't work, I'll try to implement the first or second way.
Thanks!
Hello, @superware.
I'm so sorry, I didn't have time to implement the third solution. And I really don't know when I can do it.
I hope I can create PR with the first or second solution on next week. I thinks it's the best way now.