-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3476aac
commit c4f53ef
Showing
7 changed files
with
899 additions
and
2,009 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
'use client'; | ||
|
||
import { useTranslation } from 'react-i18next'; | ||
|
||
export default function HakuPage() { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<div style={{ alignSelf: 'center', width: '70%', padding: '1rem 2rem' }}> | ||
<h2>Valitse hakukohde</h2> | ||
<p>{t('title')}</p> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use server'; | ||
|
||
import { configuration } from './configuration'; | ||
import { client } from './http-client'; | ||
import { Language } from './common'; | ||
|
||
export const getTranslations = async (lng: Language) => { | ||
const translations = {}; | ||
const { data } = await client.get(`${configuration.lokalisaatioUrl}${lng}`); | ||
|
||
console.log(data); | ||
|
||
for (const translation of data) { | ||
translations[translation.key] = translation.value; | ||
} | ||
|
||
console.log(translations); | ||
console.log('TRANSLATIONS ' + lng.toString()); | ||
|
||
return translations; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use client'; | ||
|
||
import HttpBackend from 'i18next-http-backend'; | ||
import i18n from 'i18next'; | ||
import { initReactI18next } from 'react-i18next'; | ||
import { getTranslations } from './localization'; | ||
|
||
export const createLocalization = () => { | ||
i18n | ||
.use(HttpBackend) | ||
.use(initReactI18next) | ||
.init({ | ||
debug: true, | ||
fallbackLng: 'fi', | ||
preload: ['fi', 'sv', 'en'], | ||
lng: 'fi', | ||
backend: { | ||
loadPath: '{{lng}}', | ||
request: (options, url, payload, callback) => { | ||
Check failure on line 19 in src/app/lib/translations.ts GitHub Actions / lint
Check failure on line 19 in src/app/lib/translations.ts GitHub Actions / lint
Check failure on line 19 in src/app/lib/translations.ts GitHub Actions / lint
|
||
getTranslations(url) | ||
.then((data) => { | ||
callback(null, { status: 200, data }); | ||
}) | ||
.catch(() => callback({ status: 404 })); | ||
}, | ||
}, | ||
}); | ||
return i18n; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
'use client'; | ||
import { I18nextProvider } from 'react-i18next'; | ||
import { FullSpinner } from './components/full-spinner'; | ||
import { useAsiointiKieli } from './hooks/useAsiointiKieli'; | ||
import { useAsiointiKieli } from './lib/hooks/useAsiointiKieli'; | ||
import { createLocalization } from './lib/translations'; | ||
|
||
const localization = createLocalization(); | ||
|
||
export default function Wrapper({ children }: { children: React.ReactNode }) { | ||
const { isLoading, isError, error } = useAsiointiKieli(); | ||
const { isLoading, isError, error, data } = useAsiointiKieli(); | ||
|
||
switch (true) { | ||
case isLoading: | ||
return <FullSpinner />; | ||
case isError: | ||
throw error; | ||
default: | ||
return children; | ||
localization.changeLanguage(data?.data ?? 'fi'); | ||
return <I18nextProvider i18n={localization}>{children}</I18nextProvider>; | ||
} | ||
} |