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

How to localize Login/Logout text in menu (or the login window there after)? #7280

Closed
sturlath opened this issue Jan 16, 2021 · 11 comments · Fixed by #7362
Closed

How to localize Login/Logout text in menu (or the login window there after)? #7280

sturlath opened this issue Jan 16, 2021 · 11 comments · Fixed by #7362
Assignees
Milestone

Comments

@sturlath
Copy link
Contributor

I have read the localization docs (and the extending resources) in/out and I can't figure out how I can override the default English translations that I have not set, like "Log in" etc.

It must be possible to override it even though the system doesn't currently come with Icelandic, right?

I just can't change the text Login to "Innskrá"!

image

I have tried to add all thinkable resources (they are quite a few)

See my code

Configure<AbpLocalizationOptions>(options =>
            {
                options.Resources
                    .Add<testResource>("is")
                    .AddBaseTypes(typeof(AbpValidationResource))
                    .AddBaseTypes(typeof(AbpIdentityServerResource))
                    .AddBaseTypes(typeof(IdentityResource))
                    .AddBaseTypes(typeof(AbpTenantManagementResource))
                    .AddBaseTypes(typeof(AbpLocalizationResource))
                    // name space Account not available here!
                    //.AddBaseTypes(typeof(Volo.Abp.Account.Localization.AccountResource)) 
                    .AddVirtualJson("/Localization/test");
                    
                   options.DefaultResourceType = typeof(testResource);
            });

Now that I'm writing this, I'm thinking that the lack of Volo.Abp.Account.Localization.AccountResource might be the problem. The project doesn't have access to it?

I have even tried all kinds of "overrides" in the is.json file

{
  "culture": "is",
  "texts": {
    "Menu:Home": "All special icelandic letters only showing ? -> íþð ",
    "Welcome": "Welcome",
    "LongWelcomeMessage": "Welcome to the application. This is a startup project based on the ABP framework. For more information, visit abp.io.",
    "Login": "Innskrá",
    "Logout": "Útskrá",
    "Authentication:Login": "Innskrá",
    "Authentication:Logout": "Útskrá",
    "Volo.Abp.Account:Login": "Innskrá",
    "Volo.Abp.Account:Logout": "Útskrá",
    "Login:Volo.Abp.Account.Login": "Innskrá",
    "Logout:Volo.Abp.Account.Logout": "Útskrá",
    "Default:Login": "Innskrá",
    "Default:Logout": "Útskrá",
    "Account:Login": "Innskrá",
    "Account:Logout": "Útskrá",
    "Account::Login": "Innskrá",
    "Account::Logout": "Útskrá",
    "Account:Login:Login": "Innskrá",
    "Account:Login:Logout": "Útskrá",
    "AbpAccount:Login": "Innskrá",
    "AbpAccount:Logout": "Útskrá",
    "AbpUi:Login": "Innskrá",
    "AbpUi:Logout": "Útskrá"
  }
}

I have searched open/cloes issues and found few similar but they did'nt help. See this, this and this one

Version and code
Running apb.io version 4.1.1 and Blazor
I have created a test project with this code if you like to try it out

@sturlath
Copy link
Contributor Author

Is there something stopping me from trying to create a PR for that? Is there some reason the strings are not localized there?

But how about the page after pressing the Login button? This Login.cshtml

image

There we have @l["AreYouANewUser"] but with my code above and this added to the json file it doesn't take..

    "AreYouANewUser": "Ertu nýr notandi?",
    "Authentication:AreYouANewUser": "Ertu nýr notandi?",
    "Volo.Abp.Account:AreYouANewUser": "Ertu nýr notandi?",
    "Login:Volo.Abp.Account.AreYouANewUser": "Ertu nýr notandi?",
    "Default:AreYouANewUser": "Ertu nýr notandi?",
    "Account:AreYouANewUser": "Ertu nýr notandi?",
    "Account::AreYouANewUser": "Ertu nýr notandi?",
    "Account:Login:AreYouANewUser": "Ertu nýr notandi?",
    "AbpAccount:AreYouANewUser": "Ertu nýr notandi?",
    "AbpUi:AreYouANewUser": "Ertu nýr notandi?"

That might be because of Volo.Abp.Account namespace not being available in the Domain.Shared project?
The Volo.Abp.Account.Web.IdentityServer package can´t be installed into the project...

So..?

Btw thank you @d-oit for your other suggestions. I´ll try them out for the Login text..

@sturlath sturlath changed the title How to localize Login/Logout text? How to localize Login/Logout text in menu (or the login window there after)? Jan 18, 2021
@olicooper
Copy link
Contributor

olicooper commented Jan 19, 2021

UPDATE

The localization overriding is working fine with the changes below. It was a bug specifically in Identity localization: cc1c1d3#diff-64394e2c990c78aa48c6d551c9e82a16ed963b96d17bdf1a9adbcf3029d6c642

==========

I precisely followed the abp docs and it isn't working for me either.

I want to change this localized string:

In the ConfigureServices of my Domain.Shared module:

[DependsOn(
    //...
    typeof(AbpIdentityDomainSharedModule),
    //...
)]
public class MyProjectDomainSharedModule : AbpModule
{
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        Configure<AbpLocalizationOptions>(options =>
        {
            options.Resources
                .Get<Volo.Abp.Identity.Localization.IdentityResource>()
                .AddVirtualJson("/Localization/Resources/Identity/Extensions");
        });
    }
}

My csproj project file includes the embedded resource

  <ItemGroup>
    <EmbeddedResource Include="Localization\**\*.json" />
    <Content Remove="Localization\**\*.json" />
  </ItemGroup>

File structure:
image

The text is not overridden. I have also added this to the HttpApi.Host module and used PostConfigure with no success either.

@maliming
Copy link
Member

hi @olicooper

Can you share a project to show the problem?

@olicooper
Copy link
Contributor

@maliming I don't think the problem I mention above is a localization issue, it is due to the bug I mention here.

I can create a project to show the Identity.Default issue I have if that is what you need? The configuration is what I describe in my comment above - where I override the IdentityResource to replace Volo.Abp.Identity:InvalidToken with "Invalid token, please try again."

@maliming
Copy link
Member

Please share it, thanks.

@olicooper
Copy link
Contributor

olicooper commented Jan 20, 2021

Here is a sample that should work. Go to appsettings.json and update TestUserId with the host admin Id in your database.
IdentityResourceTest.zip
When you submit the form, it should say "Invalid token, please try again." but it just says "Invalid token."

Update
@maliming I'm sorry, I should have mentioned that Identity.Default will only happen after your update cc1c1d3
The version in the first sample (IdentityResourceTest.zip) is 4.2.0-rc.2 which doesn't include the update yet, but it still doesn't localize the text as expected.
Here is a new version with manually applied changes: IdentityResourceTest-v2.zip

@maliming
Copy link
Member

Thanks @olicooper

AbpIdentityResultExtensions needs refactoring, I am working on it.

@maliming
Copy link
Member

See #7362

@olicooper
Copy link
Contributor

olicooper commented Jan 20, 2021

@sturlath Sorry for hijacking your issue! I have tested the AreYouANewUser localization issue for you...
The AccountResource is located in the Application.Contracts of the account module, so you need to place your localization overrides in your Application.Contracts module or a module that depends on it such as the Web module...

public class MyProjectApplicationContractsModule : AbpModule
{
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        Configure<AbpLocalizationOptions>(options =>
        {
            options.Resources
                .Get<Volo.Abp.Account.Localization.AccountResource>()
                .AddVirtualJson("/Localization/AbpAccount");
        });
    }
}

I have left my localization *.json files in my Domain.Shared module, but I can't guarantee that it will work properly for you.
image

You shouldn't need to use .AddBaseTypes(typeof(xyzResource)) because this just includes external resources in your own resource namespace testResource.

Is there something stopping me from trying to create a PR for that? Is there some reason the strings are not localized there?

I would say yes to creating a PR for the login text here, because a 'Login' localization already exists but it isn't being used in the menu bar for blazor apps. you can see all the places it is used here.

@maliming After looking at the issues created about localization, I wonder if the localization docs might need to be expanded to explain which module to place the override configuration in along with an example of overriding a built-in resource like AccountResource?

@maliming
Copy link
Member

An example to explain how to extend localization resource.
https://github.com/abpframework/abp-samples/tree/master/DocumentationSamples/ExtendLocalizationResource

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants