mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: start of pew
This commit is contained in:
1 parent
27c8b348bb
commit
75d7b4554b
13 files changed
+225
-194
No files matched your search
@@ -1,17 +1,16 @@
|
||||
import {} from '@blitzkit/core';
|
||||
import {
|
||||
DEFAULT_LOCALE,
|
||||
STRINGS,
|
||||
SUPPORTED_LOCALES,
|
||||
SUPPORTED_LOCALE_FLAGS,
|
||||
} from '@blitzkit/i18n';
|
||||
import { Select } from '@radix-ui/themes';
|
||||
import type { LocaleAcceptorProps } from '../hooks/useLocale';
|
||||
import { BlitzKitTheme } from './BlitzKitTheme';
|
||||
type BlitzKitStrings,
|
||||
} from "@blitzkit/i18n";
|
||||
import locales from "@blitzkit/i18n/locales.json";
|
||||
import { Select } from "@radix-ui/themes";
|
||||
import type { LocaleAcceptorProps } from "../hooks/useLocale";
|
||||
import { BlitzKitTheme } from "./BlitzKitTheme";
|
||||
|
||||
export function LocaleSwitcherThemeWrapper({ locale }: LocaleAcceptorProps) {
|
||||
return (
|
||||
<BlitzKitTheme style={{ background: 'transparent' }}>
|
||||
<BlitzKitTheme style={{ background: "transparent" }}>
|
||||
<LocaleSwitcher locale={locale} />
|
||||
</BlitzKitTheme>
|
||||
);
|
||||
@@ -22,29 +21,33 @@ export function LocaleSwitcher({ locale }: LocaleAcceptorProps) {
|
||||
<Select.Root
|
||||
defaultValue={locale}
|
||||
onValueChange={(locale) => {
|
||||
localStorage.setItem('preferred-locale', locale);
|
||||
localStorage.setItem("preferred-locale", locale);
|
||||
|
||||
let rawPath = window.location.pathname;
|
||||
|
||||
for (const supportedLocale of SUPPORTED_LOCALES) {
|
||||
if (window.location.pathname.startsWith(`/${supportedLocale}`)) {
|
||||
rawPath = rawPath.replace(`/${supportedLocale}`, '');
|
||||
for (const supported of locales.supported) {
|
||||
if (window.location.pathname.startsWith(`/${supported.locale}`)) {
|
||||
rawPath = rawPath.replace(`/${supported.locale}`, "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
window.location.pathname = `${
|
||||
locale === DEFAULT_LOCALE ? '' : `/${locale}`
|
||||
locale === locales.default ? "" : `/${locale}`
|
||||
}${rawPath}`;
|
||||
}}
|
||||
>
|
||||
<Select.Trigger variant="classic" />
|
||||
|
||||
<Select.Content>
|
||||
{SUPPORTED_LOCALES.map((locale) => (
|
||||
{locales.supported.map(({ locale }) => (
|
||||
<Select.Item key={locale} value={locale}>
|
||||
{SUPPORTED_LOCALE_FLAGS[locale]}{' '}
|
||||
{STRINGS[locale].common.locales[locale]}
|
||||
{SUPPORTED_LOCALE_FLAGS[locale]}{" "}
|
||||
{
|
||||
STRINGS[locale].common.locales[
|
||||
locale as keyof BlitzKitStrings["common"]["locales"]
|
||||
]
|
||||
}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select.Content>
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import { assertSecret } from '@blitzkit/core';
|
||||
import { DEFAULT_LOCALE, STRINGS, type SupportedLocale } from '@blitzkit/i18n';
|
||||
import { assertSecret } from "@blitzkit/core";
|
||||
import { STRINGS } from "@blitzkit/i18n";
|
||||
import locales from "@blitzkit/i18n/locales.json";
|
||||
|
||||
export function resolveBranchName(locale: string = DEFAULT_LOCALE) {
|
||||
export function resolveBranchName(locale: string = locales.default) {
|
||||
if (!(locale in STRINGS)) throw new Error(`Unsupported locale: ${locale}`);
|
||||
|
||||
const strings = STRINGS[locale as SupportedLocale];
|
||||
const strings = STRINGS[locale];
|
||||
const secret = assertSecret(import.meta.env.PUBLIC_BRANCH);
|
||||
|
||||
if (
|
||||
assertSecret(import.meta.env.MODE) === 'development' &&
|
||||
secret === 'dev'
|
||||
assertSecret(import.meta.env.MODE) === "development" &&
|
||||
secret === "dev"
|
||||
) {
|
||||
return strings.common.branches.local;
|
||||
} else {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { DEFAULT_LOCALE, STRINGS, type SupportedLocale } from '@blitzkit/i18n';
|
||||
import { STRINGS } from "@blitzkit/i18n";
|
||||
import locales from "@blitzkit/i18n/locales.json";
|
||||
|
||||
export function getStrings(locale: string = DEFAULT_LOCALE) {
|
||||
if (locale in STRINGS) return STRINGS[locale as SupportedLocale];
|
||||
export function getStrings(locale: string = locales.default) {
|
||||
if (locale in STRINGS) return STRINGS[locale];
|
||||
throw new Error(`Unsupported locale: ${locale}`);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
import { AstroSeo } from "@astrolib/seo";
|
||||
import { assertSecret } from "@blitzkit/core";
|
||||
import { DEFAULT_LOCALE, SUPPORTED_LOCALES } from "@blitzkit/i18n";
|
||||
import locales from "@blitzkit/i18n/locales.json";
|
||||
import { literals } from "@blitzkit/i18n/src/literals";
|
||||
import { Box, Flex, Link } from "@radix-ui/themes";
|
||||
import type { GetStaticPaths } from "astro";
|
||||
@@ -16,7 +16,7 @@ import BaseLayout from "../../layouts/BaseLayout.astro";
|
||||
const MAX_TOOLS_PER_ROW = 2;
|
||||
|
||||
const PUBLIC_ASSET_BRANCH = assertSecret(import.meta.env.PUBLIC_BRANCH);
|
||||
const locale = Astro.params.locale ?? DEFAULT_LOCALE;
|
||||
const locale = Astro.params.locale ?? locales.default;
|
||||
const strings = getStrings(Astro.params.locale);
|
||||
const rows: Tool[][] = [];
|
||||
|
||||
@@ -40,9 +40,9 @@ for (const id in tools) {
|
||||
|
||||
export const getStaticPaths = (() => {
|
||||
return [
|
||||
...SUPPORTED_LOCALES.filter((locale) => locale !== DEFAULT_LOCALE).map(
|
||||
(locale) => ({ params: { locale } })
|
||||
),
|
||||
...locales.supported
|
||||
.filter(({ locale }) => locale !== locales.default)
|
||||
.map(({ locale }) => ({ params: { locale } })),
|
||||
{ params: { locale: undefined } },
|
||||
];
|
||||
}) satisfies GetStaticPaths;
|
||||
@@ -81,7 +81,7 @@ export const getStaticPaths = (() => {
|
||||
</Flex> -->
|
||||
|
||||
{
|
||||
locale !== DEFAULT_LOCALE && (
|
||||
locale !== locales.default && (
|
||||
<Flex justify="center" mb="4">
|
||||
<Link
|
||||
href="https://crowdin.com/project/blitzkrieg"
|
||||
@@ -90,7 +90,9 @@ export const getStaticPaths = (() => {
|
||||
>
|
||||
{literals(strings.website.home.help_translate, [
|
||||
"BlitzKit",
|
||||
strings.common.locales[locale],
|
||||
strings.common.locales[
|
||||
locale as keyof typeof strings.common.locales
|
||||
],
|
||||
])}
|
||||
</Link>
|
||||
</Flex>
|
||||
|
||||
Reference in new issue
Block a user