Version Fix and Locale Updates (#3626)
This commit is contained in:
parent
b644022f30
commit
a6ccae5849
15 changed files with 360 additions and 58 deletions
|
@ -193,7 +193,6 @@ public class LibraryController : BaseApiController
|
|||
|
||||
var ret = _unitOfWork.LibraryRepository.GetLibraryDtosForUsernameAsync(username).ToList();
|
||||
await _libraryCacheProvider.SetAsync(CacheKey, ret, TimeSpan.FromHours(24));
|
||||
_logger.LogDebug("Caching libraries for {Key}", cacheKey);
|
||||
|
||||
return Ok(ret.Find(l => l.Id == libraryId));
|
||||
}
|
||||
|
|
|
@ -2,9 +2,15 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.Constants;
|
||||
using API.DTOs.Filtering;
|
||||
using API.Services;
|
||||
using EasyCaching.Core;
|
||||
using Kavita.Common.EnvironmentInfo;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
|
@ -13,43 +19,34 @@ namespace API.Controllers;
|
|||
public class LocaleController : BaseApiController
|
||||
{
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly IEasyCachingProvider _localeCacheProvider;
|
||||
|
||||
public LocaleController(ILocalizationService localizationService)
|
||||
private static readonly string CacheKey = "locales_" + BuildInfo.Version;
|
||||
|
||||
public LocaleController(ILocalizationService localizationService, IEasyCachingProviderFactory cachingProviderFactory)
|
||||
{
|
||||
_localizationService = localizationService;
|
||||
_localeCacheProvider = cachingProviderFactory.GetCachingProvider(EasyCacheProfiles.LocaleOptions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all applicable locales on the server
|
||||
/// </summary>
|
||||
/// <remarks>This can be cached as it will not change per version.</remarks>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> GetAllLocales()
|
||||
public async Task<ActionResult<IEnumerable<KavitaLocale>>> GetAllLocales()
|
||||
{
|
||||
// Check if temp/locale_map.json exists
|
||||
var result = await _localeCacheProvider.GetAsync<IEnumerable<KavitaLocale>>(CacheKey);
|
||||
if (result.HasValue)
|
||||
{
|
||||
return Ok(result.Value);
|
||||
}
|
||||
|
||||
// If not, scan the 2 locale files and calculate empty keys or empty values
|
||||
var ret = _localizationService.GetLocales().Where(l => l.TranslationCompletion > 0f);
|
||||
await _localeCacheProvider.SetAsync(CacheKey, ret, TimeSpan.FromDays(7));
|
||||
|
||||
// Formulate the Locale object with Percentage
|
||||
var languages = _localizationService.GetLocales().Select(c =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var cult = new CultureInfo(c);
|
||||
return new LanguageDto()
|
||||
{
|
||||
Title = cult.DisplayName,
|
||||
IsoCode = cult.IetfLanguageTag
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Some OS' don't have all culture codes supported like PT_BR, thus we need to default
|
||||
return new LanguageDto()
|
||||
{
|
||||
Title = c,
|
||||
IsoCode = c
|
||||
};
|
||||
}
|
||||
})
|
||||
.Where(l => !string.IsNullOrEmpty(l.IsoCode))
|
||||
.OrderBy(d => d.Title);
|
||||
return Ok(languages);
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -150,7 +150,7 @@ public class UsersController : BaseApiController
|
|||
}
|
||||
|
||||
|
||||
if (_localizationService.GetLocales().Contains(preferencesDto.Locale))
|
||||
if (_localizationService.GetLocales().Select(l => l.FileName).Contains(preferencesDto.Locale))
|
||||
{
|
||||
existingPreferences.Locale = preferencesDto.Locale;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue