diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpDataAnnotationAutoLocalizationMetadataDetailsProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpDataAnnotationAutoLocalizationMetadataDetailsProvider.cs index d9de135e7f..be088b0154 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpDataAnnotationAutoLocalizationMetadataDetailsProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpDataAnnotationAutoLocalizationMetadataDetailsProvider.cs @@ -54,7 +54,29 @@ namespace Volo.Abp.AspNetCore.Mvc displayMetadata.DisplayName = () => { - var localizedString = localizer[PropertyLocalizationKeyPrefix + context.Key.Name]; + /* + * DisplayName:ClassName:PropertyName + * DisplayName:PropertyName + * ClassName:PropertyName + * PropertyName + */ + + LocalizedString localizedString = null; + + if (context.Key.ContainerType != null) + { + localizedString = localizer[PropertyLocalizationKeyPrefix + context.Key.ContainerType.Name + ":" + context.Key.Name]; + } + + if (localizedString == null || localizedString.ResourceNotFound) + { + localizedString = localizer[PropertyLocalizationKeyPrefix + context.Key.Name]; + } + + if (localizedString.ResourceNotFound && context.Key.ContainerType != null) + { + localizedString = localizer[context.Key.ContainerType.Name + ":" + context.Key.Name]; + } if (localizedString.ResourceNotFound) { @@ -65,4 +87,4 @@ namespace Volo.Abp.AspNetCore.Mvc }; } } -} \ No newline at end of file +} diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/LocalizationTestController.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/LocalizationTestController.cs index 1defcf4809..ff26083a83 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/LocalizationTestController.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/LocalizationTestController.cs @@ -21,12 +21,20 @@ namespace Volo.Abp.AspNetCore.App public class PersonModel { - //[Display(Name = nameof(BirthDate))] public string BirthDate { get; set; } + public string BirthDate1 { get; set; } + + public string BirthDate2 { get; set; } + + public string BirthDate3 { get; set; } + public PersonModel() { BirthDate = DateTime.Now.ToString("yyyy-MM-dd"); + BirthDate1 = BirthDate; + BirthDate2 = BirthDate; + BirthDate3 = BirthDate; } } } diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/Views/LocalizationTest/PersonForm.cshtml b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/Views/LocalizationTest/PersonForm.cshtml index 7f0a0d470f..31dee8bf83 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/Views/LocalizationTest/PersonForm.cshtml +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/App/Views/LocalizationTest/PersonForm.cshtml @@ -5,4 +5,13 @@
\ No newline at end of file + + + + + + + + + + diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/MvcLocalization_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/MvcLocalization_Tests.cs index 4d9a4f4624..fe7912951c 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/MvcLocalization_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/MvcLocalization_Tests.cs @@ -30,7 +30,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Localization var result = await GetResponseAsStringAsync("/LocalizationTest/HelloJohn"); result.ShouldBe("Hello John."); } - + [Fact] public async Task Should_Localize_Display_Attribute() { @@ -38,12 +38,18 @@ namespace Volo.Abp.AspNetCore.Mvc.Localization { var result = await GetResponseAsStringAsync("/LocalizationTest/PersonForm"); result.ShouldContain(""); + result.ShouldContain(""); + result.ShouldContain(""); + result.ShouldContain(""); } using (CultureHelper.Use("tr")) { var result = await GetResponseAsStringAsync("/LocalizationTest/PersonForm"); result.ShouldContain(""); + result.ShouldContain(""); + result.ShouldContain(""); + result.ShouldContain(""); } } } diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/Resource/en.json b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/Resource/en.json index 2451c1b294..f11c5458db 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/Resource/en.json +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/Resource/en.json @@ -1,7 +1,10 @@ { "culture": "en", "texts": { + "DisplayName:PersonModel:BirthDate1": "Birth date1", + "DisplayName:BirthDate2": "Birth date2", + "PersonModel:BirthDate3": "Birth date3", "BirthDate": "Birth date", - "Value1": "Value One" + "Value1": "Value One" } -} \ No newline at end of file +} diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/Resource/tr.json b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/Resource/tr.json index 546e672ede..b99e81bec0 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/Resource/tr.json +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Localization/Resource/tr.json @@ -1,7 +1,10 @@ { "culture": "tr", "texts": { + "DisplayName:PersonModel:BirthDate1": "Dogum gunu1", + "DisplayName:BirthDate2": "Dogum gunu2", + "PersonModel:BirthDate3": "Dogum gunu3", "BirthDate": "Dogum gunu", - "Value1": "Değer Bir" + "Value1": "Değer Bir" } -} \ No newline at end of file +}