Skip to content
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

Huge Overhaul #47

Merged
merged 11 commits into from
Feb 24, 2025
Merged

Huge Overhaul #47

merged 11 commits into from
Feb 24, 2025

Conversation

Axemasta
Copy link
Owner

@Axemasta Axemasta commented Feb 22, 2025

This PR is a mish mash of upgrades and enhancements that I had been planning for sometime:

  • Add LocalizeBinding for explicitly binding to a property. This now correctly changes language when locales change.
  • Added targets for automatically linking EmbeddedResource and AdditionalFiles items at default location ("Resources/Locales/") + ability to override it
  • Added Enum support via LocalizeEnum, these by default will pull translation keys from the [Description] attribute but this behaviour is fully configurable for the library and for individual enums.
  • Added better code behind support, this is a blidnspot for Mocale so I've added some more csharp code methods to help localize via code. All methods now have fluent equivalents.
  • Added code sample page, this should help me identify blindspots in the api surface.
  • Switched to centralized package management
  • Added LocalizeMultiBinding for localizing when using 2 or more bindings as the format parameters.
  • Added Mocale.Testing a new package for allowing users to easily run mocale code in unit tests. The reason for this is using SetTranslation in a unit test requires mocale to be setup and the behaviour of Mock<ITranslatorManager isn't quite up to scratch since it needs to invoke INotifyPropertyChanged, I had personally been using a proxy class so I have made that part of this library.
  • Fixed update translation race condition, this previously raised multiple events in quick succession and could cause errors rendering localizations
  • Deprecated Binding and Parameters on Localize markup extension, please use the dedicated bindings now since these actually update with locale changes!

I've got a much nicer way of doing localized bindings, this currently supports 1:1 parameter to binding but that's a great start!
There is now a markup extension for binding to enums. The implementation works well and I'm going to enhance it so everything to do with enums is configurable!
Added the ability to specify how mocale deals with enums in order to grab a translation key using attributes etc. There is global settings and overrides for specific types!
I now have a good working sample of code only, I've integrated with markup ui so its easy to mocalize without using xaml!
I've added a testing mechanism for mocale since its not friendly to test the behavior at all. There is now a proxy class that does all the bits without the jazz and can be used in unit tests to emulate whats happening at runtime.
Everything is now versioned centrally using the packages.props file. I've updated packages where applicable and also remove maui compatibility references
I've added some csproj glitter to automatically reference mocale resources as EmbeddedResource and AdditionalFiles by default, the user can override them also!
There is now the ability to multibind for a list of bindings, this was alot less strife than I anticipated
I broke the tests by design of the fix earlier in this branch for the race condition. I have now made an internal abstraction for the translator manager which can be moq tested, this is also part of the proxy
Copy link

github-actions bot commented Feb 23, 2025

File Coverage Lines Branches Missing
All files 28% 28% 28%
Mocale.Cache.SQLite\obj\Debug\net9.0\Microsoft.Maui.Controls.BindingSourceGen\Microsoft.Maui.Controls.BindingSourceGen.BindingSourceGenerator\GeneratedBindingInterceptorsCommon.g.cs 0% 0% 0% 19-28
Mocale.Cache.SQLite\MocaleBuilderExtension.cs 0% 0% 100% 20-42
Mocale.Cache.SQLite\Repositories\CacheRepository.cs 0% 0% 0% 13-94
Mocale.Cache.SQLite\Repositories\RepositoryBase.cs 0% 0% 100% 8-21
Mocale.Cache.SQLite\Repositories\TranslationsRepository.cs 0% 0% 0% 12-163
Mocale.Cache.SQLite\Providers\DatabaseConnectionProvider.cs 0% 0% 100% 16-50
Mocale.Cache.SQLite\Providers\DatabasePathProvider.cs 0% 0% 100% 4-14
Mocale.Cache.SQLite\Models\SqliteConfig.cs 0% 0% 100% 7-13
Mocale.Cache.SQLite\Managers\LocalisationCacheManager.cs 0% 0% 0% 6-45
Mocale.Cache.SQLite\Managers\SqlCacheUpdateManager.cs 0% 0% 0% 15-78
Mocale.Cache.SQLite\Entities\TranslationItem.cs 0% 0% 100% 10-16
Mocale.Cache.SQLite\Entities\UpdateHistoryItem.cs 0% 0% 100% 10-14
Mocale\obj\Debug\net9.0\Microsoft.Maui.Controls.BindingSourceGen\Microsoft.Maui.Controls.BindingSourceGen.BindingSourceGenerator\GeneratedBindingInterceptorsCommon.g.cs 0% 0% 0% 19-28
Mocale\AppBuilderExtensions.cs 0% 0% 0% 22-76
Mocale\MocaleBuilder.cs 0% 0% 0% 12-48
Mocale\MocaleBuilderExtensions.cs 0% 0% 0% 21-122
Mocale\MocaleInitializeService.cs 0% 0% 100% 6-15
Mocale\MocaleLocator.cs 90% 80% 100% 33
Mocale\Wrappers\DateTimeWrapper.cs 0% 0% 100% 10
Mocale\Providers\EmbeddedResourceProvider.cs 88% 93% 83% 71-73
Mocale\Providers\InactiveExternalLocalizationProvider.cs 0% 0% 100% 7-14
Mocale\Providers\ResxResourceProvider.cs 0% 0% 0% 14-66
Mocale\Parsers\ResxLocalizationParser.cs 87% 100% 75%
Mocale\Models\AppResourcesConfig.cs 0% 0% 100% 7
Mocale\Models\EmbeddedResourcesConfig.cs 0% 0% 100% 8-14
Mocale\Models\LocalizeEnumBehavior.cs 0% 0% 100% 39-49
Mocale\Managers\ConfigurationManager.cs 0% 0% 100% 9-19
Mocale\Managers\ParameterTranslatorManager.cs 0% 0% 0% 13-58
Mocale\Managers\TranslationResolver.cs 0% 0% 0% 5-168
Mocale\Managers\TranslationResolver.cs 0% 0% 100% 88-104
Mocale\Managers\TranslationResolver.cs 0% 0% 0% 26-80
Mocale\Managers\TranslatorManager.cs 81% 78% 85% 74-91 124 146
Mocale\Helper\EnumTranslationKeyHelper.cs 0% 0% 0% 5-37
Mocale\Helper\EnumTranslationKeyHelper.cs 0% 0% 0% 42-68
Mocale\Extensions\BindableObjectExtension.cs 16% 13% 20% 20-81 101-102 113-115 132-188
Mocale\Extensions\DictionaryExtension.cs 95% 100% 90%
Mocale\Extensions\LocalizeBindingExtension.cs 0% 0% 0% 13-93
Mocale\Extensions\LocalizeEnumExtension.cs 0% 0% 0% 14-92
Mocale\Extensions\LocalizeExtension.cs 0% 0% 0% 13-104
Mocale\Extensions\LocalizeExtension.cs 0% 0% 0% 109-120
Mocale\Extensions\LocalizeMultiBindingExtension.cs 0% 0% 0% 13-98
Mocale\Extensions\TaskExtensions.cs 87% 100% 75%
Mocale\Extensions\UriExtension.cs 62% 25% 100% 12-25
Mocale\Exceptions\InitializationException.cs 0% 0% 100% 3
Mocale\Exceptions\MocaleException.cs 0% 0% 100% 6-13
Mocale.Providers.AWS.S3\obj\Debug\net9.0\Microsoft.Maui.Controls.BindingSourceGen\Microsoft.Maui.Controls.BindingSourceGen.BindingSourceGenerator\GeneratedBindingInterceptorsCommon.g.cs 0% 0% 0% 19-28
Mocale.Providers.AWS.S3\MocaleBuilderExtension.cs 0% 0% 100% 17-29
Mocale.Providers.AWS.S3\S3BucketProvider.cs 0% 0% 0% 8-46
Mocale.Providers.AWS.S3\Models\BucketConfig.cs 0% 0% 100% 7-10
Mocale.Providers.Azure.Blob\obj\Debug\net9.0\Microsoft.Maui.Controls.BindingSourceGen\Microsoft.Maui.Controls.BindingSourceGen.BindingSourceGenerator\GeneratedBindingInterceptorsCommon.g.cs 0% 0% 0% 19-28
Mocale.Providers.Azure.Blob\BlobLocalizationProvider.cs 0% 0% 100% 15-35
Mocale.Providers.Azure.Blob\BlobLocalizationProvider.cs 0% 0% 0% 42-69
Mocale.Providers.Azure.Blob\BlobLocalizationProvider.cs 0% 0% 0% 99-130
Mocale.Providers.Azure.Blob\BlobLocalizationProvider.cs 0% 0% 0% 72-92
Mocale.Providers.Azure.Blob\MocaleBuilderExtension.cs 0% 0% 0% 19-34
Mocale.Providers.Azure.Blob\Models\BlobResourceInfo.cs 0% 0% 100% 11-16
Mocale.Providers.Azure.Blob\Models\BlobStorageConfig.cs 0% 0% 100% 7-16
Mocale.Providers.Azure.Blob\Managers\BlobResourceLocator.cs 0% 0% 0% 15-52
Mocale.Providers.Azure.Blob\Managers\BlobResourceLocator.cs 0% 0% 0% 60-86
Mocale.Providers.Github.Raw\obj\Debug\net9.0\Microsoft.Maui.Controls.BindingSourceGen\Microsoft.Maui.Controls.BindingSourceGen.BindingSourceGenerator\GeneratedBindingInterceptorsCommon.g.cs 0% 0% 0% 19-28
Mocale.Providers.Github.Raw\GitHubRawProvider.cs 53% 39% 66% 46-53 61-67 75-83
Mocale.Providers.Github.Raw\MocaleBuilderExtension.cs 0% 0% 0% 17-35
Mocale.Testing\obj\Debug\net9.0\Microsoft.Maui.Controls.BindingSourceGen\Microsoft.Maui.Controls.BindingSourceGen.BindingSourceGenerator\GeneratedBindingInterceptorsCommon.g.cs 0% 0% 0% 19-28
Mocale.Testing\TranslatorManagerProxy.cs 77% 76% 77% 26 32-33 37-38 50-51 58-60 91
Mocale.Testing\Extensions\DictionaryExtension.cs 66% 72% 60% 24-29

Minimum allowed coverage is 5%

Generated by 🐒 cobertura-action against 5e50ca0

All of the build warnings have been addressed ready for merging
@Axemasta Axemasta merged commit 71767b6 into main Feb 24, 2025
4 checks passed
@Axemasta Axemasta deleted the overhaul branch March 4, 2025 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant