Skip to content

Commit

Permalink
Localization - First Pass (Kareadita#2174)
Browse files Browse the repository at this point in the history
* Started designing the backend localization service

* Worked in Transloco for initial PoC

* Worked in Transloco for initial PoC

* Translated the login screen

* translated dashboard screen

* Started work on the backend

* Fixed a logic bug

* translated edit-user screen

* Hooked up the backend for having a locale property.

* Hooked up the ability to view the available locales and switch to them.

* Made the localization service languages be derived from what's in langs/ directory.

* Fixed up localization switching

* Switched when we check for a license on UI bootstrap

* Tweaked some code

* Fixed the bug where dashboard wasn't loading and made it so language switching is working.

* Fixed a bug on dashboard with languagePath

* Converted user-scrobble-history.component.html

* Converted spoiler.component.html

* Converted review-series-modal.component.html

* Converted review-card-modal.component.html

* Updated the readme

* Translated using Weblate (English)

Currently translated at 100.0% (54 of 54 strings)

Translation: Kavita/ui
Translate-URL: https://hosted.weblate.org/projects/kavita/ui/en/

* Converted review-card.component.html

* Deleted dead component

* Converted want-to-read.component.html

* Added translation using Weblate (Korean)

* Translated using Weblate (Spanish)

Currently translated at 40.7% (22 of 54 strings)

Translation: Kavita/ui
Translate-URL: https://hosted.weblate.org/projects/kavita/ui/es/

* Translated using Weblate (Korean)

Currently translated at 62.9% (34 of 54 strings)

Translation: Kavita/ui
Translate-URL: https://hosted.weblate.org/projects/kavita/ui/ko/

* Converted user-preferences.component.html

* Translated using Weblate (Korean)

Currently translated at 92.5% (50 of 54 strings)

Translation: Kavita/ui
Translate-URL: https://hosted.weblate.org/projects/kavita/ui/ko/

* Converted user-holds.component.html

* Converted theme-manager.component.html

* Converted restriction-selector.component.html

* Converted manage-devices.component.html

* Converted edit-device.component.html

* Converted change-password.component.html

* Converted change-email.component.html

* Converted change-age-restriction.component.html

* Converted api-key.component.html

* Converted anilist-key.component.html

* Converted typeahead.component.html

* Converted user-stats-info-cards.component.html

* Converted user-stats.component.html

* Converted top-readers.component.html

* Converted some pipes and ensure translation is loaded before the app.

* Finished all but one pipe for localization

* Converted directory-picker.component.html

* Converted library-access-modal.component.html

* Converted a few components

* Converted a few components

* Converted a few components

* Converted a few components

* Converted a few components

* Merged weblate in

* ... -> … update

* Updated the readme

* Updateded all fonts to be woff2

* Cleaned up some strings to increase re-use

* Removed an old flow (that doesn't exist in backend any longer) from when we introduced emails on Kavita.

* Converted Series detail

* Lots more converted

* Lots more converted & hooked up the ability to flatten during prod build the language files.

* Lots more converted

* Lots more converted & fixed a bunch of broken pipes due to inject()

* Lots more converted

* Lots more converted

* Lots more converted & fixed some bad keys

* Lots more converted

* Fixed some bugs with admin dasbhoard nested tabs not rendering on first load due to not using onpush change detection

* Fixed up some localization errors and fixed forgot password error when the user doesn't have change password permission

* Fixed a stupid build issue again

* Started adding errors for interceptor and backend.

* Finished off manga-reader

* More translations

* Few fixes

* Fixed a bug where character tag badges weren't showing the name on chapter info

* All components are translated

* All toasts are translated

* All confirm/alerts are translated

* Trying something new for the backend

* Migrated the localization strings for the backend into a new file.

* Updated the localization service to be able to do backend localization with fallback to english.

* Cleaned up some external reviews code to reduce looping

* Localized AccountController.cs

* 60% done with controllers

* All controllers are done

* All KavitaExceptions are covered

* Some shakeout fixes

* Prep for initial merge

* Everything is done except options and basic shakeout proves response times are good. Unit tests are broken.

* Fixed up the unit tests

* All unit tests are now working

* Removed some quantifier

* I'm not sure I can support localization for some Volume/Chapter/Book strings within the codebase.

---------

Co-authored-by: Robbie Davis <[email protected]>
Co-authored-by: majora2007 <[email protected]>
Co-authored-by: expertjun <[email protected]>
Co-authored-by: ThePromidius <[email protected]>
  • Loading branch information
5 people authored Aug 3, 2023
1 parent 670bf82 commit 3b23d63
Show file tree
Hide file tree
Showing 389 changed files with 13,444 additions and 7,717 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ jobs:
cd UI/Web || exit
echo 'Installing web dependencies'
npm ci
npm install --legacy-peer-deps
echo 'Building UI'
npm run prod
Expand Down
6 changes: 3 additions & 3 deletions API.Tests/Services/ReadingListServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ public async Task CreateReadingList_ShouldNotCreate_WhenExistingList()
}
catch (Exception ex)
{
Assert.Equal("A list of this name already exists", ex.Message);
Assert.Equal("reading-list-name-exists", ex.Message);
}
Assert.Single((await _unitOfWork.UserRepository.GetUserByIdAsync(1, AppUserIncludes.ReadingLists))
.ReadingLists);
Expand Down Expand Up @@ -834,7 +834,7 @@ await _readingListService.UpdateReadingList(list,
}
catch (Exception ex)
{
Assert.Equal("A list of this name already exists", ex.Message);
Assert.Equal("reading-list-name-exists", ex.Message);
}
}

Expand All @@ -860,7 +860,7 @@ public async Task DeleteReadingList_ShouldDelete()
}
catch (Exception ex)
{
Assert.Equal("A list of this name already exists", ex.Message);
Assert.Equal("reading-list-name-exists", ex.Message);
}
Assert.Single((await _unitOfWork.UserRepository.GetUserByIdAsync(1, AppUserIncludes.ReadingLists))
.ReadingLists);
Expand Down
149 changes: 130 additions & 19 deletions API.Tests/Services/SeriesServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Linq;
using System.Threading.Tasks;
using API.Data;
Expand All @@ -19,21 +20,48 @@
using API.Tests.Helpers;
using Hangfire;
using Hangfire.InMemory;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Hosting.Internal;
using Microsoft.Extensions.Logging;
using NSubstitute;
using Xunit;

namespace API.Tests.Services;

internal class MockHostingEnvironment : IHostEnvironment {
public string ApplicationName { get => "API"; set => throw new NotImplementedException(); }
public IFileProvider ContentRootFileProvider { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

public string ContentRootPath
{
get => throw new NotImplementedException();
set => throw new NotImplementedException();
}

public string EnvironmentName { get => "Testing"; set => throw new NotImplementedException(); }
}


public class SeriesServiceTests : AbstractDbTest
{
private readonly ISeriesService _seriesService;

public SeriesServiceTests() : base()
{
var ds = new DirectoryService(Substitute.For<ILogger<DirectoryService>>(), new FileSystem()
{

});


var locService = new LocalizationService(ds, new MockHostingEnvironment(),
Substitute.For<IMemoryCache>(), Substitute.For<IUnitOfWork>());

_seriesService = new SeriesService(_unitOfWork, Substitute.For<IEventHub>(),
Substitute.For<ITaskScheduler>(), Substitute.For<ILogger<SeriesService>>(),
Substitute.For<IScrobblingService>());
Substitute.For<IScrobblingService>(), locService);
}
#region Setup

Expand Down Expand Up @@ -1194,69 +1222,152 @@ public async Task SeriesRelation_ShouldAllowDeleteOnLibrary_WhenSeriesCrossLibra
[InlineData(LibraryType.Comic, false, "Issue")]
[InlineData(LibraryType.Comic, true, "Issue #")]
[InlineData(LibraryType.Book, false, "Book")]
public void FormatChapterNameTest(LibraryType libraryType, bool withHash, string expected )
public async Task FormatChapterNameTest(LibraryType libraryType, bool withHash, string expected )
{
Assert.Equal(expected, SeriesService.FormatChapterName(libraryType, withHash));
await ResetDb();

_context.Library.Add(new LibraryBuilder("Test LIb")
.WithAppUser(new AppUserBuilder("majora2007", string.Empty)
.WithLocale("en")
.Build())
.Build());

await _context.SaveChangesAsync();

Assert.Equal(expected, await _seriesService.FormatChapterName(1, libraryType, withHash));
}

#endregion

#region FormatChapterTitle

[Fact]
public void FormatChapterTitle_Manga_NonSpecial()
public async Task FormatChapterTitle_Manga_NonSpecial()
{
await ResetDb();

_context.Library.Add(new LibraryBuilder("Test LIb")
.WithAppUser(new AppUserBuilder("majora2007", string.Empty)
.WithLocale("en")
.Build())
.Build());

await _context.SaveChangesAsync();

var chapter = new ChapterBuilder("1").WithTitle("Some title").WithIsSpecial(false).Build();
Assert.Equal("Chapter Some title", SeriesService.FormatChapterTitle(chapter, LibraryType.Manga, false));
Assert.Equal("Chapter Some title", await _seriesService.FormatChapterTitle(1, chapter, LibraryType.Manga, false));
}

[Fact]
public void FormatChapterTitle_Manga_Special()
public async Task FormatChapterTitle_Manga_Special()
{
await ResetDb();

_context.Library.Add(new LibraryBuilder("Test LIb")
.WithAppUser(new AppUserBuilder("majora2007", string.Empty)
.WithLocale("en")
.Build())
.Build());

await _context.SaveChangesAsync();
var chapter = new ChapterBuilder("1").WithTitle("Some title").WithIsSpecial(true).Build();
Assert.Equal("Some title", SeriesService.FormatChapterTitle(chapter, LibraryType.Manga, false));
Assert.Equal("Some title", await _seriesService.FormatChapterTitle(1, chapter, LibraryType.Manga, false));
}

[Fact]
public void FormatChapterTitle_Comic_NonSpecial_WithoutHash()
public async Task FormatChapterTitle_Comic_NonSpecial_WithoutHash()
{
await ResetDb();

_context.Library.Add(new LibraryBuilder("Test LIb")
.WithAppUser(new AppUserBuilder("majora2007", string.Empty)
.WithLocale("en")
.Build())
.Build());

await _context.SaveChangesAsync();
var chapter = new ChapterBuilder("1").WithTitle("Some title").WithIsSpecial(false).Build();
Assert.Equal("Issue Some title", SeriesService.FormatChapterTitle(chapter, LibraryType.Comic, false));
Assert.Equal("Issue Some title", await _seriesService.FormatChapterTitle(1, chapter, LibraryType.Comic, false));
}

[Fact]
public void FormatChapterTitle_Comic_Special_WithoutHash()
public async Task FormatChapterTitle_Comic_Special_WithoutHash()
{
await ResetDb();

_context.Library.Add(new LibraryBuilder("Test LIb")
.WithAppUser(new AppUserBuilder("majora2007", string.Empty)
.WithLocale("en")
.Build())
.Build());

await _context.SaveChangesAsync();
var chapter = new ChapterBuilder("1").WithTitle("Some title").WithIsSpecial(true).Build();
Assert.Equal("Some title", SeriesService.FormatChapterTitle(chapter, LibraryType.Comic, false));
Assert.Equal("Some title", await _seriesService.FormatChapterTitle(1, chapter, LibraryType.Comic, false));
}

[Fact]
public void FormatChapterTitle_Comic_NonSpecial_WithHash()
public async Task FormatChapterTitle_Comic_NonSpecial_WithHash()
{
await ResetDb();

_context.Library.Add(new LibraryBuilder("Test LIb")
.WithAppUser(new AppUserBuilder("majora2007", string.Empty)
.WithLocale("en")
.Build())
.Build());

await _context.SaveChangesAsync();
var chapter = new ChapterBuilder("1").WithTitle("Some title").WithIsSpecial(false).Build();
Assert.Equal("Issue #Some title", SeriesService.FormatChapterTitle(chapter, LibraryType.Comic, true));
Assert.Equal("Issue #Some title", await _seriesService.FormatChapterTitle(1, chapter, LibraryType.Comic, true));
}

[Fact]
public void FormatChapterTitle_Comic_Special_WithHash()
public async Task FormatChapterTitle_Comic_Special_WithHash()
{
await ResetDb();

_context.Library.Add(new LibraryBuilder("Test LIb")
.WithAppUser(new AppUserBuilder("majora2007", string.Empty)
.WithLocale("en")
.Build())
.Build());

await _context.SaveChangesAsync();
var chapter = new ChapterBuilder("1").WithTitle("Some title").WithIsSpecial(true).Build();
Assert.Equal("Some title", SeriesService.FormatChapterTitle(chapter, LibraryType.Comic, true));
Assert.Equal("Some title", await _seriesService.FormatChapterTitle(1, chapter, LibraryType.Comic, true));
}

[Fact]
public void FormatChapterTitle_Book_NonSpecial()
public async Task FormatChapterTitle_Book_NonSpecial()
{
await ResetDb();

_context.Library.Add(new LibraryBuilder("Test LIb")
.WithAppUser(new AppUserBuilder("majora2007", string.Empty)
.WithLocale("en")
.Build())
.Build());

await _context.SaveChangesAsync();
var chapter = new ChapterBuilder("1").WithTitle("Some title").WithIsSpecial(false).Build();
Assert.Equal("Book Some title", SeriesService.FormatChapterTitle(chapter, LibraryType.Book, false));
Assert.Equal("Book Some title", await _seriesService.FormatChapterTitle(1, chapter, LibraryType.Book, false));
}

[Fact]
public void FormatChapterTitle_Book_Special()
public async Task FormatChapterTitle_Book_Special()
{
await ResetDb();

_context.Library.Add(new LibraryBuilder("Test LIb")
.WithAppUser(new AppUserBuilder("majora2007", string.Empty)
.WithLocale("en")
.Build())
.Build());

await _context.SaveChangesAsync();
var chapter = new ChapterBuilder("1").WithTitle("Some title").WithIsSpecial(true).Build();
Assert.Equal("Some title", SeriesService.FormatChapterTitle(chapter, LibraryType.Book, false));
Assert.Equal("Some title", await _seriesService.FormatChapterTitle(1, chapter, LibraryType.Book, false));
}

#endregion
Expand Down
1 change: 1 addition & 0 deletions API/API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@

<ItemGroup>
<Folder Include="config\themes" />
<Folder Include="I18N\**" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 3b23d63

Please sign in to comment.