diff --git a/components/layouts/LanguageSelector.tsx b/components/layouts/LanguageSelector.tsx index a9d1da7..619c548 100644 --- a/components/layouts/LanguageSelector.tsx +++ b/components/layouts/LanguageSelector.tsx @@ -12,6 +12,7 @@ const LanguageSelector = (props) => { if (locale === 'gb') locale = 'en'; router.push('', '', {locale}); }; + return ( { // ["GB", "FR", "ES", "DE", "RU"] ['GB', 'FR'] } - selected={localeShort} + selected={localeShort == "en" ? "GB" : localeShort.toUpperCase()} customLabels={{GB: 'English', FR: 'Francais'}} {...props} className="menu-flags" diff --git a/functions/i18next.ts b/functions/i18next.ts index 2407823..1e58eb0 100644 --- a/functions/i18next.ts +++ b/functions/i18next.ts @@ -19,6 +19,8 @@ export const resources = { }, } as const; +export const availableLanguages = Object.keys(resources); + export const i18n: InitOptions = { // https://www.i18next.com/overview/configuration-options#logging diff --git a/functions/send-emails/index.ts b/functions/send-emails/index.ts index 10fb0de..bd535ab 100644 --- a/functions/send-emails/index.ts +++ b/functions/send-emails/index.ts @@ -56,7 +56,6 @@ const handler: Handler = async (event) => { }; } - console.log("EVENT BODY", event.body) const {recipients, action, locale} = JSON.parse(event.body) as RequestPayload; if (!recipients) { diff --git a/services/mail.ts b/services/mail.ts index e1a5e96..2d38b0a 100644 --- a/services/mail.ts +++ b/services/mail.ts @@ -1,5 +1,6 @@ import {NextRouter} from 'next/router'; import {getLocaleShort} from './utils'; +import {availableLanguages} from '@functions/i18next'; export const sendInviteMails = async ( mails: Array, @@ -25,10 +26,14 @@ export const sendInviteMails = async ( recipients[mails[index]] = { urlVote: urlVotes[index], urlResult: urlResult, + title: name, }; }); const locale = getLocaleShort(router); + if (!availableLanguages.includes(locale)) { + throw Error(`{locale} is not available for mails`) + } const req = await fetch('/.netlify/functions/send-emails', { method: 'POST', @@ -38,7 +43,6 @@ export const sendInviteMails = async ( body: JSON.stringify({ action: "invite", recipients, - title: name, locale, }), }); diff --git a/services/utils.ts b/services/utils.ts index c361728..71fd88b 100644 --- a/services/utils.ts +++ b/services/utils.ts @@ -6,14 +6,10 @@ import {NextRouter} from 'next/router'; export const getLocaleShort = (router: NextRouter): string => { if (!router.locale) { - return router.defaultLocale.substring(0, 2).toUpperCase(); + return router.defaultLocale.substring(0, 2); } - if (router.locale.startsWith("en")) { - return "GB"; - } - - return router.locale.substring(0, 2).toUpperCase(); + return router.locale.substring(0, 2); } diff --git a/tsconfig.json b/tsconfig.json index e656a77..b58b6a1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,36 +1,45 @@ { - "compilerOptions": { - "baseUrl": "./", - "paths": { - "@components/*": ["components/*"], - "@styles/*": ["styles/*"], - "@services/*": ["services/*"] - }, - "target": "es5", - "lib": [ - "dom", - "dom.iterable", - "esnext" - ], - "allowJs": true, - "skipLibCheck": true, - "strict": false, - "forceConsistentCasingInFileNames": true, - "noEmit": true, - "incremental": true, - "esModuleInterop": true, - "module": "esnext", - "moduleResolution": "node", - "resolveJsonModule": true, - "isolatedModules": true, - "jsx": "preserve" - }, - "include": [ - "next-env.d.ts", - "**/*.ts", - "**/*.tsx" - ], - "exclude": [ - "node_modules" - ] + "compilerOptions": { + "baseUrl": "./", + "paths": { + "@components/*": [ + "components/*" + ], + "@styles/*": [ + "styles/*" + ], + "@services/*": [ + "services/*" + ], + "@functions/*": [ + "functions/*" + ] + }, + "target": "es5", + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "skipLibCheck": true, + "strict": false, + "forceConsistentCasingInFileNames": true, + "noEmit": true, + "incremental": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "preserve" + }, + "include": [ + "next-env.d.ts", + "**/*.ts", + "**/*.tsx" + ], + "exclude": [ + "node_modules" + ] }