Skip to content

[dev-v5] Add Localizer service - #2979

Merged
Denis Voituron (dvoituron) merged 11 commits into
dev-v5from
users/dvoituron/dev-v5/localization
Nov 29, 2024
Merged

Denis Voituron (dvoituron) merged 11 commits into
dev-v5from
users/dvoituron/dev-v5/localization

Conversation

@dvoituron

Copy link
Copy Markdown
Collaborator

[dev-v5] Add Localizer service

A file LanguageResource.resx is included in the project.
A service IFluentLocalizer is automatically added to the project, using AddFluentUIComponents().
The developer can customize/override this service.

To use the service is the Lib, we can use the "key" defined in the resx file.

Title = Localizer["FluentLayoutHamburger_Title"];

Customization

The developer can customize the Localizer to add other languages.

Services.AddFluentUIComponents(config => config.Localizer = new EmbeddedLocalizer());
public class EmbeddedLocalizer : IFluentLocalizer
{
    private const string BaseName = "...Resources.FluentLocalizer";   // .resx files
    private static readonly ResourceManager ResourceManager = new ResourceManager(BaseName, Assembly.GetExecutingAssembly());

    /// <summary>
    /// Gets the string resource with the given key, depending of the current UI culture.
    /// </summary>
    /// <param name="key"></param>
    /// <param name="arguments"></param>
    /// <returns></returns>
    public string this[string key, params object[] arguments]
    {
        get
        {
            // Need to add
            //  - builder.Services.AddLocalization();
            //  - app.UseRequestLocalization(new RequestLocalizationOptions().AddSupportedUICultures(["en", "fr", "nl"]));

            // Returns the localized version of the string
            // By default, returns the English version of the string
            var localizedString = ResourceManager.GetString(key, CultureInfo.CurrentUICulture)
                               ?? IFluentLocalizer.GetDefault(key);

            return arguments.Length > 0
                ? string.Format(CultureInfo.CurrentCulture, localizedString, arguments)
                : localizedString;
        }
    }
}

Unit Tests

{E3D9B4F1-A88D-4EF0-A39E-10DB38810A5D}

@github-actions

github-actions Bot commented Nov 26, 2024 •

Copy link
Copy Markdown

✅ All tests passed successfully

Details on your Workflow / Core Tests page.

@github-actions

github-actions Bot commented Nov 26, 2024 •

Copy link
Copy Markdown

Summary - Unit Tests Code Coverage

Summary
Generated on: 11/29/2024 - 11:37:07
Coverage date: 11/29/2024 - 11:37:00
Parser: Cobertura
Assemblies: 1
Classes: 37
Files: 43
Line coverage: 98.9% (736 of 744)
Covered lines: 736
Uncovered lines: 8
Coverable lines: 744
Total lines: 3621
Branch coverage: 92.8% (484 of 521)
Covered branches: 484
Total branches: 521
Method coverage: Feature is only available for sponsors
Tag: 2082_12084067378

Coverage

Microsoft.FluentUI.AspNetCore.Components - 98.9%
Name Line Branch
Microsoft.FluentUI.AspNetCore.Components 98.9% 92.8%
Microsoft.FluentUI.AspNetCore.Components.Extensions.EnumExtensions 100% 100%
Microsoft.FluentUI.AspNetCore.Components.Extensions.FluentInputExtensions 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentButton 100% 89.5%
Microsoft.FluentUI.AspNetCore.Components.FluentComponentBase 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentGrid 100% 90%
Microsoft.FluentUI.AspNetCore.Components.FluentGridItem 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentIcon`1 100% 95.8%
Microsoft.FluentUI.AspNetCore.Components.FluentInputBase`1 100% 83.3%
Microsoft.FluentUI.AspNetCore.Components.FluentInputImmediateBase`1 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentJSModule 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentLabel 100%
Microsoft.FluentUI.AspNetCore.Components.FluentLayout 100% 71.4%
Microsoft.FluentUI.AspNetCore.Components.FluentLayoutHamburger 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentLayoutItem 100% 89.2%
Microsoft.FluentUI.AspNetCore.Components.FluentListBase`1 93.3% 94.7%
Microsoft.FluentUI.AspNetCore.Components.FluentLocalizerExtensions 100%
Microsoft.FluentUI.AspNetCore.Components.FluentLocalizerInternal 100%
Microsoft.FluentUI.AspNetCore.Components.FluentOption 91.6% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentSelect`1 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentText 100% 100%
Microsoft.FluentUI.AspNetCore.Components.FluentTextInput 100% 100%
Microsoft.FluentUI.AspNetCore.Components.Icon 100% 91.1%
Microsoft.FluentUI.AspNetCore.Components.IconFromImage 100%
Microsoft.FluentUI.AspNetCore.Components.IconInfo 100%
Microsoft.FluentUI.AspNetCore.Components.IFluentLocalizer 100% 100%
Microsoft.FluentUI.AspNetCore.Components.InternalListContext`1 60%
Microsoft.FluentUI.AspNetCore.Components.Localization.LanguageResource 100% 100%
Microsoft.FluentUI.AspNetCore.Components.Migration.AppearanceExtensions 100% 100%
Microsoft.FluentUI.AspNetCore.Components.Migration.FluentInputAppearanceExt
ensions
83.3% 75%
Microsoft.FluentUI.AspNetCore.Components.Utilities.AddTag 100% 100%
Microsoft.FluentUI.AspNetCore.Components.Utilities.CssBuilder 100% 92.8%
Microsoft.FluentUI.AspNetCore.Components.Utilities.Debounce 100% 83.3%
Microsoft.FluentUI.AspNetCore.Components.Utilities.Identifier 100% 100%
Microsoft.FluentUI.AspNetCore.Components.Utilities.IdentifierContext 100% 75%
Microsoft.FluentUI.AspNetCore.Components.Utilities.InlineStyleBuilder 100% 92.8%
Microsoft.FluentUI.AspNetCore.Components.Utilities.InternalDebounce.Dispatc
herTimerExtensions
95.7% 75%
Microsoft.FluentUI.AspNetCore.Components.Utilities.StyleBuilder 100% 100%

@dvoituron
Denis Voituron (dvoituron) merged commit 68ea7e5 into dev-v5 Nov 29, 2024
@dvoituron
Denis Voituron (dvoituron) deleted the users/dvoituron/dev-v5/localization branch November 29, 2024 11:36
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.

2 participants