Files
game-ideas/src/GameIdeas/Server/GameIdeas.WebAPI/Controllers/TranslationsController.cs
2025-02-17 13:49:01 +01:00

36 lines
841 B
C#

using Microsoft.AspNetCore.Mvc;
namespace GameIdeas.WebAPI.Controllers;
[ApiController]
[Route("api/[controller]")]
public class TranslationsController (ILogger<TranslationsController> Logger) : ControllerBase
{
[HttpGet]
public async Task<IActionResult> GetTranslations()
{
var dictionary = new Dictionary<string, string>();
try
{
var filesDirectory = Path.Combine(
Directory.GetCurrentDirectory(),
"Files");
var translationFiles = Directory.GetFiles(filesDirectory, "*.json");
foreach (var file in translationFiles)
{
var name = file.Split('.');
var culture = name[^2];
var content = await System.IO.File.ReadAllTextAsync(file);
dictionary.Add(culture, content);
}
}
catch(Exception ex)
{
Logger.LogError(ex, "Internal translations error");
}
return Ok(dictionary);
}
}