Add i18n to search components

This commit is contained in:
Will Abson
2016-06-02 22:40:05 +01:00
parent 83f3963bbd
commit d989bf309f
5 changed files with 36 additions and 9 deletions

View File

@@ -0,0 +1,15 @@
{
"SEARCH": {
"CONTROL": {
"LABEL": "Search content"
},
"RESULTS": {
"SUMMARY": "Found {{numResults}} results for {{searchTerm}}",
"COLUMNS": {
"NAME": "Name",
"MODIFIED_BY": "Modified by",
"MODIFIED_AT": "Modified at"
}
}
}
}

View File

@@ -5,7 +5,7 @@
</label>
<div [class]="getTextFieldHolderClassName()">
<input class="mdl-textfield__input" [type]="inputType" [autocomplete]="getAutoComplete()" id="searchTerm" [ngFormControl]="searchControl" [(ngModel)]="searchTerm">
<label class="mdl-textfield__label" for="searchTerm">Search content</label>
<label class="mdl-textfield__label" for="searchTerm">{{'SEARCH.CONTROL.LABEL' | translate}}</label>
</div>
</div>
</form>

View File

@@ -19,6 +19,8 @@ import { Control, Validators } from 'angular2/common';
import { Component, Input, Output, EventEmitter } from 'angular2/core';
import { AlfrescoService } from './../services/alfresco.service';
import { AlfrescoPipeTranslate, AlfrescoTranslationService } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
declare let __moduleName: string;
declare var componentHandler: any;
@@ -28,7 +30,8 @@ declare var componentHandler: any;
styles: [
],
templateUrl: './alfresco-search-control.component.html',
providers: [AlfrescoService]
providers: [AlfrescoService],
pipes: [AlfrescoPipeTranslate]
})
export class AlfrescoSearchControlComponent {
@@ -49,13 +52,14 @@ export class AlfrescoSearchControlComponent {
searchControl: Control;
constructor() {
constructor(private translate: AlfrescoTranslationService) {
this.searchControl = new Control(
this.searchTerm,
Validators.compose([Validators.required, Validators.minLength(3)])
);
translate.addComponent('node_modules/ng2-alfresco-search');
}
ngAfterViewInit() {

View File

@@ -1,4 +1,4 @@
<p *ngIf="searchTerm">Found {{results.length}} results for {{searchTerm}}</p>
<p *ngIf="searchTerm">{{ 'SEARCH.RESULTS.SUMMARY' | translate:{numResults: results.length, searchTerm: searchTerm} }}</p>
<table *ngIf="searchTerm && results.length" class="mdl-data-table mdl-js-data-table mdl-shadow--2dp full-width">
<thead>
<tr>
@@ -6,13 +6,13 @@
<span class="mdl-data-table__cell--non-numeric"></span>
</th>
<th>
<span class="mdl-data-table__cell--non-numeric">Name</span>
<span class="mdl-data-table__cell--non-numeric">{{'SEARCH.RESULTS.COLUMNS.NAME' | translate}}</span>
</th>
<th>
<span class="mdl-data-table__cell--non-numeric">Modified by</span>
<span class="mdl-data-table__cell--non-numeric">{{'SEARCH.RESULTS.COLUMNS.MODIFIED_BY' | translate}}</span>
</th>
<th>
<span class="mdl-data-table__cell--non-numeric">Modified at</span>
<span class="mdl-data-table__cell--non-numeric">{{'SEARCH.RESULTS.COLUMNS.MODIFIED_AT' | translate}}</span>
</th>
</tr>
</thead>

View File

@@ -19,6 +19,8 @@ import { Component, Input, Optional, OnChanges, OnInit } from 'angular2/core';
import { RouteParams } from 'angular2/router';
import { AlfrescoService } from './../services/alfresco.service';
import { AlfrescoPipeTranslate, AlfrescoTranslationService } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
declare let __moduleName: string;
@Component({
@@ -27,7 +29,8 @@ declare let __moduleName: string;
styles: [
],
templateUrl: './alfresco-search.component.html',
providers: [AlfrescoService]
providers: [AlfrescoService],
pipes: [AlfrescoPipeTranslate]
})
export class AlfrescoSearchComponent implements OnChanges, OnInit {
@@ -41,7 +44,12 @@ export class AlfrescoSearchComponent implements OnChanges, OnInit {
route: any[] = [];
constructor(
private _alfrescoService: AlfrescoService, @Optional() params: RouteParams) {
private _alfrescoService: AlfrescoService,
private translate: AlfrescoTranslationService,
@Optional() params: RouteParams)
{
translate.addComponent('node_modules/ng2-alfresco-search');
this.results = [];
if (params) {
this.searchTerm = params.get('q');