https://github.com/kardelruveyda/dotnet-localization-example
A simple ASP.NET Core MVC example demonstrating how to implement multilingual support using IStringLocalizer and IViewLocalizer with .resx resource files.
https://github.com/kardelruveyda/dotnet-localization-example
dotnet dotnetcore localization mvc
Last synced: 11 months ago
JSON representation
A simple ASP.NET Core MVC example demonstrating how to implement multilingual support using IStringLocalizer and IViewLocalizer with .resx resource files.
- Host: GitHub
- URL: https://github.com/kardelruveyda/dotnet-localization-example
- Owner: KardelRuveyda
- Created: 2025-08-02T22:13:20.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-08-02T22:26:42.000Z (11 months ago)
- Last Synced: 2025-08-03T00:14:52.261Z (11 months ago)
- Topics: dotnet, dotnetcore, localization, mvc
- Language: HTML
- Homepage:
- Size: 1000 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# π MultiLangDemo - ASP.NET Core Localization Example
MultiLangDemo is a sample ASP.NET Core MVC project that demonstrates how to implement **multi-language support** using `IStringLocalizer` and `IViewLocalizer`.
Users can view the site in their preferred language based on browser settings or a query string.
---
## π Project Structure
```
MultiLangDemo/
βββ Controllers/
β βββ HomeController.cs
βββ Views/
β βββ Home/
β βββ Index.cshtml
βββ Resources/
β βββ Views/
β βββ Home/
β βββ Index.en-US.resx
β βββ Index.tr-TR.resx
β βββ Index.de-DE.resx
βββ Program.cs
βββ MultiLangDemo.csproj
βββ README.md
```
---
## π Getting Started
### β
Requirements
- [.NET 9 SDK](https://dotnet.microsoft.com/download)
- Visual Studio Code or Visual Studio 2022+
- Git (optional)
### π§ Setup Instructions
```bash
git clone https://github.com/yourusername/MultiLangDemo.git
cd MultiLangDemo
dotnet restore
dotnet run
```
The application will launch at:
π https://localhost:5001
---
## π Testing Localization
You can switch the UI language by appending `?ui-culture=xx-XX` to the URL:
| Language | URL Example |
|----------|--------------------------------------------------|
| πΊπΈ English | `https://localhost:5001/?ui-culture=en-US` |
| πΉπ· Turkish | `https://localhost:5001/?ui-culture=tr-TR` |
| π©πͺ German | `https://localhost:5001/?ui-culture=de-DE` |
---
## π§© Key Concepts
- `IViewLocalizer`: Used in Razor Views to localize UI content.
- `IStringLocalizer`: Used in controllers or services to retrieve localized strings.
- `.resx` Files: Resource files that store key-value pairs for each supported culture.
---
## π‘ Sample Output
When visiting `https://localhost:5001/?ui-culture=tr-TR`:
```
HoΕ geldiniz!
Aktif dil: tr-TR
```
When visiting `https://localhost:5001/?ui-culture=en-US`:
```
Welcome to our site!
Active culture: en-US
```
---
## β Adding a New Language
To add support for French:
1. Create a new resource file:
`Resources/Views/Home/Index.fr-FR.resx`
2. Add translation keys and values:
| Name | Value |
|-----------------|----------------------------|
| WelcomeMessage | Bienvenue sur notre site |
3. Add `fr-FR` to the supported cultures list in `Program.cs`.
---
## π Security Note
If you encounter a warning like:
```
Package 'System.Text.RegularExpressions' 4.3.0 has a known high severity vulnerability
```
You can upgrade the package using:
```bash
dotnet add package System.Text.RegularExpressions --version 4.3.1
```
---
## π License
This project is licensed under the MIT License.