Automatic casing of nouns based on language (#17035)

This commit is contained in:
Philip Allgaier 2023-06-26 14:58:14 +02:00 committed by GitHub
parent a3f0c428f8
commit 96a6261a09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 4 deletions

View File

@ -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);

View File

@ -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
),
});
}