### File

`projects/angular-l10n/src/lib/services/l10n-user-language.ts`

### Description

Implement this class-interface to get the user language.

### Index

###### Methods

- Public Abstract Async get

### Methods

Public Abstract Async get
`get()`
Defined in projects/angular-l10n/src/lib/services/l10n-user-language.ts:14
This method must contain the logic to get the user language. Returns : `Promise<string | null>` The user language

    import { Injectable, Inject } from '@angular/core';

    import { L10N_CONFIG, L10nConfig } from '../models/l10n-config';

    /**
     * Implement this class-interface to get the user language.
     */
    @Injectable() export abstract class L10nUserLanguage {

        /**
         * This method must contain the logic to get the user language.
         * @return The user language
         */
        public abstract async get(): Promise<string | null>;

    }

    @Injectable() export class L10nDefaultUserLanguage implements L10nUserLanguage {

        constructor(@Inject(L10N_CONFIG) private config: L10nConfig) { }

        public async get(): Promise<string | null> {
            let browserLanguage = null;
            if (typeof navigator !== 'undefined' && navigator.language) {
                switch (this.config.format) {
                    case 'language':
                        browserLanguage = navigator.language.split('-')[0];
                        break;
                    case 'language-region':
                        browserLanguage = navigator.language;
                        break;
                }
            }
            return Promise.resolve(browserLanguage);
        }

    }

# result-matching ""

# No results matching ""