Skip to content

Commit

Permalink
Provide default en for undefined resolvedLanguage
Browse files Browse the repository at this point in the history
  • Loading branch information
starsep committed Dec 23, 2023
1 parent 568abad commit 153a6df
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/components/downloadCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { backendBaseUrl, fetchCountriesData } from "../backend";
const worldCountryCode = "WORLD";

export default function DownloadCard() {
const { t, i18n: { resolvedLanguage: language } } = useTranslation();
const { t, i18n: { resolvedLanguage } } = useTranslation();
const language = resolvedLanguage ?? "en";
function countryName(country: Country) {
if (country.code === worldCountryCode) return t("sidebar.world");
const backendLanguageUppercase = language.toUpperCase();
Expand Down
2 changes: 1 addition & 1 deletion src/components/languageSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function LanguageSwitcher() {
<div className="select">
<select
id="language-switcher"
value={i18n.resolvedLanguage}
value={i18n.resolvedLanguage ?? "en"}
onChange={(e) => {
i18n.changeLanguage(e.target.value);
}}
Expand Down
5 changes: 3 additions & 2 deletions src/components/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const Map: FC<MapProps> = ({ openChangesetId, setOpenChangesetId }) => {
authState: { auth }, setModalState, sidebarAction, setSidebarAction, sidebarData, setSidebarData,
} = useAppContext();
const { t, i18n: { resolvedLanguage } } = useTranslation();
const language = resolvedLanguage ?? "en";

const hash4MapName = "map";

Expand Down Expand Up @@ -203,7 +204,7 @@ const Map: FC<MapProps> = ({ openChangesetId, setOpenChangesetId }) => {
maplibregl,
placeholder: t("sidebar.find_location"),
});
maplibreGeocoder.setLanguage(resolvedLanguage);
maplibreGeocoder.setLanguage(language);

map.addControl(maplibreGeocoder);
mapRef.current = map;
Expand Down Expand Up @@ -321,7 +322,7 @@ const Map: FC<MapProps> = ({ openChangesetId, setOpenChangesetId }) => {
);
}
}, [initialLatitude, initialLongitude, initialZoom,
setSidebarAction, setSidebarData, setSidebarLeftShown, resolvedLanguage]);
setSidebarAction, setSidebarData, setSidebarLeftShown, language]);

return (
<>
Expand Down
5 changes: 3 additions & 2 deletions src/components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const SiteNavbar: FC<SiteNavbarProps> = ({ toggleSidebarShown }) => {
const { setModalState } = useAppContext();
const [isActive, setIsActive] = React.useState(false);
const { t, i18n: { resolvedLanguage } } = useTranslation();
const language = resolvedLanguage ?? "en";
return (
<Navbar color="success" className="has-background-green">
<Navbar.Brand>
Expand Down Expand Up @@ -97,14 +98,14 @@ const SiteNavbar: FC<SiteNavbarProps> = ({ toggleSidebarShown }) => {
<ReactStoreBadges
platform="android"
url="https://play.google.com/store/apps/details?id=pl.enteam.aed_map"
language={resolvedLanguage}
language={language}
/>
</Navbar.Item>
<Navbar.Item p={1} renderAs="div">
<ReactStoreBadges
platform="ios"
url="https://apps.apple.com/app/mapa-aed/id1638495701"
language={resolvedLanguage}
language={language}
/>
</Navbar.Item>
<Navbar.Item className="is-hidden-desktop" textColor="white" renderAs="div" pl={0} pr={0}>
Expand Down
9 changes: 5 additions & 4 deletions src/components/sidebar/defibrillatorEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ const DefibrillatorEditor: FC<DefibrillatorEditorProps> = ({
closeSidebar, marker, openChangesetId, setOpenChangesetId, data,
}) => {
const { t, i18n: { resolvedLanguage } } = useTranslation();
const language = resolvedLanguage ?? "en";
const { authState: { auth }, setModalState } = useAppContext();
const newAED = data === null;
const initialTags = data !== null ? data.tags : { emergency: "defibrillator" };
const [access, setAccess] = useState<string>(initialTags.access || "");
const [indoor, setIndoor] = useState<string>(initialTags.indoor || "");
const [level, setLevel] = useState<string>(initialTags.level || "");
const [location, setLocation] = useState<string>(
initialTags[`defibrillator:location:${resolvedLanguage}`] || "",
initialTags[`defibrillator:location:${language}`] || "",
);
const [phoneNumber, setPhoneNumber] = useState<string>(initialTags.phone || initialTags["contact:phone"] || "");
const todayDate = new Date().toISOString().substring(0, 10);
Expand All @@ -35,7 +36,7 @@ const DefibrillatorEditor: FC<DefibrillatorEditorProps> = ({
if (access.length > 0) tags.access = access;
if (indoor.length > 0) tags.indoor = indoor;
if (level.length > 0) tags.level = level.trim();
if (location.trim().length > 0) tags[`defibrillator:location:${resolvedLanguage}`] = location.trim();
if (location.trim().length > 0) tags[`defibrillator:location:${language}`] = location.trim();
if (phoneNumber.trim().length > 0) tags.phone = phoneNumber.trim();
if (checkDate.trim().length > 0) tags.check_date = checkDate.trim();
return tags;
Expand Down Expand Up @@ -68,7 +69,7 @@ const DefibrillatorEditor: FC<DefibrillatorEditorProps> = ({
lat: lngLat.lat,
tags,
};
getOpenChangesetId(auth, openChangesetId, setOpenChangesetId, resolvedLanguage, newAED)
getOpenChangesetId(auth, openChangesetId, setOpenChangesetId, language, newAED)
.then((changesetId) => addDefibrillatorToOSM(auth, changesetId, newDefibrillatorData))
.then((newNodeId) => {
button.classList.remove("is-loading");
Expand All @@ -84,7 +85,7 @@ const DefibrillatorEditor: FC<DefibrillatorEditorProps> = ({
...data,
tags,
};
getOpenChangesetId(auth, openChangesetId, setOpenChangesetId, resolvedLanguage, newAED)
getOpenChangesetId(auth, openChangesetId, setOpenChangesetId, language, newAED)
.then((changesetId) => editDefibrillatorInOSM(auth, changesetId, defibrillatorData))
.then((newVersion) => {
button.classList.remove("is-loading");
Expand Down
2 changes: 1 addition & 1 deletion src/components/sidebar/openingHours.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function parseOpeningHours(openingHours: string, nominatimStateData: NominatimSt

try {
const oh = new OpeningHours(openingHours, nominatimStateData, 2);
const config = getOpeningHoursConfig(i18n.resolvedLanguage);
const config = getOpeningHoursConfig(i18n.resolvedLanguage ?? "en");
// @ts-ignore
return oh.prettifyValue({ conf: config });
} catch (error) {
Expand Down

0 comments on commit 153a6df

Please sign in to comment.