From 28d920c1342d42b550b4293e59f287637dff42c5 Mon Sep 17 00:00:00 2001 From: Rafal Dziegielewski Date: Fri, 19 Jan 2024 12:00:53 +0100 Subject: [PATCH] fix: add missing translations for boolean/select fields --- src/backend/decorators/property/property-decorator.ts | 2 +- .../decorators/property/property-options.interface.ts | 2 +- src/frontend/components/property-type/boolean/filter.tsx | 6 ++++-- src/frontend/components/property-type/default-type/edit.tsx | 4 ++-- .../components/property-type/default-type/filter.tsx | 4 ++-- .../interfaces/property-json/property-json.interface.ts | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/backend/decorators/property/property-decorator.ts b/src/backend/decorators/property/property-decorator.ts index 36e7f1ea5..858187171 100644 --- a/src/backend/decorators/property/property-decorator.ts +++ b/src/backend/decorators/property/property-decorator.ts @@ -144,7 +144,7 @@ export class PropertyDecorator { * * @returns {Array<{value: string, label: string}>} */ - availableValues(): null | Array<{ value: string | number; label: string }> { + availableValues(): null | Array<{ value: string | number; label?: string }> { if (this.options.availableValues) { return this.options.availableValues } diff --git a/src/backend/decorators/property/property-options.interface.ts b/src/backend/decorators/property/property-options.interface.ts index bf9f7caf6..b58988554 100644 --- a/src/backend/decorators/property/property-options.interface.ts +++ b/src/backend/decorators/property/property-options.interface.ts @@ -66,7 +66,7 @@ export default interface PropertyOptions { */ availableValues?: Array<{ value: string | number; - label: string; + label?: string; }>; /** diff --git a/src/frontend/components/property-type/boolean/filter.tsx b/src/frontend/components/property-type/boolean/filter.tsx index ff2fe80d4..73020adf6 100644 --- a/src/frontend/components/property-type/boolean/filter.tsx +++ b/src/frontend/components/property-type/boolean/filter.tsx @@ -5,6 +5,7 @@ import mapValue from './map-value.js' import { FilterPropertyProps } from '../base-property-props.js' import allowOverride from '../../../hoc/allow-override.js' import PropertyLabel from '../utils/property-label/property-label.js' +import { useTranslation } from '../../../hooks/index.js' const boolValue = (s: string): boolean => { if (/true/i.test(s)) { @@ -15,10 +16,11 @@ const boolValue = (s: string): boolean => { const Filter: React.FC = (props) => { const { property, filter = {}, onChange } = props + const { tp } = useTranslation() const value = typeof filter[property.path] === 'undefined' ? '' : boolValue(filter[property.path]) const options = [ - { value: true, label: mapValue(true) }, - { value: false, label: mapValue(false) }, + { value: true, label: tp(`${property.path}.true`, property.resourceId, { defaultValue: mapValue(true) }) }, + { value: false, label: tp(`${property.path}.false`, property.resourceId, { defaultValue: mapValue(false) }) }, ] const selected = options.find((o) => o.value === value) const handleChange = (s) => { diff --git a/src/frontend/components/property-type/default-type/edit.tsx b/src/frontend/components/property-type/default-type/edit.tsx index ea89a7cad..2e7b8196f 100644 --- a/src/frontend/components/property-type/default-type/edit.tsx +++ b/src/frontend/components/property-type/default-type/edit.tsx @@ -25,7 +25,7 @@ const Edit: FC = (props) => { const SelectEdit: FC = (props) => { const { record, property, onChange } = props - const { translateProperty } = useTranslation() + const { tp } = useTranslation() if (!property.availableValues) { return null } @@ -34,7 +34,7 @@ const SelectEdit: FC = (props) => { // eslint-disable-next-line max-len const availableValues = property.availableValues.map((v) => ({ ...v, - label: translateProperty(v.label), + label: tp(`${property.path}.${v.value}`, property.resourceId, { defaultValue: v.label ?? v.value }), })) // eslint-disable-next-line eqeqeq const selected = availableValues.find((av) => av.value == propValue) diff --git a/src/frontend/components/property-type/default-type/filter.tsx b/src/frontend/components/property-type/default-type/filter.tsx index 24829409d..78da8e164 100644 --- a/src/frontend/components/property-type/default-type/filter.tsx +++ b/src/frontend/components/property-type/default-type/filter.tsx @@ -8,7 +8,7 @@ import { useTranslation } from '../../../hooks/use-translation.js' const Filter: React.FC = (props) => { const { property, onChange, filter } = props - const { translateProperty } = useTranslation() + const { tp } = useTranslation() const handleInputChange = (event) => { onChange(property.path, event.target.value) @@ -25,7 +25,7 @@ const Filter: React.FC = (props) => { if (property.availableValues) { const availableValues = property.availableValues.map((v) => ({ ...v, - label: translateProperty(v.label), + label: tp(`${property.path}.${v.value}`, property.resourceId, { defaultValue: v.label ?? v.value }), })) const selected = property.availableValues.find((av) => av.value === value) return ( diff --git a/src/frontend/interfaces/property-json/property-json.interface.ts b/src/frontend/interfaces/property-json/property-json.interface.ts index 9c8e953b2..e6484ce25 100644 --- a/src/frontend/interfaces/property-json/property-json.interface.ts +++ b/src/frontend/interfaces/property-json/property-json.interface.ts @@ -26,7 +26,7 @@ export interface PropertyJSON { /** * If property has restricted number of values */ - availableValues: Array<{label: string; value: string | number}> | null; + availableValues: Array<{label?: string; value: string | number}> | null; /** * Property uniq name */