Movies now show in the specified user language

This commit is contained in:
tidusjar 2020-06-11 21:29:59 +01:00
parent fbd88248c0
commit fdd856bb9f
11 changed files with 45 additions and 20 deletions

View file

@ -162,16 +162,21 @@ namespace Ombi.Core.Engine
} }
} }
private string defaultLangCode;
protected async Task<string> DefaultLanguageCode(string currentCode) protected async Task<string> DefaultLanguageCode(string currentCode)
{ {
if (currentCode.HasValue()) if (currentCode.HasValue())
{ {
return currentCode; return currentCode;
} }
var user = await GetUser();
var s = await GetOmbiSettings(); if (string.IsNullOrEmpty(user.Language))
return s.DefaultLanguageCode; {
var s = await GetOmbiSettings();
return s.DefaultLanguageCode;
}
return user.Language;
} }
private OmbiSettings ombiSettings; private OmbiSettings ombiSettings;

View file

@ -8,6 +8,6 @@ namespace Ombi.Core.Engine.V2
{ {
public interface IMultiSearchEngine public interface IMultiSearchEngine
{ {
Task<List<MultiSearchResult>> MultiSearch(string searchTerm, CancellationToken cancellationToken, string lang = "en"); Task<List<MultiSearchResult>> MultiSearch(string searchTerm, CancellationToken cancellationToken);
} }
} }

View file

@ -36,8 +36,9 @@ namespace Ombi.Core.Engine.V2
private readonly IMusicBrainzApi _musicApi; private readonly IMusicBrainzApi _musicApi;
public async Task<List<MultiSearchResult>> MultiSearch(string searchTerm, CancellationToken cancellationToken, string lang = "en") public async Task<List<MultiSearchResult>> MultiSearch(string searchTerm, CancellationToken cancellationToken)
{ {
var lang = await DefaultLanguageCode(null);
var model = new List<MultiSearchResult>(); var model = new List<MultiSearchResult>();
var movieDbData = (await _movieDbApi.MultiSearch(searchTerm, lang, cancellationToken)).results; var movieDbData = (await _movieDbApi.MultiSearch(searchTerm, lang, cancellationToken)).results;

View file

@ -13,6 +13,7 @@ namespace Ombi.Core.Models.UI
public string EmailAddress { get; set; } public string EmailAddress { get; set; }
public string Password { get; set; } public string Password { get; set; }
public DateTime? LastLoggedIn { get; set; } public DateTime? LastLoggedIn { get; set; }
public string Language { get; set; }
public bool HasLoggedIn { get; set; } public bool HasLoggedIn { get; set; }
public UserType UserType { get; set; } public UserType UserType { get; set; }
public int MovieRequestLimit { get; set; } public int MovieRequestLimit { get; set; }

View file

@ -5,7 +5,7 @@ import { NavigationStart, Router } from "@angular/router";
import { TranslateService } from "@ngx-translate/core"; import { TranslateService } from "@ngx-translate/core";
import { AuthService } from "./auth/auth.service"; import { AuthService } from "./auth/auth.service";
import { ILocalUser } from "./auth/IUserLogin"; import { ILocalUser } from "./auth/IUserLogin";
import { NotificationService, CustomPageService } from "./services"; import { NotificationService, CustomPageService, IdentityService } from "./services";
import { SettingsService } from "./services"; import { SettingsService } from "./services";
import { MatSnackBar } from '@angular/material/snack-bar'; import { MatSnackBar } from '@angular/material/snack-bar';
@ -49,21 +49,26 @@ export class AppComponent implements OnInit {
private storage: StorageService, private storage: StorageService,
private signalrNotification: SignalRNotificationService, private signalrNotification: SignalRNotificationService,
private readonly snackBar: MatSnackBar, private readonly snackBar: MatSnackBar,
@Inject(DOCUMENT) private document: HTMLDocument) { private readonly identity: IdentityService,
@Inject(DOCUMENT) private document: HTMLDocument) {
this.translate.addLangs(["en", "de", "fr", "da", "es", "it", "nl", "sk", "sv", "no", "pl", "pt"]); this.translate.addLangs(["en", "de", "fr", "da", "es", "it", "nl", "sk", "sv", "no", "pl", "pt"]);
const selectedLang = this.storage.get("Language"); if (this.authService.loggedIn()) {
this.identity.getUser().subscribe(u => {
if (u.language) {
this.translate.use(u.language);
}
});
}
// this language will be used as a fallback when a translation isn't found in the current language // this language will be used as a fallback when a translation isn't found in the current language
this.translate.setDefaultLang("en"); this.translate.setDefaultLang("en");
if (selectedLang) {
this.translate.use(selectedLang); // See if we can match the supported langs with the current browser lang
} else { const browserLang: string = translate.getBrowserLang();
// See if we can match the supported langs with the current browser lang this.translate.use(browserLang.match(/en|fr|da|de|es|it|nl|sk|sv|no|pl|pt/) ? browserLang : "en");
const browserLang: string = translate.getBrowserLang();
this.translate.use(browserLang.match(/en|fr|da|de|es|it|nl|sk|sv|no|pl|pt/) ? browserLang : "en");
}
} }
public ngOnInit() { public ngOnInit() {

View file

@ -15,6 +15,7 @@ export interface IUser {
episodeRequestLimit: number; episodeRequestLimit: number;
musicRequestLimit: number; musicRequestLimit: number;
userAccessToken: string; userAccessToken: string;
language: string;
userQualityProfiles: IUserQualityProfiles; userQualityProfiles: IUserQualityProfiles;
// FOR UI // FOR UI

View file

@ -9,6 +9,7 @@ import { AuthService } from "../../../auth/auth.service";
import { IMovieRequests, RequestType, IAdvancedData } from "../../../interfaces"; import { IMovieRequests, RequestType, IAdvancedData } from "../../../interfaces";
import { DenyDialogComponent } from "../shared/deny-dialog/deny-dialog.component"; import { DenyDialogComponent } from "../shared/deny-dialog/deny-dialog.component";
import { NewIssueComponent } from "../shared/new-issue/new-issue.component"; import { NewIssueComponent } from "../shared/new-issue/new-issue.component";
import { StorageService } from "../../../shared/storage/storage-service";
@Component({ @Component({
templateUrl: "./movie-details.component.html", templateUrl: "./movie-details.component.html",
@ -29,7 +30,8 @@ export class MovieDetailsComponent {
constructor(private searchService: SearchV2Service, private route: ActivatedRoute, constructor(private searchService: SearchV2Service, private route: ActivatedRoute,
private sanitizer: DomSanitizer, private imageService: ImageService, private sanitizer: DomSanitizer, private imageService: ImageService,
public dialog: MatDialog, private requestService: RequestService, public dialog: MatDialog, private requestService: RequestService,
public messageService: MessageService, private auth: AuthService) { public messageService: MessageService, private auth: AuthService,
private storage: StorageService) {
this.route.params.subscribe((params: any) => { this.route.params.subscribe((params: any) => {
debugger; debugger;
if (typeof params.movieDbId === 'string' || params.movieDbId instanceof String) { if (typeof params.movieDbId === 'string' || params.movieDbId instanceof String) {

View file

@ -75,7 +75,12 @@ export class IdentityService extends ServiceHelpers {
public getNotificationPreferences(): Observable<INotificationPreferences[]> { public getNotificationPreferences(): Observable<INotificationPreferences[]> {
return this.http.get<INotificationPreferences[]>(`${this.url}notificationpreferences`, {headers: this.headers}); return this.http.get<INotificationPreferences[]>(`${this.url}notificationpreferences`, {headers: this.headers});
} }
public getNotificationPreferencesForUser(userId: string): Observable<INotificationPreferences[]> { public getNotificationPreferencesForUser(userId: string): Observable<INotificationPreferences[]> {
return this.http.get<INotificationPreferences[]>(`${this.url}notificationpreferences/${userId}`, {headers: this.headers}); return this.http.get<INotificationPreferences[]>(`${this.url}notificationpreferences/${userId}`, {headers: this.headers});
} }
public updateLanguage(lang: string): Observable<null> {
return this.http.post<any>(`${this.url}language`, {lang: lang}, {headers: this.headers});
}
} }

View file

@ -4,6 +4,7 @@ import { TranslateService } from "@ngx-translate/core";
import { AvailableLanguages, ILanguage } from "./user-preference.constants"; import { AvailableLanguages, ILanguage } from "./user-preference.constants";
import { StorageService } from "../../../shared/storage/storage-service"; import { StorageService } from "../../../shared/storage/storage-service";
import { IdentityService, SettingsService } from "../../../services"; import { IdentityService, SettingsService } from "../../../services";
import { IUser } from "../../../interfaces";
@Component({ @Component({
templateUrl: "./user-preference.component.html", templateUrl: "./user-preference.component.html",
@ -17,6 +18,8 @@ export class UserPreferenceComponent implements OnInit {
public qrCode: string; public qrCode: string;
public qrCodeEnabled: boolean; public qrCodeEnabled: boolean;
private user: IUser;
constructor(private authService: AuthService, constructor(private authService: AuthService,
private readonly translate: TranslateService, private readonly translate: TranslateService,
private storage: StorageService, private storage: StorageService,
@ -39,14 +42,14 @@ export class UserPreferenceComponent implements OnInit {
this.qrCodeEnabled = true; this.qrCodeEnabled = true;
} }
const selectedLang = this.storage.get("Language"); this.user = await this.identityService.getUser().toPromise();
if (selectedLang) { if (this.user.language) {
this.selectedLang = selectedLang; this.selectedLang = this.user.language;
} }
} }
public languageSelected() { public languageSelected() {
this.storage.save("Language", this.selectedLang); this.identityService.updateLanguage(this.selectedLang).subscribe();
this.translate.use(this.selectedLang); this.translate.use(this.selectedLang);
} }

View file

@ -71,6 +71,7 @@ export class UserManagementUserComponent implements OnInit {
musicRequestLimit: 0, musicRequestLimit: 0,
episodeRequestQuota: null, episodeRequestQuota: null,
movieRequestQuota: null, movieRequestQuota: null,
language: null,
userQualityProfiles: { userQualityProfiles: {
radarrQualityProfile: 0, radarrQualityProfile: 0,
radarrRootPath: 0, radarrRootPath: 0,

View file

@ -330,6 +330,7 @@ namespace Ombi.Controllers.V1
EpisodeRequestLimit = user.EpisodeRequestLimit ?? 0, EpisodeRequestLimit = user.EpisodeRequestLimit ?? 0,
MovieRequestLimit = user.MovieRequestLimit ?? 0, MovieRequestLimit = user.MovieRequestLimit ?? 0,
MusicRequestLimit = user.MusicRequestLimit ?? 0, MusicRequestLimit = user.MusicRequestLimit ?? 0,
Language = user.Language
}; };
foreach (var role in userRoles) foreach (var role in userRoles)