Skip to content

Commit

Permalink
feat: Update language options and selected language logic in LunarPha…
Browse files Browse the repository at this point in the history
…seCardEditor
  • Loading branch information
ngocjohn committed Aug 25, 2024
1 parent b2a6d42 commit 4921644
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,17 @@ export class LunarPhaseCardEditor extends LitElement implements LovelaceCardEdit
}

private _renderViewConfiguration(): TemplateResult {
const langOpts = [...languageOptions.sort((a, b) => a.name.localeCompare(b.name))];
const syslang = this.hass?.language;

const langOpts = [
{ key: 'system', nativeName: 'System' },
...languageOptions.sort((a, b) => a.name.localeCompare(b.name)),
];

// Map langOpts to the format expected by _haComboBox
const itemsLang = langOpts.map((lang) => ({
value: lang.key,
label: `${lang.name} (${lang.nativeName})`,
label: lang.nativeName,
}));

const viewItemMap = [
Expand All @@ -215,7 +221,7 @@ export class LunarPhaseCardEditor extends LitElement implements LovelaceCardEdit
${this._haComboBox(
itemsLang, // Passing the mapped language options
'placeHolder.language', // Localization key for the label
this._config?.selected_language || this._systemLanguage, // Currently selected language
this._config?.selected_language || '', // Currently selected language
'selected_language', // Config value key
false, // Allow custom value
)}
Expand Down Expand Up @@ -437,6 +443,12 @@ export class LunarPhaseCardEditor extends LitElement implements LovelaceCardEdit
...this._config.font_customize,
[key]: updatedValue,
};
} else if (configValue === 'selected_language') {
if (value === 'system' || value === undefined) {
updates.selected_language = this.hass?.language;
} else {
updates.selected_language = value;
}
} else {
// Update the main configuration object
updates[configValue] = value;
Expand Down
2 changes: 2 additions & 0 deletions src/lunar-phase-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ export class LunarPhaseCard extends LitElement {
public static getStubConfig = (hass: HomeAssistant): Record<string, unknown> => {
const defaultLatitude = hass.config.latitude || 0;
const defaultLongitude = hass.config.longitude || 0;
const lang = hass.language;
return {
...defaultConfig,
latitude: defaultLatitude,
longitude: defaultLongitude,
selected_language: lang,
};
};

Expand Down

0 comments on commit 4921644

Please sign in to comment.