mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACS-5629] enhanced way of providing translations (#8763)
* enhanced way providing translations * update documentation * update documentation * test fixes * try add missing module import * inject i18n to core module to cause the setup
This commit is contained in:
@@ -19,7 +19,7 @@ import { NgModule } from '@angular/core';
|
||||
import { CoreModule } from '../core.module';
|
||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { TRANSLATION_PROVIDER } from '../translation/translation.service';
|
||||
import { provideTranslations } from '../translation/translation.service';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -28,14 +28,7 @@ import { TRANSLATION_PROVIDER } from '../translation/translation.service';
|
||||
BrowserAnimationsModule
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
provide: TRANSLATION_PROVIDER,
|
||||
multi: true,
|
||||
useValue: {
|
||||
name: 'adf-core',
|
||||
source: 'assets/adf-core'
|
||||
}
|
||||
}
|
||||
provideTranslations('adf-core', 'assets/adf-core')
|
||||
]
|
||||
})
|
||||
export class CoreStoryModule { }
|
||||
|
@@ -21,7 +21,7 @@ import { getTestBed, TestBed } from '@angular/core/testing';
|
||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
import { TranslateLoaderService } from './translate-loader.service';
|
||||
import { TRANSLATION_PROVIDER, TranslationService } from './translation.service';
|
||||
import { provideTranslations, TranslationService } from './translation.service';
|
||||
import { AppConfigService } from '../app-config/app-config.service';
|
||||
import { AppConfigServiceMock } from '../common/mock/app-config.service.mock';
|
||||
import { AlfrescoApiService } from '../services/alfresco-api.service';
|
||||
@@ -47,14 +47,7 @@ describe('TranslationService', () => {
|
||||
providers: [
|
||||
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
|
||||
{ provide: AppConfigService, useClass: AppConfigServiceMock },
|
||||
{
|
||||
provide: TRANSLATION_PROVIDER,
|
||||
multi: true,
|
||||
useValue: {
|
||||
name: '@alfresco/adf-core',
|
||||
source: 'assets/ng2-alfresco-core'
|
||||
}
|
||||
}
|
||||
provideTranslations('@alfresco/adf-core', 'assets/ng2-alfresco-core')
|
||||
]
|
||||
});
|
||||
|
||||
|
@@ -28,6 +28,24 @@ export interface TranslationProvider {
|
||||
source: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate translation provider
|
||||
*
|
||||
* @param id Unique identifier
|
||||
* @param path Path to translation files
|
||||
* @returns Provider
|
||||
*/
|
||||
export function provideTranslations(id: string, path: string) {
|
||||
return {
|
||||
provide: TRANSLATION_PROVIDER,
|
||||
multi: true,
|
||||
useValue: {
|
||||
name: id,
|
||||
source: path
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
|
Reference in New Issue
Block a user