diff --git a/package.json b/package.json index 72d0b458..70bea524 100644 --- a/package.json +++ b/package.json @@ -29,10 +29,8 @@ "@angular/common": "^4.3.6", "@angular/core": "^4.3.6", "@angular/forms": "^4.3.6", - "@skyux/core": "^3.1.0", - "@skyux/i18n": "^3.0.1", - "@skyux/indicators": ">=3.0.0-rc.0", - "rxjs": "^5.4.3" + "@skyux/i18n": "^3.2.0", + "@skyux/indicators": "^3.0.0-rc.0" }, "dependencies": {}, "devDependencies": { @@ -43,9 +41,9 @@ "@angular/forms": "4.3.6", "@angular/platform-browser": "4.3.6", "@blackbaud/skyux": "2.26.0", - "@blackbaud/skyux-builder": "1.24.0", - "@skyux-sdk/builder-plugin-skyux": "1.0.0-rc.0", - "@skyux/indicators": "3.0.0-rc.0", + "@blackbaud/skyux-builder": "1.25.0", + "@skyux-sdk/builder-plugin-skyux": "1.0.0-rc.3", + "@skyux/indicators": "3.0.0-rc.2", "core-js": "2.4.1", "rxjs": "5.4.3", "ts-node": "3.0.4", diff --git a/src/app/public/modules/file-attachment/file-attachments.module.ts b/src/app/public/modules/file-attachment/file-attachments.module.ts index 9f3eb649..9aceecf5 100644 --- a/src/app/public/modules/file-attachment/file-attachments.module.ts +++ b/src/app/public/modules/file-attachment/file-attachments.module.ts @@ -9,24 +9,30 @@ import { FormsModule } from '@angular/forms'; +import { + SkyI18nModule +} from '@skyux/i18n'; + import { SkyIconModule } from '@skyux/indicators'; +import { + SkyFormsResourcesModule +} from '../shared'; + import { SkyFileDropComponent } from './file-drop.component'; + import { SkyFileItemComponent } from './file-item.component'; + import { SkyFileSizePipe } from './file-size.pipe'; -import { - SkyI18nModule -} from '@skyux/i18n/modules/i18n/i18n.module'; - @NgModule({ declarations: [ SkyFileDropComponent, @@ -36,6 +42,7 @@ import { imports: [ CommonModule, FormsModule, + SkyFormsResourcesModule, SkyIconModule, SkyI18nModule ], diff --git a/src/app/public/modules/file-attachment/file-drop.component.html b/src/app/public/modules/file-attachment/file-drop.component.html index e48ed0b2..dd9a13fc 100644 --- a/src/app/public/modules/file-attachment/file-drop.component.html +++ b/src/app/public/modules/file-attachment/file-drop.component.html @@ -12,7 +12,7 @@ (dragenter)="fileDragEnter($event)" (dragleave)="fileDragLeave($event)" (drop)="fileDrop($event)" - [attr.aria-label]="'skyux_file_attachment_file_upload_drag_or_click' | skyAppResources"> + [attr.aria-label]="'skyux_file_attachment_file_upload_drag_or_click' | skyLibResources">
- {{ 'skyux_file_attachment_file_upload_drag_file_here' | skyAppResources }} + {{ 'skyux_file_attachment_file_upload_drag_file_here' | skyLibResources }}
- {{ 'skyux_file_attachment_file_upload_or_click_to_browse' | skyAppResources }} + {{ 'skyux_file_attachment_file_upload_or_click_to_browse' | skyLibResources }}
@@ -39,7 +39,7 @@
- {{ 'skyux_file_attachment_file_upload_drop_files_here' | skyAppResources }} + {{ 'skyux_file_attachment_file_upload_drop_files_here' | skyLibResources }}
@@ -47,7 +47,7 @@
- {{ 'skyux_file_attachment_file_upload_invalid_file' | skyAppResources }} + {{ 'skyux_file_attachment_file_upload_invalid_file' | skyLibResources }}
@@ -62,24 +62,24 @@ diff --git a/src/app/public/modules/file-attachment/file-item.component.html b/src/app/public/modules/file-attachment/file-item.component.html index 8200ab3c..30b260ba 100644 --- a/src/app/public/modules/file-attachment/file-item.component.html +++ b/src/app/public/modules/file-attachment/file-item.component.html @@ -10,7 +10,7 @@
-
@@ -21,7 +21,7 @@ + [alt]="'skyux_file_attachment_file_upload_image_preview_alt_text' | skyLibResources" />
diff --git a/src/app/public/modules/file-attachment/file-item.component.spec.ts b/src/app/public/modules/file-attachment/file-item.component.spec.ts index 4d18a7dc..7b0dd884 100644 --- a/src/app/public/modules/file-attachment/file-item.component.spec.ts +++ b/src/app/public/modules/file-attachment/file-item.component.spec.ts @@ -8,6 +8,14 @@ import { expect } from '@skyux-sdk/testing'; +import { + SkyLibResourcesService +} from '@skyux/i18n'; + +import { + SkyLibResourcesTestService +} from '@skyux/i18n/testing'; + import { SkyFileAttachmentsModule } from './file-attachments.module'; @@ -36,6 +44,12 @@ describe('File item component', () => { TestBed.configureTestingModule({ imports: [ SkyFileAttachmentsModule + ], + providers: [ + { + provide: SkyLibResourcesService, + useClass: SkyLibResourcesTestService + } ] }); }); diff --git a/src/app/public/modules/file-attachment/file-size.pipe.spec.ts b/src/app/public/modules/file-attachment/file-size.pipe.spec.ts index 25379877..4637dda8 100644 --- a/src/app/public/modules/file-attachment/file-size.pipe.spec.ts +++ b/src/app/public/modules/file-attachment/file-size.pipe.spec.ts @@ -1,11 +1,18 @@ import { DecimalPipe } from '@angular/common'; -import { SkyFileSizePipe } from './file-size.pipe'; + +import { + SkyLibResourcesTestService +} from '@skyux/i18n/testing'; + +import { + SkyFileSizePipe +} from './file-size.pipe'; describe('File size pipe', () => { - let fileSizePipe: SkyFileSizePipe, - decimalPipe: DecimalPipe; + let fileSizePipe: SkyFileSizePipe; + let decimalPipe: DecimalPipe; function validateFormatted(value: number, expected: string, newFileSizePipe: SkyFileSizePipe) { let result = newFileSizePipe.transform(value); @@ -15,7 +22,10 @@ describe('File size pipe', () => { beforeEach(function() { decimalPipe = new DecimalPipe('en'); - fileSizePipe = new SkyFileSizePipe(decimalPipe); + fileSizePipe = new SkyFileSizePipe( + decimalPipe, + new SkyLibResourcesTestService() as any + ); }); it('should format bytes', function () { diff --git a/src/app/public/modules/file-attachment/file-size.pipe.ts b/src/app/public/modules/file-attachment/file-size.pipe.ts index 08df7a7b..24cf2fdc 100644 --- a/src/app/public/modules/file-attachment/file-size.pipe.ts +++ b/src/app/public/modules/file-attachment/file-size.pipe.ts @@ -8,20 +8,18 @@ import { } from '@angular/common'; import { - SkyFormat -} from '@skyux/core/modules/format/format'; + SkyLibResourcesService +} from '@skyux/i18n'; @Pipe({ name: 'skyFileSize' }) export class SkyFileSizePipe implements PipeTransform { - // TODO: The following require statement is not recommended, but was done - // to avoid a breaking change (SkyResources is synchronous, but SkyAppResources is asynchronous). - // We should switch to using SkyAppResources in the next major release. - private resources: any = require('!json-loader!.skypageslocales/resources_en_US.json'); - - public constructor(private decimalPipe: DecimalPipe) {} + constructor( + private decimalPipe: DecimalPipe, + private resourcesService: SkyLibResourcesService + ) { } public transform(input: number): string { @@ -38,18 +36,18 @@ export class SkyFileSizePipe implements PipeTransform { /* tslint:enable */ if (Math.abs(input) === 1) { - template = this.getString('skyux_file_attachment_file_size_b_singular'); + template = 'skyux_file_attachment_file_size_b_singular'; } else if (input < 1000) { - template = this.getString('skyux_file_attachment_file_size_b_plural'); + template = 'skyux_file_attachment_file_size_b_plural'; } else if (input < 1e6) { - template = this.getString('skyux_file_attachment_file_size_kb'); + template = 'skyux_file_attachment_file_size_kb'; dividend = 1000; } else if (input < 1e9) { - template = this.getString('skyux_file_attachment_file_size_mb'); + template = 'skyux_file_attachment_file_size_mb'; dividend = 1e6; decimalPlaces = 1; } else { - template = this.getString('skyux_file_attachment_file_size_gb'); + template = 'skyux_file_attachment_file_size_gb'; dividend = 1e9; decimalPlaces = 1; } @@ -59,15 +57,15 @@ export class SkyFileSizePipe implements PipeTransform { formattedSize = this.decimalPipe.transform(roundedSize, '.0-3'); - return SkyFormat.formatText(template, formattedSize); + return this.getString(template, formattedSize); } - /** - * This method is a stand-in for the old SkyResources service from skyux2. - * TODO: We should consider using Builder's resources service instead. - * @param key - */ - private getString(key: string): string { - return this.resources[key].message; + private getString(key: string, ...args: any[]): string { + // TODO: Need to implement the async `getString` method in a breaking change. + return this.resourcesService.getStringForLocale( + { locale: 'en-US' }, + key, + ...args + ); } } diff --git a/src/app/public/modules/shared/forms-resources.module.ts b/src/app/public/modules/shared/forms-resources.module.ts new file mode 100644 index 00000000..ca67d9ef --- /dev/null +++ b/src/app/public/modules/shared/forms-resources.module.ts @@ -0,0 +1,20 @@ +import { + NgModule +} from '@angular/core'; + +import { + SKY_LIB_RESOURCES_PROVIDERS +} from '@skyux/i18n'; + +import { + SkyFormsResourcesProvider +} from '../../plugin-resources/forms-resources-provider'; + +@NgModule({ + providers: [{ + provide: SKY_LIB_RESOURCES_PROVIDERS, + useClass: SkyFormsResourcesProvider, + multi: true + }] +}) +export class SkyFormsResourcesModule { } diff --git a/src/app/public/modules/shared/index.ts b/src/app/public/modules/shared/index.ts new file mode 100644 index 00000000..0283de4f --- /dev/null +++ b/src/app/public/modules/shared/index.ts @@ -0,0 +1 @@ +export * from './forms-resources.module'; diff --git a/src/app/public/plugin-resources/forms-resources-provider.ts b/src/app/public/plugin-resources/forms-resources-provider.ts new file mode 100644 index 00000000..68f09682 --- /dev/null +++ b/src/app/public/plugin-resources/forms-resources-provider.ts @@ -0,0 +1,8 @@ +import { + SkyAppLocaleInfo, + SkyLibResourcesProvider +} from '@skyux/i18n'; + +export class SkyFormsResourcesProvider implements SkyLibResourcesProvider { + public getString: (localeInfo: SkyAppLocaleInfo, name: string) => string; +}