using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
namespace gehGassi.Web.Controllers
{
///
/// Controller für die Sprachverwaltung
///
public class LanguageController : Controller
{
private readonly IStringLocalizerFactory _localizer;
///
/// Erstellt eine Instanz
///
///
public LanguageController(IStringLocalizerFactory localizer)
{
_localizer = localizer;
}
///
/// Gibt die Ressource "Client" als Json-Dictionary zurück
///
/// Gewünschte Ressource
/// Gewünchte Sprache ISO2 code
/// Versionsnummer wegen Caching
/// Json-Dictionary
#if DEBUG
[ResponseCache(Duration = 1, VaryByQueryKeys = new[] { "resource", "lang", "version" })]
#else
[ResponseCache(CacheProfileName = "ResourcesCache")]
#endif
public ActionResult GetResource(string resource, string lang, string version)
{
var localizer = _localizer.Create(resource, "Localization");
var items = localizer.GetAllStrings();
Dictionary dictionary = items.ToDictionary(k => k.Name, v => v.Value);
return Json(dictionary);
}
}
}