Skip to content

Commit

Permalink
localizing messages and exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardoporro committed Feb 6, 2017
1 parent 0f6e9ed commit 09b6797
Show file tree
Hide file tree
Showing 60 changed files with 546 additions and 333 deletions.
18 changes: 9 additions & 9 deletions Detached.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Detached.EntityFramework.Te
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Detached.DataAnnotations", "src\Detached.DataAnnotations\Detached.DataAnnotations.xproj", "{CAE57FCE-7531-44CE-8A64-0433DAA578D3}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Detached.Mvc", "src\Detached.Mvc\Detached.Mvc.xproj", "{09D59FB4-FE99-4E3A-B867-32EF550509E0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "demo", "demo", "{E24B1EB7-4790-4DE9-ADF8-08A2636F6D33}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Detached.Angular2Demo", "demo\Detached.Angular2Demo\Detached.Angular2Demo.xproj", "{0A133ABC-BE1C-4542-8F0F-DCD3315F30BC}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Detached.Services", "src\Detached.Services\Detached.Services.xproj", "{EBDDAEB2-00F9-4C93-8ADE-165265549501}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Detached.Mvc.Localization", "src\Detached.Mvc.Localization\Detached.Mvc.Localization.xproj", "{206AF418-85E9-40C6-85F2-58144EFF8059}"
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Detached.Mvc", "src\Detached.Mvc\Detached.Mvc.xproj", "{206AF418-85E9-40C6-85F2-58144EFF8059}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Detached.Mvc.Controllers", "src\Detached.Mvc.Controllers\Detached.Mvc.Controllers.xproj", "{09D59FB4-FE99-4E3A-B867-32EF550509E0}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Detached.Mvc.Localization.Tests", "test\Detached.Mvc.Localization.Tests\Detached.Mvc.Localization.Tests.xproj", "{0035A3D1-C76F-43A2-ABB5-BBA9979A6FDC}"
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Detached.Mvc.Tests", "test\Detached.Mvc.Tests\Detached.Mvc.Tests.xproj", "{0035A3D1-C76F-43A2-ABB5-BBA9979A6FDC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -53,10 +53,6 @@ Global
{CAE57FCE-7531-44CE-8A64-0433DAA578D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CAE57FCE-7531-44CE-8A64-0433DAA578D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CAE57FCE-7531-44CE-8A64-0433DAA578D3}.Release|Any CPU.Build.0 = Release|Any CPU
{09D59FB4-FE99-4E3A-B867-32EF550509E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09D59FB4-FE99-4E3A-B867-32EF550509E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09D59FB4-FE99-4E3A-B867-32EF550509E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09D59FB4-FE99-4E3A-B867-32EF550509E0}.Release|Any CPU.Build.0 = Release|Any CPU
{0A133ABC-BE1C-4542-8F0F-DCD3315F30BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A133ABC-BE1C-4542-8F0F-DCD3315F30BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A133ABC-BE1C-4542-8F0F-DCD3315F30BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -69,6 +65,10 @@ Global
{206AF418-85E9-40C6-85F2-58144EFF8059}.Debug|Any CPU.Build.0 = Debug|Any CPU
{206AF418-85E9-40C6-85F2-58144EFF8059}.Release|Any CPU.ActiveCfg = Release|Any CPU
{206AF418-85E9-40C6-85F2-58144EFF8059}.Release|Any CPU.Build.0 = Release|Any CPU
{09D59FB4-FE99-4E3A-B867-32EF550509E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09D59FB4-FE99-4E3A-B867-32EF550509E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09D59FB4-FE99-4E3A-B867-32EF550509E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09D59FB4-FE99-4E3A-B867-32EF550509E0}.Release|Any CPU.Build.0 = Release|Any CPU
{0035A3D1-C76F-43A2-ABB5-BBA9979A6FDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0035A3D1-C76F-43A2-ABB5-BBA9979A6FDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0035A3D1-C76F-43A2-ABB5-BBA9979A6FDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -81,10 +81,10 @@ Global
{25A5DE5A-7F46-4A46-8865-4BB44EBBE13D} = {6CBDF9FC-D22B-426E-A5A6-E4A2D095976E}
{8555F84A-E20D-4C08-A5D6-E50BFC1AD458} = {2A413C2B-93C8-4CD7-BCBE-F6DE1B3ADEA9}
{CAE57FCE-7531-44CE-8A64-0433DAA578D3} = {6CBDF9FC-D22B-426E-A5A6-E4A2D095976E}
{09D59FB4-FE99-4E3A-B867-32EF550509E0} = {6CBDF9FC-D22B-426E-A5A6-E4A2D095976E}
{0A133ABC-BE1C-4542-8F0F-DCD3315F30BC} = {E24B1EB7-4790-4DE9-ADF8-08A2636F6D33}
{EBDDAEB2-00F9-4C93-8ADE-165265549501} = {6CBDF9FC-D22B-426E-A5A6-E4A2D095976E}
{206AF418-85E9-40C6-85F2-58144EFF8059} = {6CBDF9FC-D22B-426E-A5A6-E4A2D095976E}
{09D59FB4-FE99-4E3A-B867-32EF550509E0} = {6CBDF9FC-D22B-426E-A5A6-E4A2D095976E}
{0035A3D1-C76F-43A2-ABB5-BBA9979A6FDC} = {2A413C2B-93C8-4CD7-BCBE-F6DE1B3ADEA9}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,16 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Errors_InternalError_ErrorMessage" xml:space="preserve">
<value>An internal error has occurred. Please try again later or contact '{0}'.</value>
</data>
<data name="Errors_InvalidModel_ErrorMessage" xml:space="preserve">
<value>The submitted data is not valid. Please check the errors and try again.</value>
</data>
<data name="Validation_RegularExpression_ErrorMessage" xml:space="preserve">
<value>Field data is not valid.</value>
<value>Field data is not valid</value>
</data>
<data name="Validation_Required_ErrorMessage" xml:space="preserve">
<value>Field '{0}' is required :)</value>
<value>Field '{0}' is required</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Errors_InternalError_ErrorMessage" xml:space="preserve">
<value>Ha ocurrido un error interno. Por favor intente de nuevo mas tarde o contactese a '{0}'.</value>
</data>
<data name="Errors_InvalidModel_ErrorMessage" xml:space="preserve">
<value>Los datos enviados no son validos. Por favor chequeelos e intentelo nuevamente.</value>
</data>
<data name="Validation_RegularExpression_ErrorMessage" xml:space="preserve">
<value>Los datos no son validos</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
using Detached.Angular2Demo.Server.Security.Users.Model;
using Detached.Angular2Demo.Server.Security.Users.Services;
using Detached.Mvc.Controllers;
using Detached.Mvc.Errors;
using Detached.Mvc.Validation;
using Detached.Services;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace Detached.Angular2Demo.Server.Security.Users.Controllers
{
[ValidateModel]
[LocalizedApiErrors]
[LocalizedModelValidation]
public class UsersController : DetachedController<User, UserQuery>
{
public UsersController(IUserService userService)
: base(userService)
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="UsersController_Save_InternalError" xml:space="preserve">
<value>an internal error happened. damn!</value>
</data>
<data name="User_Name_DisplayName" xml:space="preserve">
<value>Name</value>
</data>
<data name="User_Name_RegularExpression" xml:space="preserve">
<value>The field {0} only accepts lower-case letters</value>
</data>
<data name="User_Name_Required" xml:space="preserve">
<value>The field {0} is required -&gt;Property-specific</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="UsersController_Save_InternalErro" xml:space="preserve">
<value>an internal error happened. damn!</value>
</data>
<data name="User_Name_DisplayName" xml:space="preserve">
<value>Nombre</value>
</data>
<data name="User_Name_RegularExpression" xml:space="preserve">
<value>El campo {0} debe contener solamente letras minusculas</value>
</data>
<data name="User_Name_Required" xml:space="preserve">
<value>El campo {0} es requerido -&gt; Especifico de la propiedad</value>
</data>
</root>
18 changes: 7 additions & 11 deletions demo/Detached.Angular2Demo/Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,17 @@ public void ConfigureServices(IServiceCollection services)
services.AddMvc();

// add a resource mapper.
// this maps .NET type names to a key and resource file/table/etc.
// this maps .NET type names to a key and resource source (file/table/etc).
services.AddResourceMapper(o =>
{
o.SupportInfo = new SupportInfo { Email = "it@example.com" };
o.StringCase = StringCase.PascalCase;
o.FallbackKey = (feat, type, prop) => new ResourceKey { KeyName = $"{feat}_{type}_{prop}", ResourceName = "Server.Common.Resources.Strings" };
o.Rules.Clear();
o.Rules.AddRange(new[] {
// model mapping
new Rule(pattern: "{brand}.{product}.{platform}.{module}.{feature}.{layer}.{model}#{field}!{descriptor}",
keyTemplate: "{model}_{field}_{descriptor}",
sourceTemplate: "Server.{module}.{feature}.Resources.Strings"),
// validators mapping
new Rule(pattern: "System.ComponentModel.DataAnnotations.{validator}Attribute#{property}",
keyTemplate: "Validation_{validator}_{property}",
sourceTemplate: "Server.Common.Resources.Strings")
});
o.Rules.Add(
new Rule(pattern: "{company}.{app}.{platform}.{module}.{feature}.{layer}.{modelOrController}.{fieldOrAction}#{descriptor}",
keyTemplate: "{modelOrController}_{fieldOrAction}_{descriptor}",
sourceTemplate: "{platform}.{module}.{feature}.Resources.Strings"));
})
.AddAutomaticDisplayMetadataLocalization()
.AddAutomaticValidationAttributeLocalization();
Expand Down
4 changes: 2 additions & 2 deletions demo/Detached.Angular2Demo/project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"dependencies": {
"Detached.DataAnnotations": "1.0.0-*",
"Detached.Mvc": "1.0.0-*",
"Detached.Mvc.Localization": "1.0.0-*",
"Detached.Mvc.Controllers": "1.0.0-*",
"Detached.Services": "1.0.0-*",
"Microsoft.AspNetCore.Diagnostics": "1.1.0",
"Microsoft.AspNetCore.Mvc": "1.1.0",
Expand Down Expand Up @@ -62,7 +63,6 @@

"scripts": {
"prepublish": [

],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
},
Expand Down
9 changes: 3 additions & 6 deletions src/Detached.DataAnnotations/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"NETStandard.Library": "1.6.1"
},

"frameworks": {
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System.ComponentModel.DataAnnotations": "",
Expand All @@ -13,11 +13,8 @@
}
}
},
"netstandard1.3": {
"dependencies": {
"System.ComponentModel.Annotations": "4.3.0-*",
"System.Linq.Queryable": "4.3.0-*"
}
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
10 changes: 3 additions & 7 deletions src/Detached.EntityFramework/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"NETStandard.Library": "1.6.1",
"Newtonsoft.Json": "9.0.1"
},
"frameworks": {
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System.ComponentModel.DataAnnotations": "",
Expand All @@ -17,12 +17,8 @@
}
}
},
"netstandard1.3": {
"dependencies": {
"System.ComponentModel.Annotations": "4.3.0-*",
"System.Reflection": "4.3.0-*",
"System.Linq.Queryable": "4.3.0-*"
}
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>206af418-85e9-40c6-85f2-58144eff8059</ProjectGuid>
<RootNamespace>Detached.Mvc.Localization</RootNamespace>
<ProjectGuid>09d59fb4-fe99-4e3a-b867-32ef550509e0</ProjectGuid>
<RootNamespace>Detached.Mvc.Controllers</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// associated with an assembly.
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Detached.Mvc.Localization")]
[assembly: AssemblyProduct("Detached.Mvc")]
[assembly: AssemblyTrademark("")]

// Setting ComVisible to false makes the types in this assembly not visible
Expand All @@ -16,4 +16,4 @@
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("206af418-85e9-40c6-85f2-58144eff8059")]
[assembly: Guid("09d59fb4-fe99-4e3a-b867-32ef550509e0")]
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
"dependencies": {
"Microsoft.AspNetCore.Diagnostics": "1.1.0",
"Microsoft.AspNetCore.Mvc": "1.1.0",
"Microsoft.AspNetCore.Routing": "1.1.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
"Microsoft.Extensions.Configuration.Json": "1.1.0",
"Microsoft.Extensions.Logging": "1.1.0",
"Microsoft.Extensions.Logging.Console": "1.1.0",
"Microsoft.Extensions.Logging.Debug": "1.1.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
"Detached.Services": "1.0.0-*",
"Detached.DataAnnotations": "1.0.0-*",
"NETStandard.Library": "1.6.1"
},
"frameworks": {
Expand Down
19 changes: 0 additions & 19 deletions src/Detached.Mvc.Localization/Mapping/IResourceMapper.cs

This file was deleted.

Loading

0 comments on commit 09b6797

Please sign in to comment.