-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow translations of BTCPay Server Backend by admins
- Loading branch information
1 parent
6437967
commit 7f76afc
Showing
28 changed files
with
866 additions
and
19 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
BTCPayServer.Data/Migrations/20231219031609_translationsmigration.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using BTCPayServer.Data; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
#nullable disable | ||
|
||
namespace BTCPayServer.Migrations | ||
{ | ||
[DbContext(typeof(ApplicationDbContext))] | ||
[Migration("20231219031609_translationsmigration")] | ||
public partial class translationsmigration : Migration | ||
{ | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
if (migrationBuilder.IsNpgsql()) | ||
{ | ||
migrationBuilder.Sql("CREATE TABLE translations (key TEXT NOT NULL PRIMARY KEY, value TEXT NOT NULL)"); | ||
} | ||
} | ||
|
||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
26 changes: 26 additions & 0 deletions
26
BTCPayServer/Controllers/UIServerController.Translations.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Threading.Tasks; | ||
using BTCPayServer.Abstractions.Constants; | ||
using BTCPayServer.Abstractions.Extensions; | ||
using BTCPayServer.Models.ServerViewModels; | ||
using BTCPayServer.Services; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace BTCPayServer.Controllers | ||
{ | ||
public partial class UIServerController | ||
{ | ||
[HttpGet("server/translations")] | ||
public IActionResult ServerTranslations() | ||
{ | ||
return View(new ServerTranslationsViewModel().SetTranslations(_localizer.Translations)); | ||
} | ||
[HttpPost("server/translations")] | ||
public async Task<IActionResult> ServerTranslations(ServerTranslationsViewModel viewModel) | ||
{ | ||
var translation = Translations.CreateFromText(viewModel.Translations); | ||
await _localizer.Save(translation); | ||
TempData[WellKnownTempData.SuccessMessage] = "Translations updated"; | ||
return RedirectToAction(); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using BTCPayServer.Abstractions.Contracts; | ||
using BTCPayServer.Services; | ||
|
||
namespace BTCPayServer.Hosting | ||
{ | ||
public class LoadTranslationsStartupTask(LocalizerService LocalizerService) : IStartupTask | ||
{ | ||
public Task ExecuteAsync(CancellationToken cancellationToken = default) | ||
{ | ||
// Do not make startup longer for this | ||
_ = LocalizerService.Load(); | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
18 changes: 18 additions & 0 deletions
18
BTCPayServer/Models/ServerViewModels/ServerTranslationsViewModel.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using BTCPayServer.Services; | ||
|
||
namespace BTCPayServer.Models.ServerViewModels | ||
{ | ||
public class ServerTranslationsViewModel | ||
{ | ||
public string Translations { get; set; } | ||
public int Lines { get; set; } | ||
|
||
internal ServerTranslationsViewModel SetTranslations(Translations translations) | ||
{ | ||
Translations = translations.ToTextFormat(); | ||
Lines = translations.Records.Count; | ||
return this; | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.