Migrate from .resx + *.Designer.cs to IStringLocalizer for ASP.NET Core-native localization#83
Draft
Migrate from .resx + *.Designer.cs to IStringLocalizer for ASP.NET Core-native localization#83
Conversation
Co-authored-by: Matt-17 <11333169+Matt-17@users.noreply.github.com>
Co-authored-by: Matt-17 <11333169+Matt-17@users.noreply.github.com>
Co-authored-by: Matt-17 <11333169+Matt-17@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Improvement of Localization
Migrate from .resx + *.Designer.cs to IStringLocalizer for ASP.NET Core-native localization
Sep 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR migrates Gibbon Git Server from the legacy
.resx+*.Designer.cslocalization pattern to ASP.NET Core's nativeIStringLocalizerapproach, eliminating generated designer files from source control and modernizing the localization infrastructure.Problem
The current localization implementation had several issues:
*.Designer.csfiles caused frequent merge conflicts - These auto-generated files changed across branches and Visual Studio versions, creating noisy diffsSolution
Migrated to the recommended ASP.NET Core localization stack using
IStringLocalizerwith runtime resource lookup:Before:
After:
Views Before:
Views After:
Changes Made
Infrastructure
Resources.Designer.cs(1 generated file)SharedResourcemarker class forIStringLocalizer<T>App_Resources/toResources/folderResources.*.resx→SharedResource.*.resxProgram.cs:AddLocalization(options => options.ResourcesPath = "Resources")AddViewLocalization()for Razor viewsAddDataAnnotationsLocalization()for model validationCode Updates
IStringLocalizer<SharedResource>ResourceTypeattributes from DataAnnotations@Resources.Keywith@Localizer["Key"]IViewLocalizerinjection via_ViewImports.cshtmlResourcesimport fromGlobalUsings.csTesting
Repository Hygiene
.gitignorerules to exclude future Designer.cs files:Test Results
All tests passing ✅
Supported Languages (17)
English (neutral), Afrikaans, Czech, Danish, German, Spanish, French, Italian, Japanese, Polish, Portuguese, Russian, Swedish, Turkish, Chinese (Simplified), Chinese (Hong Kong), Chinese (Traditional)
Benefits
.resxfiles committed, generated code stays out of GitMigration Notes
SharedResourceclass serves as the marker type forIStringLocalizer<T>CultureMiddlewareremains unchangedRollback Plan
If needed, rollback is straightforward:
ResXFileCodeGeneratorin Visual StudioResourcesclass.gitignorerulesFixes #[issue-number]
Closes #[issue-number]
Original prompt
This section details on the original issue you should resolve
<issue_title>Improvement of Localization</issue_title>
<issue_description>The current localization is a bit outdated. Recreation of
Resources.Designer.cscauses git to think it changed. Removing this file alone does not allow build without explicit recreation.There is an approach in:
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/localization/make-content-localizable?view=aspnetcore-9.0
Migrate from
.resx+*.Designer.cstoIStringLocalizer(no designer files)Type: refactor ♻️ · Area: localization 🌍 · Priority: high
Goal: Eliminate
*.Designer.cschurn/diffs and adopt the ASP.NET Core-native localization stack (IStringLocalizer/IViewLocalizer), keeping only.resxfiles in source control.Why
*.Designer.csare generated and frequently re-written across branches/VS versions → noisy diffs and merge conflicts.IStringLocalizer(runtime lookup from embedded.resx)..resxcommitted; generated code stays out of Git.Out of scope
Plan (high level)
Program.cs.Resources/and ensure Build Action = Embedded resource.Resources.MyStrings.SomeKey(designer props) with_localizer["SomeKey"](orLocalizer["SomeKey"]in views)..gitignorerules after deleting designer files.Detailed tasks & checklists
0) Remove designer files (first!)
*.Designer.csgenerated from.resx..csprojhas no<Compile Include="...Designer.cs" />..gitignoreyet; do that after this commit).1) Enable localization services & middleware
Program.cs:Acceptance: App chooses translations based on
Accept-Languageheader or explicit culture.2) Resource file layout
Resources/at the project root if it doesn’t exist.Resources/SharedResource.resx(neutral)Resources/SharedResource.de.resx,Resources/SharedResource.en.resx, …Resources/Controllers.HomeController.resx,Resources/Controllers.HomeController.de.resx, ….resxhas Build Action = Embedded resource (default in SDK-style projects).3) Replace designer usages
Before (designer style):
After (localizer style):