-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resource key without suffix ".content", ".text" etc. #39
Comments
Hi @Pietro228 ! You can get a localized string using the string localizedText = WinUI3Localizer.Localizer.Get().GetLocalizedString("SomeUid"); and if you need to update the text when the selected language is changed, you can use the public SomePage()
{
InitializeComponent();
WinUI3Localizer.Localizer.Get().LanguageChanged += OnLanguageChanged;
}
private void OnLanguageChanged(object? sender, LanguageChangedEventArgs e)
{
string localizedText = WinUI3Localizer.Localizer.Get().GetLocalizedString("SomeUid");
} |
Thanks for the suggestion. I guess there are 2 considerable options here:
I'm afraid, I'm going to need time to think about this. |
The first one would be easier to understand, but the second one is shorter and faster to write. My opinion is that it's better to go with the 2nd option. Btw. Interesting post. I didn't know that some people already wanted to make it easier |
Any news about this? :D |
I'm not sure if I can find time to consider and implement this anytime soon. 😵 |
That's OK :D For now I'll just prompt the user to restart the app. |
I don't understand. If you have access to the target element, you should be able to localize strings. The new feature about extending the |
I'm able to localize them, but only by naming the keys like this |
By the way, you can still use the WinUI3Localizer in your markup extension: [MarkupExtensionReturnType(ReturnType = typeof(string))]
public class LocalizedString : MarkupExtension
{
public string Key { get; set; } = string.Empty;
protected override object ProvideValue() => Localizer.Get().GetLocalizedString(Key);
} or you can also do this with a simple helper class: public static class WinUI3LocalizerHelper
{
public static string GetLocalizedString(string key)
{
return Localizer.Get().GetLocalizedString(key);
}
} <TextBlock Text="{x:Bind local:WinUI3LocalizerHelper.GetLocalizedString('SomeKey')}" /> |
I know, you already told me about it here #39 (comment). But I still need to restart the app to change the language |
@Pietro228 In order to keep consistentcy with |
Reopening this for v3. |
@AndrewKeepCoding Any news? 🤔 |
Sorry for the delay. I just published v2.3.0-alpha. Can you give it a try if it works for your requirements? |
Hi,
is there any way to use keys without the suffix? I would like to use a highly used word in more controls, but without creating two variants ".Content" and ".Text".
The text was updated successfully, but these errors were encountered: