Comments (20)
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
from winui3localizer.
Reopening this for v3.
from winui3localizer.
I can make it work by using a resource loader, but it doesn't update runtime and you have to restart the app :/
Would it be possible to create something like this? It's really time consuming to use the suffixes
from winui3localizer.
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.
Thank you for your help, but it always returns "null" :/
I have only replaced the resourceLoader.GetString(Name);
for your method.
from winui3localizer.
I found the issue. It did not copy new string resource files.
This should be InstalledWidgets
not MainWindow_InstalledWidgets.Content
from winui3localizer.
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.
from winui3localizer.
Thanks for the suggestion. I guess there are 2 considerable options here:
-
Add
l:Uids.Target
:<NavigationViewItem l:Uids.Uid="SomeItem" l:Uids.Target="Content" />
-
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.
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.
Any news about this? :D
from winui3localizer.
I'm not sure if I can find time to consider and implement this anytime soon. 😵
from winui3localizer.
That's OK :D For now I'll just prompt the user to restart the app.
from winui3localizer.
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.
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.
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.
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.
Idk why, but VS says that it can't find my class, however it builds without any problems :D
That's why I look forward to your solution which wouldn't give me unnecessary errors
from winui3localizer.
@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.
@AndrewKeepCoding Any news? 🤔
from winui3localizer.
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)
- How to use this package for projects conststing of multiple DLLs resp. code projects? HOT 2
- Can I name the .resw files differnently, eg, <PRJNAME>.resw? HOT 1
- Unpackaged sample in README is not correct HOT 1
- MVVM Pattern HOT 4
- FlowDirection not working HOT 2
- multiple resources HOT 4
- Localizing DLLs HOT 2
- Add support for factoring strings into multiple resources files HOT 4
- Options.UseUidWhenLocalizedStringNotFound does not work with Uid on XAML
- Add support for auto populate external string resources files (Resoures.resw)
- How to change language without restart the app? HOT 2
- Add support for attached properties HOT 3
- Add support for brush properties
- Dynamically Loading a String Dictionary at Runtime HOT 1
- MVVM sample project in NuGet Gallery crash with V2 HOT 6
- PublishTrimmed/TrimMode support? HOT 16
- Make building process easier
- Recommended way to localize top-level UI components? HOT 2
- Support default Resources.resw
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from winui3localizer.