2017-10-24 12:41:44 +00:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
|
|
|
|
export interface Locale
|
|
|
|
{
|
|
|
|
lang: string;
|
|
|
|
data: Object;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class FuseTranslationLoaderService
|
|
|
|
{
|
2018-05-20 07:12:31 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param {TranslateService} _translateService
|
|
|
|
*/
|
|
|
|
constructor(
|
|
|
|
private _translateService: TranslateService
|
|
|
|
)
|
2017-10-24 12:41:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-05-20 07:12:31 +00:00
|
|
|
// -----------------------------------------------------------------------------------------------------
|
|
|
|
// @ Public methods
|
|
|
|
// -----------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load translations
|
|
|
|
*
|
|
|
|
* @param {Locale} args
|
|
|
|
*/
|
|
|
|
loadTranslations(...args: Locale[]): void
|
2017-10-24 12:41:44 +00:00
|
|
|
{
|
|
|
|
const locales = [...args];
|
|
|
|
|
|
|
|
locales.forEach((locale) => {
|
|
|
|
// use setTranslation() with the third argument set to true
|
|
|
|
// to append translations instead of replacing them
|
2018-05-20 07:12:31 +00:00
|
|
|
this._translateService.setTranslation(locale.lang, locale.data, true);
|
2017-10-24 12:41:44 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|