<commit_before>import { IUser } from './services/model/IUser';
import { Component, ElementRef, OnInit, OnDestroy, AfterContentChecked } from '@angular/core';
import { Router, NavigationStart } from '@angular/router';
import { Subscription } from 'rxjs/Subscription';

import { TranslateService } from '@ngx-translate/core';
import { Angulartics2GoogleAnalytics, Angulartics2 } from 'angulartics2';
import { environment } from 'environments/environment';

import { UserService } from './services/api';
import { ErrorHandlerService } from './services/config/ErrorHandler.service';
import { Logger } from './services/Logger';
import { HelpBlockComponent } from 'app/shared/components';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit, OnDestroy, AfterContentChecked  {
  navState = false;
  currentHelpBlocks;

  userSubscription: Subscription;
  user: IUser;
  get locationHref () {
    return encodeURIComponent(window.location.pathname);
  }

  get currentLang() { return this.translate.currentLang; }

  get hasHelp() {
    return this.currentHelpBlocks > 0;
  }

  showHelp = false;

  get error() { return this.errorHandler.error; }
  set error(value) { this.errorHandler.error = value; }

  constructor(
    private element: ElementRef,
    private userService: UserService,
    private translate: TranslateService,
    private errorHandler: ErrorHandlerService,
    private router: Router,
    private angulartics2: Angulartics2,
    private angulartics: Angulartics2GoogleAnalytics
  ) {
    // Identify dev mode
    this.angulartics2.developerMode(!environment.production);

    // Set translation defaults
    this.translate.addLangs(['en', 'no']);
    this.translate.setDefaultLang('en');
    const browserLang: string = this.translate.getBrowserLang();
    this.changeLang(browserLang.match(/en|no/) ? browserLang : 'en');

    // For debugging routes (only visible in dev mode)
    this.router.events.subscribe(event => Logger.debug(event));
  }

  ngOnInit(): void {
    this.userSubscription = this.userService.getMe().subscribe(user => this.user = user);
  }

  ngAfterContentChecked() {
    const helpBlocks = document.querySelectorAll('app-help-block');
    if (this.currentHelpBlocks !== helpBlocks.length) {
      this.currentHelpBlocks = helpBlocks.length;
    }
  }

  ngOnDestroy() {
    if (this.userSubscription) {
      this.userSubscription.unsubscribe();
    }
  }

  closeNav(evt: MouseEvent): void {
    if (this.navState) {
      return this.toggleNav(evt);
    }
  }
  toggleNav(evt: MouseEvent): void {
    this.navState = !this.navState;
    evt.preventDefault();
    evt.stopPropagation();
  }

  toggleHelp() {
    this.showHelp = !this.showHelp;
  }

  changeLang(lang) {
    this.translate.use(lang);
    Logger.debug('** Changing language: ', this.currentLang, lang);
  }
}<commit_msg>Persisting selected language in localstorage<commit_after>import { IUser } from './services/model/IUser';
import { Component, ElementRef, OnInit, OnDestroy, AfterContentChecked } from '@angular/core';
import { Router, NavigationStart } from '@angular/router';
import { Subscription } from 'rxjs/Subscription';

import { TranslateService } from '@ngx-translate/core';
import { Angulartics2GoogleAnalytics, Angulartics2 } from 'angulartics2';
import { environment } from 'environments/environment';

import { UserService } from './services/api';
import { ErrorHandlerService } from './services/config/ErrorHandler.service';
import { Logger } from './services/Logger';
import { HelpBlockComponent } from 'app/shared/components';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit, OnDestroy, AfterContentChecked  {
  navState = false;
  currentHelpBlocks;

  userSubscription: Subscription;
  user: IUser;
  get locationHref () {
    return encodeURIComponent(window.location.pathname);
  }

  get currentLang() { return this.translate.currentLang; }

  get hasHelp() {
    return this.currentHelpBlocks > 0;
  }

  showHelp = false;

  get error() { return this.errorHandler.error; }
  set error(value) { this.errorHandler.error = value; }

  constructor(
    private element: ElementRef,
    private userService: UserService,
    private translate: TranslateService,
    private errorHandler: ErrorHandlerService,
    private router: Router,
    private angulartics2: Angulartics2,
    private angulartics: Angulartics2GoogleAnalytics
  ) {
    // Identify dev mode
    this.angulartics2.developerMode(!environment.production);

    // Set translation defaults
    this.translate.addLangs(['en', 'no']);
    this.translate.setDefaultLang('en');
    const browserLang: string = this.translate.getBrowserLang();
    const newLang = localStorage.getItem('lang') || browserLang;
    this.changeLang(newLang.match(/en|no|nb/) ? newLang : 'en');

    // For debugging routes (only visible in dev mode)
    this.router.events.subscribe(event => Logger.debug(event));
  }

  ngOnInit(): void {
    this.userSubscription = this.userService.getMe().subscribe(user => this.user = user);
  }

  ngAfterContentChecked() {
    const helpBlocks = document.querySelectorAll('app-help-block');
    if (this.currentHelpBlocks !== helpBlocks.length) {
      this.currentHelpBlocks = helpBlocks.length;
    }
  }

  ngOnDestroy() {
    if (this.userSubscription) {
      this.userSubscription.unsubscribe();
    }
  }

  closeNav(evt: MouseEvent): void {
    if (this.navState) {
      return this.toggleNav(evt);
    }
  }
  toggleNav(evt: MouseEvent): void {
    this.navState = !this.navState;
    evt.preventDefault();
    evt.stopPropagation();
  }

  toggleHelp() {
    this.showHelp = !this.showHelp;
  }

  changeLang(lang) {
    if (lang === 'nb') { lang = 'no'; }
    this.translate.use(lang);
    localStorage.setItem('lang', lang);
    Logger.debug('** Changing language: ', this.currentLang, lang);
  }
}
{'fraction_non_alphanumeric': 0.12874400132384578, 'fraction_numerical': 0.0026476915439351315, 'mean_word_length': 4.02828618968386, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2615393', 'n_tokens_mistral': 1814, 'n_tokens_neox': 1807, 'n_words': 387}