-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add cmsClient, modify NavBar to use useTranslate
- Loading branch information
Showing
10 changed files
with
526 additions
and
79 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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as dotenv from "dotenv"; | ||
dotenv.config({ path: ".env.local" }); | ||
import { writeFile } from "fs/promises"; | ||
import createClient from "./lib/cmsClient"; | ||
import { readItems } from "@directus/sdk"; | ||
|
||
export async function fetchTranslations() { | ||
const client = createClient(); | ||
try { | ||
const translations = await client.request(readItems("Translation")); | ||
// go from [{key: "hello", fi: "Hei", sv: "Hej", en: "Hello"}] to {"hello": {fi: "Hei", sv: "Hej", en: "Hello"}} | ||
const mappedTranslations = translations.reduce( | ||
(map, translation) => ({ | ||
...map, | ||
[translation.key]: { | ||
fi: translation.fi, | ||
en: translation.en, | ||
sv: translation.sv, | ||
}, | ||
}), | ||
{}, | ||
); | ||
|
||
await writeFile( | ||
"./hooks/translations.json", | ||
JSON.stringify(mappedTranslations), | ||
); | ||
console.log("Downloaded and saved translations"); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
} | ||
|
||
fetchTranslations(); |
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,13 +1,19 @@ | ||
{ | ||
"new_test": { "fi": "moi", "en": "hi", "sv": "hej" }, | ||
"general:nation": { | ||
"fi": "Satakuntalainen Osakunta", | ||
"en": "Satakunta Nation", | ||
"sv": "Satakunta Nation" | ||
}, | ||
"home:welcome": { | ||
"fi": "Tervetuloa Satakuntalaisen Osakunnan sivuille", | ||
"en": "Welcome to the website of Satakuntalainen Osakunta", | ||
"nav:forMembers": { | ||
"fi": "Jäsenille", | ||
"en": "For Members", | ||
"sv": "För Medlemmar" | ||
}, | ||
"nav:home": { "fi": "Etusivu", "en": "Home", "sv": "Framsida" }, | ||
"nav:languages": { "fi": "Kielet", "en": "Languages", "sv": "Språk" }, | ||
"nav:nationInfo": { | ||
"fi": "Tietoa osakunnasta", | ||
"en": "Nation Info", | ||
"sv": "Samma på svenska" | ||
} | ||
} |
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,31 @@ | ||
import { createDirectus, rest } from "@directus/sdk"; | ||
|
||
type Schema = { | ||
NavigationLink: NavigationLink[]; | ||
Translation: Translation[]; | ||
}; | ||
|
||
export type NavigationLink = { | ||
labelKey: string; | ||
url: string; | ||
category: "GENERAL" | "FOR_MEMBERS"; | ||
}; | ||
|
||
/* | ||
* You shouldnt use this type, use the better typed one in useTranslate.tsx instead | ||
*/ | ||
export type Translation = { | ||
key: string; | ||
fi: string; | ||
en: string; | ||
sv: string; | ||
}; | ||
|
||
const createClient = () => { | ||
if (process.env.DIRECTUS_URL === undefined) { | ||
throw Error("Environment variable DIRECTUS_URL not defined"); | ||
} | ||
return createDirectus<Schema>(process.env.DIRECTUS_URL).with(rest()); | ||
}; | ||
|
||
export default createClient; |
Oops, something went wrong.