-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Improve flexibility with build-in controls localization #13773
Conversation
if I missed any of the controls - let me know. For some reason, Rider doesn't report localizable strings warnings now, even though it always annoyed me with that before. |
/cc @robloo as you have made the ColorPicker which is one of the main controls to be translated :-) |
I don't think this is right design for localization. We were on a better track in the old discussion. This seems like a quick and dirty hack rather than an integrated design. I suppose something is better than nothing but these types of things have a habit of staying around forever.
Edit, added:
@timunie I can separate out strings for this as required. However, the entire control has a different design philosophy than WinUI. In WinUI they have text names for almost everything. In Avalonia's ColorPicker I specifically tried to use symbols which don't need to be localized. Even the 'R', 'G', 'B' strings are considered universal symbols for the RGB color model and don't need to be translated (PhotoShop doesn't localize these and we decided to use their trick years ago). About the only thing that needs localization right now are the actual color names and unfortunately there are quite a few of those. In the future this will probably expand to slider tooltip text and accessibility names though. |
This should probably be named |
Oh, right, I forgot it had localizable strings too. As robloo said it should have way less of them compared to UWP, but worth double check. However, I have doubts if I should localize color names in this PR. UWP did it IIRC.
First of all, a reminder, the problem is not to provide a localization framework to the users. The problem is to make build-in controls localizable with a little effort. The old design idea was flawed and suitable for some people while being a nuisance for other.
The developer is not forced to do anything. If they need to override strings used in default controls - they can do it after this PR. They can use XML, or txt, or hardcode it, or redirect to IStringLocalizer. IResourceProvider is an old interface that can do anything if that can implement TryGetResource. Problems with this PR:
Well, as I said you can't make it good for everybody. Also, this single language is, in fact, defined in XML (XAML). Also, it's an internal implementation detail - developers don't see it.
Okay, we will never use RESX/RESW for XAML for internal localization due to technical reasons - satellites, aot and generally an overhead. There was an idea to generate static consts from RESX files with a source generator, but it would kill the whole point. And use xaml resources also support width and heights or any other values that can be put to the resources.
True, it's not covered by this PR. But I also don't see how it would be a problem with the current solution. In XAML accessibility names are defined in XAML, and we also can use dynamic resources there.
Yeah, a better one can be used.
Same as with any other resource. When a new text resource is added, and not yet overridden by the developer, - the original one will be used.
As mentioned above, it can be extended as part of the same internal implementation detail, even though we don't have plans for this yet. And, at the same time, developers can use whatever they want by providing a custom IResourceProvider. For example, IStringLocalizer does support language fallbacks when used with RESX. It can be used from IResourceProvider as well. |
Not sure. It's a language provided by the OS, since it's part of the IPlatformSettigns interface. "Requested" term normally identifies something required by the user, which might not be the case with OS language. And "Actual" language isn't fitting well either, as OS language can be ignored in the app. But yeah, it is outside of this PR's scope. |
Yes and yes. And yes, it is expected to stay here for a while. While being easy to remove if we decide so. |
Changed sample IResourceProvider implementation to use IStringLocalizer and avoiding hardcoded strings in the description. |
You can test this PR using the following package version. |
# Conflicts: # src/Avalonia.Themes.Fluent/Controls/DatePicker.xaml
You can test this PR using the following package version. |
You can test this PR using the following package version. |
What does the pull request do?
We have a longstanding problem with hardcoded localization of our built-in controls. This PR does make it more flexible by reusing the existing infrastructure of resource dictionaries (which is the main difference from the discussion of #8741). After discussion, these resources won't affect performance in any measurable way, especially when compared with other possible solutions. Also, it doesn't introduce a dependency on IStringLocalizer nor duplicate it, while still making it possible to use one, if a developer wants.
In the future, I am going to implement something like
PlatformSettigns.PreferredUILanguage
so it would be possible to get the current UI language from the OS and subscribe to its changes. But it is out of the scope of this PR.What is the current behavior?
What is the updated/expected behavior with this PR?
On the last one in more details:
Fixed issues
Fixes #8741
Fixes #14706