forked from podkrepi-bg/frontend
-
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.
Merge branch 'create-common-components' of https://github.com/daritel…
…ska-platforma/frontend into create-common-components
- Loading branch information
Showing
13 changed files
with
450 additions
and
315 deletions.
There are no files selected for viewing
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
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,3 @@ | ||
{ | ||
"ABOUT":"Относно" | ||
} |
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,4 @@ | ||
{ | ||
"ONE": "Едно", | ||
"TWO": "Две" | ||
} |
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,3 @@ | ||
{ | ||
"ABOUT":"About" | ||
} |
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,4 @@ | ||
{ | ||
"ONE": "One", | ||
"TWO": "Two" | ||
} |
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
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,63 @@ | ||
import i18next from 'i18next' | ||
import { initReactI18next } from 'react-i18next' | ||
import { NextRouter } from 'next/router' | ||
|
||
interface Translation { | ||
[key: string]: string | ||
} | ||
interface Translations { | ||
[namespace: string]: Translation | ||
} | ||
interface I18nResources { | ||
translations: Translations | ||
namespaces: string[] | ||
} | ||
|
||
export const i18nextInit = async (router: NextRouter, i18nResources: I18nResources) => { | ||
if (!i18nResources || !router.locale) { | ||
return | ||
} | ||
|
||
const { translations, namespaces } = i18nResources | ||
|
||
if (!i18next.isInitialized) { | ||
i18next.use(initReactI18next).init({ | ||
lng: router.locale, | ||
|
||
supportedLngs: router.locales, | ||
|
||
fallbackLng: router.defaultLocale, | ||
|
||
ns: namespaces, | ||
|
||
react: { | ||
useSuspense: false, | ||
}, | ||
}) | ||
} | ||
|
||
i18next.setDefaultNamespace(namespaces[0]) | ||
|
||
if (i18next.language !== router.locale) { | ||
i18next.changeLanguage(router.locale) | ||
} | ||
|
||
for (const ns of namespaces) { | ||
if (!i18next.hasResourceBundle(router.locale, ns)) { | ||
i18next.addResourceBundle(router.locale, ns, translations[ns]) | ||
} | ||
} | ||
} | ||
|
||
export async function getTranslations(locale: string | undefined, namespaces: string[]) { | ||
const translations: Translations = {} | ||
|
||
for (const ns of namespaces) { | ||
const { default: data = {} }: { default: Translation } = await import( | ||
`../public/locales/${locale}/${ns}.json` | ||
) | ||
translations[ns] = data | ||
} | ||
|
||
return { translations, namespaces } | ||
} |
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,3 +1,11 @@ | ||
import AboutPage from 'components/about/AboutPage' | ||
import { GetStaticProps } from 'next' | ||
import { getTranslations } from '../i18n' | ||
|
||
export const getStaticProps: GetStaticProps = async ({ locale }) => ({ | ||
props: { | ||
i18nResources: await getTranslations(locale, ['common', 'about']), | ||
}, | ||
}) | ||
|
||
export default AboutPage |
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,3 +1,11 @@ | ||
import IndexPage from 'components/IndexPage' | ||
import { GetStaticProps } from 'next' | ||
import { getTranslations } from '../i18n' | ||
|
||
export const getStaticProps: GetStaticProps = async ({ locale }) => ({ | ||
props: { | ||
i18nResources: await getTranslations(locale, ['common']), | ||
}, | ||
}) | ||
|
||
export default IndexPage |
Oops, something went wrong.