From 8acdc2894d8057bc369816dd0520edf86dcc3c4e Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Tue, 13 Mar 2018 00:22:50 -0400 Subject: [PATCH] fix(formatter): translate formatter was causing issues in some occasion --- .../formatters/translateBooleanFormatter.ts | 9 ++++----- .../aurelia-slickgrid/formatters/translateFormatter.ts | 10 ++++------ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/aurelia-slickgrid/src/aurelia-slickgrid/formatters/translateBooleanFormatter.ts b/aurelia-slickgrid/src/aurelia-slickgrid/formatters/translateBooleanFormatter.ts index 5f2bb53b2..10f8d0b2f 100644 --- a/aurelia-slickgrid/src/aurelia-slickgrid/formatters/translateBooleanFormatter.ts +++ b/aurelia-slickgrid/src/aurelia-slickgrid/formatters/translateBooleanFormatter.ts @@ -6,17 +6,16 @@ export const translateBooleanFormatter: Formatter = (row: number, cell: number, const gridOptions = (grid && typeof grid.getOptions === 'function') ? grid.getOptions() : {}; const columnParams = columnDef.params || {}; const gridParams = gridOptions.params || {}; + const i18n = gridParams.i18n || columnParams.i18n; - if ((!columnParams.i18n || !(columnParams.i18n instanceof I18N)) && (!gridParams.i18n || !(gridParams.i18n instanceof I18N))) { - throw new Error(`The translate formatter requires the "I18N" Service to be provided as a Column Definition params or a Grid Option params. + if (!i18n || typeof i18n.tr !== 'function') { + throw new Error(`The translate formatter requires the "I18N" Service to be provided as a Grid Options or Column Definition "params". For example: this.gridOptions = { enableTranslate: true, params: { i18n: this.i18n }}`); } - const translate = gridParams.i18n || columnParams.i18n; - // make sure the value is a string (for example a boolean value would throw an error) if (value !== undefined && typeof value !== 'string') { value = value + ''; } - return value ? translate.tr(value.toUpperCase() as string) : ''; + return value ? i18n.tr(value.toUpperCase() as string) : ''; }; diff --git a/aurelia-slickgrid/src/aurelia-slickgrid/formatters/translateFormatter.ts b/aurelia-slickgrid/src/aurelia-slickgrid/formatters/translateFormatter.ts index 477e8390d..821b5c128 100644 --- a/aurelia-slickgrid/src/aurelia-slickgrid/formatters/translateFormatter.ts +++ b/aurelia-slickgrid/src/aurelia-slickgrid/formatters/translateFormatter.ts @@ -1,23 +1,21 @@ import { Column, Formatter } from './../models/index'; -import { I18N } from 'aurelia-i18n'; /** Takes a cell value and translates it (i18n). Requires an instance of the I18N Service:: `params: { i18n: this.i18n } */ export const translateFormatter: Formatter = (row: number, cell: number, value: any, columnDef: Column, dataContext: any, grid: any) => { const gridOptions = (grid && typeof grid.getOptions === 'function') ? grid.getOptions() : {}; const columnParams = columnDef.params || {}; const gridParams = gridOptions.params || {}; + const i18n = gridParams.i18n || columnParams.i18n; - if ((!columnParams.i18n || !(columnParams.i18n instanceof I18N)) && (!gridParams.i18n || !(gridParams.i18n instanceof I18N))) { - throw new Error(`The translate formatter requires the "I18N" Service to be provided as a Column Definition params or a Grid Option params. + if (!i18n || typeof i18n.tr !== 'function') { + throw new Error(`The translate formatter requires the "I18N" Service to be provided as a Grid Options or Column Definition "params". For example: this.gridOptions = { enableTranslate: true, params: { i18n: this.i18n }}`); } - const translate = gridParams.i18n || columnParams.i18n; - // make sure the value is a string (for example a boolean value would throw an error) if (value !== undefined && typeof value !== 'string') { value = value + ''; } - return value ? translate.tr(value) : ''; + return value ? i18n.tr(value) : ''; };