-
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
efcb11f
commit ffcd20a
Showing
9 changed files
with
135 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { CountryData, Category } from '$types'; | ||
import { writable } from 'svelte/store'; | ||
|
||
export const countriesStore = writable<Record<string, CountryData>>({}); | ||
export const categoriesStore = writable<Record<string, Category>>({}); |
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,12 @@ | ||
export type CountryData = { | ||
name: { [key: string]: string }; | ||
alt: string[]; | ||
}; | ||
|
||
export type Category = { | ||
[key: string]: string[]; | ||
}; | ||
|
||
export type LanguageData = { | ||
[key: string]: string; | ||
}; |
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,25 @@ | ||
import type { Category, CountryData } from '$types'; | ||
import type { PageServerLoad } from './$types'; | ||
|
||
export const load: PageServerLoad = async () => { | ||
const categoriesFiles = import.meta.glob<{ default: Category }>('$data/categories/*.json'); | ||
const categories: Record<string, Category> = {}; | ||
|
||
for (const path in categoriesFiles) { | ||
const module = await categoriesFiles[path](); | ||
const categoryName = path.split('/').pop()?.replace('.json', '') || ''; | ||
categories[categoryName] = module.default; | ||
} | ||
|
||
const countriesFiles = import.meta.glob<{ default: CountryData }>('$data/names/*.json'); | ||
const allFlags = []; | ||
for (const path in countriesFiles) { | ||
const countryCode = path.split('/').pop()?.replace('.json', '') || ''; | ||
allFlags.push(countryCode); | ||
} | ||
|
||
return { | ||
categories, | ||
allFlags | ||
}; | ||
}; |
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,11 @@ | ||
import { json } from '@sveltejs/kit'; | ||
import type { RequestHandler } from './$types'; | ||
|
||
export const GET: RequestHandler = async ({ params }) => { | ||
try { | ||
const countryData = await import(`$data/languages/${params.langCode}.json`); | ||
return json(countryData.default); | ||
} catch (error) { | ||
return new Response('Language not found', { status: 404 }); | ||
} | ||
}; |
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,11 @@ | ||
import { json } from '@sveltejs/kit'; | ||
import type { RequestHandler } from './$types'; | ||
|
||
export const GET: RequestHandler = async ({ params }) => { | ||
try { | ||
const countryData = await import(`$data/names/${params.countryCode}.json`); | ||
return json(countryData.default); | ||
} catch (error) { | ||
return new Response('Names not found', { status: 404 }); | ||
} | ||
}; |
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