mirror of
https://framagit.org/framasoft/framadate/funky-framadate-front.git
synced 2023-08-25 13:53:14 +02:00
add langs from framadate 1 in selector component
This commit is contained in:
parent
819e99f75e
commit
902c50d8cb
@ -1,12 +1,13 @@
|
||||
module.exports = {
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['@typescript-eslint'],
|
||||
plugins: ['@typescript-eslint', 'json'],
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/eslint-recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:prettier/recommended',
|
||||
'prettier/@typescript-eslint',
|
||||
'plugin:json/recommended',
|
||||
],
|
||||
parserOptions: {
|
||||
ecmaVersion: 2018,
|
||||
|
@ -6,15 +6,12 @@ import { environment } from '../environments/environment';
|
||||
import { Theme } from './core/enums/theme.enum';
|
||||
import { LanguageService } from './core/services/language.service';
|
||||
import { ThemeService } from './core/services/theme.service';
|
||||
import { NavigationEnd, Route, Router, RouterOutlet } from '@angular/router';
|
||||
import { NavigationEnd, Route, Router } from '@angular/router';
|
||||
import { slideInAnimation } from './shared/animations/main';
|
||||
import { FramaKeyboardShortcuts } from './shared/shortcuts/main';
|
||||
import { ShortcutEventOutput, ShortcutInput } from 'ng-keyboard-shortcuts';
|
||||
import { PollService } from './core/services/poll.service';
|
||||
import { Poll } from './core/models/poll.model';
|
||||
import { PollDTO } from './core/models/poll.DTO.model';
|
||||
import { PrimeNGConfig } from 'primeng/api';
|
||||
import { Language } from './core/enums/language.enum';
|
||||
import { ApiService } from './core/services/api.service';
|
||||
import { DOCUMENT } from '@angular/common';
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* liste des fichiers JSON de traduction des textes dans l'appli à charger par ngx-translate et prposer aux utilisateurs et utilisatrices de Framdate.
|
||||
* Cette enum est utilisé dans le composant de sélection de langue.
|
||||
*/
|
||||
export enum Language {
|
||||
export enum LanguageEnum {
|
||||
FR = 'fr',
|
||||
BR = 'br',
|
||||
CA = 'ca',
|
||||
|
@ -72,7 +72,7 @@ export class ApiService {
|
||||
'Content-Type': 'application/json',
|
||||
// mode: 'no-cors',
|
||||
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
|
||||
'Access-Control-Allow-Headers': 'Accept,Accept-Language,Content-Language,Content-Type',
|
||||
'Access-Control-Allow-Headers': 'Accept,Accept-LanguageEnum,Content-LanguageEnum,Content-Type',
|
||||
};
|
||||
const headersAxios = {
|
||||
headers: headerDict,
|
||||
|
@ -1,10 +1,8 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { TranslateService, LangChangeEvent } from '@ngx-translate/core';
|
||||
import { LangChangeEvent, TranslateService } from '@ngx-translate/core';
|
||||
|
||||
import { Language } from '../enums/language.enum';
|
||||
import { LanguageEnum } from '../enums/language.enum';
|
||||
import { StorageService } from './storage.service';
|
||||
import { type } from 'os';
|
||||
import { isString } from 'util';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@ -12,11 +10,11 @@ import { isString } from 'util';
|
||||
export class LanguageService {
|
||||
constructor(private translate: TranslateService, private storageService: StorageService) {}
|
||||
|
||||
public getLangage(): Language {
|
||||
return this.translate.currentLang as Language;
|
||||
public getLangage(): LanguageEnum {
|
||||
return this.translate.currentLang as LanguageEnum;
|
||||
}
|
||||
|
||||
public setLanguage(language: Language): void {
|
||||
public setLanguage(language: LanguageEnum): void {
|
||||
this.translate.use(language.toString());
|
||||
}
|
||||
|
||||
@ -27,11 +25,11 @@ export class LanguageService {
|
||||
public configureAndInitTranslations(): void {
|
||||
// always save in storage the currentLang used
|
||||
this.translate.onLangChange.subscribe((event: LangChangeEvent) => {
|
||||
this.storageService.language = event.lang as Language;
|
||||
this.storageService.language = event.lang as LanguageEnum;
|
||||
});
|
||||
|
||||
// set all languages available
|
||||
this.translate.addLangs(Object.keys(Language));
|
||||
this.translate.addLangs(Object.keys(LanguageEnum));
|
||||
|
||||
// set language
|
||||
this.setLanguageOnInit();
|
||||
@ -54,7 +52,7 @@ export class LanguageService {
|
||||
|
||||
// set default language
|
||||
if (!this.translate.currentLang) {
|
||||
this.setLanguage(Language.FR);
|
||||
this.setLanguage(LanguageEnum.FR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,8 +62,9 @@ export class LanguageService {
|
||||
this.setLanguage(this.storageService.language);
|
||||
}
|
||||
}
|
||||
|
||||
private setLanguageFromBrowser(): void {
|
||||
const currentBrowserLanguage: Language = this.translate.getBrowserLang().toUpperCase() as Language;
|
||||
const currentBrowserLanguage: LanguageEnum = this.translate.getBrowserLang().toUpperCase() as LanguageEnum;
|
||||
console.log('currentBrowserLanguage', currentBrowserLanguage);
|
||||
if (this.translate.getLangs().includes(currentBrowserLanguage)) {
|
||||
this.setLanguage(currentBrowserLanguage);
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { LocalStorage } from 'ngx-webstorage';
|
||||
|
||||
import { Language } from '../enums/language.enum';
|
||||
import { LanguageEnum } from '../enums/language.enum';
|
||||
import { Theme } from '../enums/theme.enum';
|
||||
import { Stack } from '../models/stack.model';
|
||||
import { Choice } from '../models/choice.model';
|
||||
@ -28,7 +28,7 @@ export class StorageService {
|
||||
public theme: Theme;
|
||||
|
||||
@LocalStorage()
|
||||
public language: Language;
|
||||
public language: LanguageEnum;
|
||||
|
||||
@LocalStorage()
|
||||
public userPolls: Poll[] = [];
|
||||
|
@ -17,7 +17,6 @@
|
||||
</span>
|
||||
</button>
|
||||
</label>
|
||||
({{ availableLanguages.length }} availableLanguages)
|
||||
<select class="is-hidden" id="lang_selector" (change)="setLang()" [(ngModel)]="currentLang">
|
||||
<option *ngFor="let language of availableLanguages" value="{{ language }}">
|
||||
<!-- {{ language }} - -->
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
|
||||
import { Language } from '../../../../core/enums/language.enum';
|
||||
import { LanguageEnum } from '../../../../core/enums/language.enum';
|
||||
import { LanguageService } from '../../../../core/services/language.service';
|
||||
import { StorageService } from '../../../../core/services/storage.service';
|
||||
|
||||
@ -10,7 +10,7 @@ import { StorageService } from '../../../../core/services/storage.service';
|
||||
styleUrls: ['./language-selector.component.scss'],
|
||||
})
|
||||
export class LanguageSelectorComponent implements OnInit {
|
||||
public currentLang: Language;
|
||||
public currentLang: LanguageEnum;
|
||||
public availableLanguages: any = ['FR', 'EN', 'ES'];
|
||||
language: string;
|
||||
|
||||
|
@ -34,6 +34,7 @@ export const environment = {
|
||||
expiresDaysDelay: 30,
|
||||
frontDomain: productionBaseUrl,
|
||||
interval_days_default: 7,
|
||||
description_max_chars: 900,
|
||||
maxCountOfAnswers: 300,
|
||||
production: true,
|
||||
showDemoWarning: false,
|
||||
|
Loading…
Reference in New Issue
Block a user