Skip to content

Commit

Permalink
Update country picker dialog in onboarding (#24551)
Browse files Browse the repository at this point in the history
* Update country picker dialog in onboarding

* Handle if language has no locale

* Don't fall back to NL
  • Loading branch information
balloob authored Mar 8, 2025
1 parent 1ac0092 commit 6ed2640
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/ha-country-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "./ha-list-item";
import "./ha-select";
import type { HaSelect } from "./ha-select";

const COUNTRIES = [
export const COUNTRIES = [
"AD",
"AE",
"AF",
Expand Down
13 changes: 12 additions & 1 deletion src/onboarding/onboarding-core-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { fireEvent } from "../common/dom/fire_event";
import type { LocalizeFunc } from "../common/translations/localize";
import "../components/ha-alert";
import "../components/ha-circular-progress";
import "../components/ha-country-picker";
import { COUNTRIES } from "../components/ha-country-picker";
import type { ConfigUpdateValues } from "../data/core";
import { saveCoreConfig } from "../data/core";
import { countryCurrency } from "../data/currency";
Expand Down Expand Up @@ -131,6 +131,17 @@ class OnboardingCoreConfig extends LitElement {
this._save(ev);
return;
}

// Set suggested country
let suggested: string | undefined;
if (navigator.language) {
const lang = navigator.language.split("-").pop()!.toUpperCase();
if (COUNTRIES.includes(lang)) {
suggested = lang;
}
}
this._country = suggested;

fireEvent(this, "onboarding-progress", { increase: 0.5 });
await this.updateComplete;
setTimeout(
Expand Down
2 changes: 1 addition & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8234,7 +8234,7 @@
"osm_privacy_policy": "Privacy policy",
"title_location_detect": "Do you want us to detect your location?",
"intro_location_detect": "We can detect your location by making a one-time request to an external service.",
"country_intro": "We would like to know the country your home is in, so we can use the correct units for you.",
"country_intro": "We would like to know the country your home is in, so we can use the correct units.",
"location_name": "Name of your Home Assistant installation",
"location_name_default": "Home",
"address_label": "Search address",
Expand Down

0 comments on commit 6ed2640

Please sign in to comment.