Set language from URL.
This commit is contained in:
@@ -1,8 +1,17 @@
|
|||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage } from 'react-intl';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link, useLocation } from 'react-router-dom';
|
||||||
|
import { useSetRecoilState } from 'recoil';
|
||||||
|
import { currentLanguage } from '../atoms/language';
|
||||||
import './Confirmation.scss';
|
import './Confirmation.scss';
|
||||||
|
import { getLangFromSearch } from './utils';
|
||||||
|
|
||||||
export const Confirmation = () => {
|
export const Confirmation = () => {
|
||||||
|
const { search } = useLocation();
|
||||||
|
const setlang = useSetRecoilState(currentLanguage);
|
||||||
|
|
||||||
|
const lang = getLangFromSearch(search);
|
||||||
|
if (lang != '') setlang(lang);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='Confirmation'>
|
<div className='Confirmation'>
|
||||||
<h1>
|
<h1>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import './Main.scss';
|
import './Main.scss';
|
||||||
|
|
||||||
import { Link, useParams } from 'react-router-dom';
|
import { Link, useParams, useLocation } from 'react-router-dom';
|
||||||
import { Menu } from '../components/Menu';
|
import { Menu } from '../components/Menu';
|
||||||
import { NavBar } from '../components/NavBar';
|
import { NavBar } from '../components/NavBar';
|
||||||
import { Program } from '../components/Program';
|
import { Program } from '../components/Program';
|
||||||
@@ -9,6 +9,9 @@ import { LanguagePicker } from '../components/LanguagePicker';
|
|||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage } from 'react-intl';
|
||||||
import { DateAndPlace } from '../components/DateAndPlace';
|
import { DateAndPlace } from '../components/DateAndPlace';
|
||||||
import { Info } from '../components/Info';
|
import { Info } from '../components/Info';
|
||||||
|
import { getLangFromSearch } from './utils';
|
||||||
|
import { useSetRecoilState } from 'recoil';
|
||||||
|
import { currentLanguage } from '../atoms/language';
|
||||||
|
|
||||||
interface MainParams {
|
interface MainParams {
|
||||||
page: string;
|
page: string;
|
||||||
@@ -16,6 +19,11 @@ interface MainParams {
|
|||||||
|
|
||||||
export const Main = () => {
|
export const Main = () => {
|
||||||
const { page } = useParams<MainParams>();
|
const { page } = useParams<MainParams>();
|
||||||
|
const { search } = useLocation();
|
||||||
|
const setlang = useSetRecoilState(currentLanguage);
|
||||||
|
|
||||||
|
const lang = getLangFromSearch(search);
|
||||||
|
if (lang != '') setlang(lang);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='Main'>
|
<div className='Main'>
|
||||||
|
|||||||
@@ -4,9 +4,18 @@ import { FormattedMessage } from 'react-intl';
|
|||||||
import RegForm from '../components/RegForm';
|
import RegForm from '../components/RegForm';
|
||||||
import { RegistrationHeader } from '../components/RegistrationHeader';
|
import { RegistrationHeader } from '../components/RegistrationHeader';
|
||||||
import { LanguagePicker } from '../components/LanguagePicker';
|
import { LanguagePicker } from '../components/LanguagePicker';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link, useLocation } from 'react-router-dom';
|
||||||
|
import { getLangFromSearch } from './utils';
|
||||||
|
import { useSetRecoilState } from 'recoil';
|
||||||
|
import { currentLanguage } from '../atoms/language';
|
||||||
|
|
||||||
export const Registration = () => {
|
export const Registration = () => {
|
||||||
|
const { search } = useLocation();
|
||||||
|
const setlang = useSetRecoilState(currentLanguage);
|
||||||
|
|
||||||
|
const lang = getLangFromSearch(search);
|
||||||
|
if (lang != '') setlang(lang);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<RegistrationHeader />
|
<RegistrationHeader />
|
||||||
|
|||||||
9
src/pages/utils.ts
Normal file
9
src/pages/utils.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
export const getLangFromSearch = (search: string) => {
|
||||||
|
const param = search.substring(0,6);
|
||||||
|
const lang = search.substring(6,8);
|
||||||
|
|
||||||
|
if(param === '?lang=' && (lang === 'en' || lang === 'fi' || lang === 'sk')) {
|
||||||
|
return lang;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user