[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:
Denys Vuika
2023-07-18 20:06:09 +01:00
committed by GitHub
parent d70f689e06
commit 1a4d7ba008
11 changed files with 99 additions and 183 deletions

View File

@@ -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 { }

View File

@@ -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')
]
});

View File

@@ -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'
})