Skip to content

Commit

Permalink
Issue #529: recovery default language on be
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzov96 authored and danielecalda committed Jul 25, 2023
1 parent 2fb3f8b commit 19eb72e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function SortResultList({
</option>
{options.data?.map((option) => {
return (
<React.Fragment>
<React.Fragment key={option.id + "fragment"}>
<option
key={option.id + "asc"}
value={JSON.stringify({
Expand Down
14 changes: 14 additions & 0 deletions js-packages/search-frontend/src/components/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ export function OpenK9Client({
await response.json();
return data;
},
async getLanguageDefault() {
const response = await authFetch(
`/api/datasource/buckets/current/defaultLanguage`,
{
method: "GET",
headers: { Accept: "application/json" },
},
);
if (!response.ok) {
throw new Error();
}
const data: { value: string } = await response.json();
return data;
},
async getSuggestions({
searchQuery,
suggestionCategoryId,
Expand Down
29 changes: 28 additions & 1 deletion js-packages/search-frontend/src/embeddable/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ import { SortResultList } from "../components/SortResultList";
import { FiltersHorizontalMemo } from "../components/FiltersHorizontal";
import { DetailMobileMemo } from "../components/DetailMobile";
import "../i18n";
import { I18nextProvider } from "react-i18next";
import { I18nextProvider, useTranslation } from "react-i18next";
import i18next from "i18next";
import { ActiveFilter } from "../components/ActiveFilters";
import { FiltersMobileMemo } from "../components/FiltersMobile";
import { FiltersMobileLiveChangeMemo } from "../components/FiltersMobileLiveChange";
import { DataRangePicker } from "../components/DateRangePicker";

type MainProps = {
configuration: Configuration;
onConfigurationChange: ConfigurationUpdateFunction;
Expand Down Expand Up @@ -77,6 +78,17 @@ export function Main({
const dynamicFilters = useQuery(["handle-dynamic-filters", {}], async () => {
return await client.handle_dynamic_filters();
});
const defaultLanguage = "en";
const language = useQuery(["language", {}], async () => {
return await client.getLanguageDefault();
});
const { i18n } = useTranslation();
React.useEffect(() => {
i18n.changeLanguage(
remappingLanguage({ language: language.data?.value || defaultLanguage }),
);
}, []);

const [isMobile, setIsMobile] = React.useState(false);
React.useEffect(() => {
const checkIfMobile = () => {
Expand Down Expand Up @@ -633,3 +645,18 @@ function fixQueryAnalysisResult(data: AnalysisResponse) {
}),
};
}

function remappingLanguage({ language }: { language: string }) {
switch (language) {
case "it_IT":
return "it";
case "es_ES":
return "es;";
case "en_US":
return "en";
case "fr_FR":
return "fr";
default:
return "en";
}
}

0 comments on commit 19eb72e

Please sign in to comment.