<commit_before>import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { StorageService } from '../storage/storage.service';

/**
 * @internal
 */
@Injectable({
	providedIn: 'root'
})
export class CaptionService {

	private langTitles = [
		{ name: 'English', ISO: 'en-US' },
		{ name: 'Español', ISO: 'es-ES' },
		{ name: 'Deutsch', ISO: 'de-DE' },
		{ name: 'Français', ISO: 'fr-FR' },
		{ name: '中国', ISO: 'zh-CN' },
		{ name: 'हिन्दी', ISO: 'hi-IN' },
		{ name: 'Italiano', ISO: 'it-IT' },
		{ name: 'やまと', ISO: 'jp-JP' },
		{ name: 'Português', ISO: 'pt-PT' }
	];
	captionLangSelected: { name: string; ISO: string };
	captionLangObs: Observable<{ name: string; ISO: string }>;
	private _captionLangObs: Subject<{ name: string; ISO: string }> = new Subject();
	private captionsEnabled: boolean = false;

	constructor(private storageService: StorageService) {
		const iso = this.storageService.getCaptionsLang();
		if (iso) {
			this.captionLangSelected = this.langTitles.find((lang) => lang.ISO === iso) || this.langTitles[0];
		}
		this.captionLangObs = this._captionLangObs.asObservable();
	}

	setCaptionsEnabled(value: boolean) {
		this.captionsEnabled = value;
	}

	areCaptionsEnabled(): boolean {
		return this.captionsEnabled;
	}

	setLanguage(lang: string) {
		const newLang = this.langTitles.find((l) => l.ISO === lang);
		if(!!newLang && newLang.ISO !== this.captionLangSelected.ISO){
			this.captionLangSelected = newLang;
			this.storageService.setCaptionLang(lang);
			this._captionLangObs.next(this.captionLangSelected);
		}
	}

	getLangSelected(): { name: string; ISO: string } {
		return this.captionLangSelected || this.langTitles[0];
	}

	getCaptionLanguages(): { name: string; ISO: string }[] {
		return this.langTitles;
	}
}<commit_msg>openvidu-components: Fixed bug with captions lang initialization<commit_after>import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { StorageService } from '../storage/storage.service';

/**
 * @internal
 */
@Injectable({
	providedIn: 'root'
})
export class CaptionService {
	private langs = [
		{ name: 'English', ISO: 'en-US' },
		{ name: 'Español', ISO: 'es-ES' },
		{ name: 'Deutsch', ISO: 'de-DE' },
		{ name: 'Français', ISO: 'fr-FR' },
		{ name: '中国', ISO: 'zh-CN' },
		{ name: 'हिन्दी', ISO: 'hi-IN' },
		{ name: 'Italiano', ISO: 'it-IT' },
		{ name: 'やまと', ISO: 'jp-JP' },
		{ name: 'Português', ISO: 'pt-PT' }
	];
	captionLangSelected: { name: string; ISO: string } = { name: 'English', ISO: 'en-US' };
	captionLangObs: Observable<{ name: string; ISO: string }>;
	private _captionLangObs: Subject<{ name: string; ISO: string }> = new Subject();
	private captionsEnabled: boolean = false;

	constructor(private storageService: StorageService) {
		const iso = this.storageService.getCaptionsLang();
		const lang = this.langs.find((lang) => lang.ISO === iso);
		if (iso && lang) {
			this.captionLangSelected = lang;
		} else {
			this.captionLangSelected = this.langs[0];
		}
		this.captionLangObs = this._captionLangObs.asObservable();
	}

	setCaptionsEnabled(value: boolean) {
		this.captionsEnabled = value;
	}

	areCaptionsEnabled(): boolean {
		return this.captionsEnabled;
	}

	setLanguage(lang: string) {
		const newLang = this.langs.find((l) => l.ISO === lang);
		if (!!newLang && newLang.ISO !== this.captionLangSelected.ISO) {
			this.captionLangSelected = newLang;
			this.storageService.setCaptionLang(lang);
			this._captionLangObs.next(this.captionLangSelected);
		}
	}

	getLangSelected(): { name: string; ISO: string } {
		return this.captionLangSelected;
	}

	getCaptionLanguages(): { name: string; ISO: string }[] {
		return this.langs;
	}
}
{'fraction_non_alphanumeric': 0.17345562449420016, 'fraction_numerical': 0.0008092797410304828, 'mean_word_length': 4.358381502890174, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4049986', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1293, 'n_words': 284}