feat(core): add isLocalized method to LocalizationService

#3791
pull/3936/head
mehmet-erim 5 years ago
parent 99c5fb6a5c
commit c79944b3a8

@ -1,11 +1,12 @@
import { Injectable, NgZone, Optional, SkipSelf } from '@angular/core';
import { ActivatedRouteSnapshot, Router } from '@angular/router';
import { Store, Actions, ofActionSuccessful } from '@ngxs/store';
import { Actions, ofActionSuccessful, Store } from '@ngxs/store';
import { noop, Observable } from 'rxjs';
import { SetLanguage } from '../actions/session.actions';
import { ApplicationConfiguration } from '../models/application-configuration';
import { Config } from '../models/config';
import { ConfigState } from '../states/config.state';
import { registerLocale } from '../utils/initial-utils';
import { Config } from '../models/config';
import { SetLanguage } from '../actions/session.actions';
type ShouldReuseRoute = (future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot) => boolean;
@ -75,4 +76,31 @@ export class LocalizationService {
instant(key: string | Config.LocalizationWithDefault, ...interpolateParams: string[]): string {
return this.store.selectSnapshot(ConfigState.getLocalization(key, ...interpolateParams));
}
isLocalized(key, sourceName) {
if (sourceName === '_') {
//A convention to suppress the localization
return true;
}
const localization = this.store.selectSnapshot(
ConfigState.getOne('localization'),
) as ApplicationConfiguration.Localization;
sourceName = sourceName || localization.defaultResourceName;
if (!sourceName) {
return false;
}
const source = localization.values[sourceName];
if (!source) {
return false;
}
const value = source[key];
if (value === undefined) {
return false;
}
return true;
}
}

Loading…
Cancel
Save