Ozcorps.Localization
9.0.0
dotnet add package Ozcorps.Localization --version 9.0.0
NuGet\Install-Package Ozcorps.Localization -Version 9.0.0
<PackageReference Include="Ozcorps.Localization" Version="9.0.0" />
<PackageVersion Include="Ozcorps.Localization" Version="9.0.0" />
<PackageReference Include="Ozcorps.Localization" />
paket add Ozcorps.Localization --version 9.0.0
#r "nuget: Ozcorps.Localization, 9.0.0"
#:package Ozcorps.Localization@9.0.0
#addin nuget:?package=Ozcorps.Localization&version=9.0.0
#tool nuget:?package=Ozcorps.Localization&version=9.0.0
Ozcorps.Localization
A lightweight, database-driven localization library for .NET 8. Manages multilingual translations stored in PostgreSQL, with built-in in-memory caching, platform-based word filtering, and full CRUD services for languages and translations.
Features
- Database-driven translations (no JSON/RESX files needed)
- Supports PostgreSQL (
Npgsql) - In-memory caching with configurable expiration (default: 30 minutes)
- Platform-based word filtering via
PlatformId - Full CRUD services:
ILanguageService,ILanguageWordService,ILanguageWordTypeService - Simple DI setup with a single extension method call
Installation
dotnet add package Ozcorps.Localization
Database Setup
The library expects three tables: language, language_word, and language_word_type.
PostgreSQL example:
CREATE TABLE language (
id UUID PRIMARY KEY,
key VARCHAR(200),
name VARCHAR(300),
is_active BOOLEAN DEFAULT true,
is_deleted BOOLEAN DEFAULT false,
created_at TIMESTAMP WITHOUT TIME ZONE,
created_by_id UUID,
updated_at TIMESTAMP WITHOUT TIME ZONE,
updated_by_id UUID
);
CREATE TABLE language_word_type (
id UUID PRIMARY KEY,
name VARCHAR(300),
is_active BOOLEAN DEFAULT true,
is_deleted BOOLEAN DEFAULT false,
created_at TIMESTAMP WITHOUT TIME ZONE,
created_by_id UUID,
updated_at TIMESTAMP WITHOUT TIME ZONE,
updated_by_id UUID
);
CREATE TABLE language_word (
id UUID PRIMARY KEY,
language_id UUID,
language_word_type_id UUID,
platform_id BIGINT NOT NULL DEFAULT 1,
key VARCHAR(200),
value VARCHAR(300),
is_active BOOLEAN DEFAULT true,
is_deleted BOOLEAN DEFAULT false,
created_at TIMESTAMP WITHOUT TIME ZONE,
created_by_id UUID,
updated_at TIMESTAMP WITHOUT TIME ZONE,
updated_by_id UUID
);
Sample data:
INSERT INTO language (id, key, name, is_active, is_deleted, created_at, created_by_id)
VALUES (gen_random_uuid(), 'tr', 'Türkçe', true, false, now(), gen_random_uuid());
INSERT INTO language (id, key, name, is_active, is_deleted, created_at, created_by_id)
VALUES (gen_random_uuid(), 'en', 'English', true, false, now(), gen_random_uuid());
Registration
builder.Services.AddLocalization("Host=localhost;Database=mydb;Username=user;Password=pass");
Accepts an optional shouldAddLanguageServices parameter (default: true). Set it to false if you only need LocalizationTool without the CRUD services.
// Only LocalizationTool, no CRUD services
builder.Services.AddLocalization(connectionString, shouldAddLanguageServices: false);
Usage
Inject LocalizationTool
public class ProductController : ControllerBase
{
private readonly LocalizationTool _localization;
public ProductController(LocalizationTool localization)
{
_localization = localization;
}
[HttpGet]
public IActionResult Get([FromQuery] string lang = "tr")
{
var message = _localization.Get(lang, "welcome_message");
return Ok(message);
}
}
Get all words for a language (dictionary)
// Get all words
var words = _localization.GetWords("en");
// Get words filtered by platform
var words = _localization.GetWords("en", platformId: 2);
Clear the cache
_localization.Refresh();
CRUD Services
When shouldAddLanguageServices: true (default), three services are registered:
| Interface | Description |
|---|---|
ILanguageService |
Manage languages (add, update, remove, paginate) |
ILanguageWordService |
Manage translation entries |
ILanguageWordTypeService |
Manage word type categories |
Each service provides: Get, GetAll, Add, Update, Remove, Paginate, Any.
Configuration Summary
| Extension Method | Database | Cache | CRUD Services |
|---|---|---|---|
AddLocalization |
PostgreSQL | IMemoryCache (30 min) |
Optional |
License
MIT © ozcorps
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 8.0.11)
- Ozcorps.Generic (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.