Skip to content

Commit

Permalink
JSUI-3321 Removed generic localization from dynamic facet values (#1812)
Browse files Browse the repository at this point in the history
  • Loading branch information
btaillon-coveo authored Dec 6, 2021
1 parent 59f3167 commit 60f17d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/ui/Facet/FacetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class FacetUtils {
}

static getDisplayValueFromValueCaption(value: string, field: string, valueCaption: Record<string, string>) {
const returnValue = this.tryToGetTranslatedCaption(field, value);
const returnValue = this.tryToGetTranslatedCaption(field, value, false);
return valueCaption[value] || returnValue;
}

Expand Down Expand Up @@ -93,17 +93,17 @@ export class FacetUtils {
}
}

static tryToGetTranslatedCaption(field: string, value: string) {
static tryToGetTranslatedCaption(field: string, value: string, fallbackOnLocalization = true) {
let found: string;

if (QueryUtils.isStratusAgnosticField(field.toLowerCase(), '@filetype')) {
found = FileTypes.getFileType(value).caption;
found = FileTypes.getFileType(value, fallbackOnLocalization).caption;
} else if (QueryUtils.isStratusAgnosticField(field.toLowerCase(), '@objecttype')) {
found = FileTypes.getObjectType(value).caption;
found = FileTypes.getObjectType(value, fallbackOnLocalization).caption;
} else if (FacetUtils.isMonthFieldValue(field, value)) {
const month = parseInt(value, 10);
found = DateUtils.monthToString(month - 1);
} else {
} else if (fallbackOnLocalization) {
found = l(value);
}
return found != undefined && Utils.isNonEmptyString(found) ? found : value;
Expand Down
8 changes: 4 additions & 4 deletions src/ui/Misc/FileTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class FileTypes {
}
}

static getObjectType(objecttype: string): IFileTypeInfo {
static getObjectType(objecttype: string, fallbackOnLocalization = true): IFileTypeInfo {
// We must use lowercase filetypes because that's how the CSS classes
// are generated (they are case sensitive, alas).
const loweredCaseObjecttype = objecttype.toLowerCase();
Expand All @@ -43,13 +43,13 @@ export class FileTypes {
// Some strings are sent as `objecttype_[...]` to specify a dictionary to use. If there's no match, try using
// the main dictionary by using the original value.
if (localizedString.toLowerCase() == variableValue.toLowerCase()) {
localizedString = l(objecttype);
localizedString = fallbackOnLocalization ? l(objecttype) : objecttype;
}

return this.safelyBuildFileTypeInfo('objecttype', loweredCaseObjecttype, localizedString);
}

static getFileType(filetype: string): IFileTypeInfo {
static getFileType(filetype: string, fallbackOnLocalization = true): IFileTypeInfo {
// We must use lowercase filetypes because that's how the CSS classes
// are generated (they are case sensitive, alas).
let loweredCaseFiletype = filetype.toLowerCase();
Expand All @@ -66,7 +66,7 @@ export class FileTypes {
if (localizedString.toLowerCase() == variableValue.toLowerCase()) {
// Some strings are sent as `filetype_[...]` to specify a dictionary to use. If there's no match, try using
// The main dictionary by using the original value.
localizedString = l(filetype);
localizedString = fallbackOnLocalization ? l(filetype) : filetype;
}

return this.safelyBuildFileTypeInfo('filetype', loweredCaseFiletype, localizedString);
Expand Down

0 comments on commit 60f17d8

Please sign in to comment.