mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Automatic casing of nouns based on language (#17035)
This commit is contained in:
parent
a3f0c428f8
commit
96a6261a09
19
src/common/translations/auto_case_noun.ts
Normal file
19
src/common/translations/auto_case_noun.ts
Normal 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);
|
@ -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
|
||||
),
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user