Giter Club home page Giter Club logo

Comments (20)

Pietro228 avatar Pietro228 commented on September 27, 2024 1

Btw. Is there any way that you could make it so that I can specify which property should receive my translated string? Something like this: <NavigationViewItem l:Uids.Uid="Dashboard" l:Uids.Target="Content"/>

I'm asking you because using MarkupExtension doesn't support updating value and it always shows me an error, but it builds without any problems :D
obrazek

from winui3localizer.

AndrewKeepCoding avatar AndrewKeepCoding commented on September 27, 2024 1

Reopening this for v3.

from winui3localizer.

Pietro228 avatar Pietro228 commented on September 27, 2024

I can make it work by using a resource loader, but it doesn't update runtime and you have to restart the app :/

obrazek
obrazek

Would it be possible to create something like this? It's really time consuming to use the suffixes

from winui3localizer.

AndrewKeepCoding avatar AndrewKeepCoding commented on September 27, 2024

Hi @Pietro228 !

You can get a localized string using the GetLocalizedString method:

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 OnLanguageChanged event:

public SomePage()
{
    InitializeComponent();
    WinUI3Localizer.Localizer.Get().LanguageChanged += OnLanguageChanged;
}

private void OnLanguageChanged(object? sender, LanguageChangedEventArgs e)
{
    string localizedText = WinUI3Localizer.Localizer.Get().GetLocalizedString("SomeUid");
}

from winui3localizer.

Pietro228 avatar Pietro228 commented on September 27, 2024

Thank you for your help, but it always returns "null" :/

I have only replaced the resourceLoader.GetString(Name); for your method.
obrazek

from winui3localizer.

Pietro228 avatar Pietro228 commented on September 27, 2024

I found the issue. It did not copy new string resource files.

This should be InstalledWidgets not MainWindow_InstalledWidgets.Content
obrazek

from winui3localizer.

Pietro228 avatar Pietro228 commented on September 27, 2024

This condition is not that good for prototyping, because it doesn't copy your resource files. I wasn't paying attention to that code when I was trying your plugin, but now when I was looking at the code, I found it. You should mention it in your usage documentation.

obrazek

from winui3localizer.

AndrewKeepCoding avatar AndrewKeepCoding commented on September 27, 2024

Thanks for the suggestion. I guess there are 2 considerable options here:

  1. Add l:Uids.Target:

    <NavigationViewItem l:Uids.Uid="SomeItem" l:Uids.Target="Content" />
  2. Make it work within l:Uids.Uid:

    <NavigationViewItem l:Uids.Uid="SomeItem.Content" />

    This was actually suggested a very long time ago but wasn't implemented.
    Microsoft/xaml-standard#199

I'm afraid, I'm going to need time to think about this.

from winui3localizer.

Pietro228 avatar Pietro228 commented on September 27, 2024

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

from winui3localizer.

Pietro228 avatar Pietro228 commented on September 27, 2024

Any news about this? :D

from winui3localizer.

AndrewKeepCoding avatar AndrewKeepCoding commented on September 27, 2024

I'm not sure if I can find time to consider and implement this anytime soon. 😵

from winui3localizer.

Pietro228 avatar Pietro228 commented on September 27, 2024

That's OK :D For now I'll just prompt the user to restart the app.

from winui3localizer.

AndrewKeepCoding avatar AndrewKeepCoding commented on September 27, 2024

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 x:Uid is a different thing. Can you be more specific about your localization again?

from winui3localizer.

Pietro228 avatar Pietro228 commented on September 27, 2024

I'm able to localize them, but only by naming the keys like this Dashboard.Content = Name.Target. I don't want to inlude target in a key, so for now, while I'm waiting for your implementation of the extended x:Uid, I'll be using my own solution using the ResourceString despite the need to restart the app for language changes to take effect.

from winui3localizer.

AndrewKeepCoding avatar AndrewKeepCoding commented on September 27, 2024

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')}" />

from winui3localizer.

Pietro228 avatar Pietro228 commented on September 27, 2024

I know, you already told me about it here #39 (comment). But I still need to restart the app to change the language

from winui3localizer.

Pietro228 avatar Pietro228 commented on September 27, 2024

Idk why, but VS says that it can't find my class, however it builds without any problems :D
obrazek

That's why I look forward to your solution which wouldn't give me unnecessary errors

from winui3localizer.

AndrewKeepCoding avatar AndrewKeepCoding commented on September 27, 2024

@Pietro228 In order to keep consistentcy with x:Uid, I'm afraid I'm going to go with the 3rd option which is leave it as it is. I hope you understand.

from winui3localizer.

Pietro228 avatar Pietro228 commented on September 27, 2024

@AndrewKeepCoding Any news? 🤔

from winui3localizer.

AndrewKeepCoding avatar AndrewKeepCoding commented on September 27, 2024

Sorry for the delay. I just published v2.3.0-alpha. Can you give it a try if it works for your requirements?
(Make sure to check the Include prerelease checkbox.)

from winui3localizer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.