diff --git a/src/common/translations/auto_case_noun.ts b/src/common/translations/auto_case_noun.ts new file mode 100644 index 0000000000..5099003631 --- /dev/null +++ b/src/common/translations/auto_case_noun.ts @@ -0,0 +1,19 @@ +// In a few languages nouns are always capitalized. This helper +// indicates if for a given language that is the case. + +import { capitalizeFirstLetter } from "../string/capitalize-first-letter"; + +export const useCapitalizedNouns = (language: string): boolean => { + switch (language) { + case "de": + case "lb": + return true; + default: + return false; + } +}; + +export const autoCaseNoun = (noun: string, language: string): string => + useCapitalizedNouns(language) + ? capitalizeFirstLetter(noun) + : noun.toLocaleLowerCase(language); diff --git a/src/data/logbook.ts b/src/data/logbook.ts index 1bb048abdc..f5caa718b7 100644 --- a/src/data/logbook.ts +++ b/src/data/logbook.ts @@ -7,6 +7,7 @@ import { import { computeDomain } from "../common/entity/compute_domain"; import { computeStateDisplay } from "../common/entity/compute_state_display"; import { computeStateDomain } from "../common/entity/compute_state_domain"; +import { autoCaseNoun } from "../common/translations/auto_case_noun"; import { LocalizeFunc } from "../common/translations/localize"; import { HaEntityPickerEntityFilterFunc } from "../components/entity/ha-entity-picker"; import { HomeAssistant } from "../types"; @@ -359,15 +360,21 @@ export const localizeStateMessage = ( case "vibration": if (isOn) { return localize(`${LOGBOOK_LOCALIZE_PATH}.detected_device_class`, { - device_class: localize( - `component.binary_sensor.entity_component.${device_class}.name` + device_class: autoCaseNoun( + localize( + `component.binary_sensor.entity_component.${device_class}.name` + ), + hass.language ), }); } if (isOff) { return localize(`${LOGBOOK_LOCALIZE_PATH}.cleared_device_class`, { - device_class: localize( - `component.binary_sensor.entity_component.${device_class}.name` + device_class: autoCaseNoun( + localize( + `component.binary_sensor.entity_component.${device_class}.name` + ), + hass.language ), }); }