mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
feat: set up locales
This commit is contained in:
1 parent
3bbc083b2a
commit
60ab845326
7 files changed
+28
-14
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { Locale } from 'discord.js';
|
||||
import { SUPPORTED_LOCALES } from '../localization/strings/constants';
|
||||
import { SUPPORTED_DISCORD_LOCALES } from '../localization/strings/constants';
|
||||
import { translator } from '../localization/translator';
|
||||
|
||||
const validNameRegex = /^[-_\p{L}\p{N}\p{sc=Deva}\p{sc=Thai}]{1,32}$/u;
|
||||
@@ -9,7 +9,7 @@ export function localizationObject(
|
||||
literals?: string[],
|
||||
strict = false,
|
||||
) {
|
||||
return SUPPORTED_LOCALES.reduce<Partial<Record<Locale, string>>>(
|
||||
return SUPPORTED_DISCORD_LOCALES.reduce<Partial<Record<Locale, string>>>(
|
||||
(localizations, locale) => {
|
||||
const { translate } = translator(locale);
|
||||
const translation = translate(path, literals);
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import { LOCALE_FILES } from '@blitzkit/core';
|
||||
import { Locale } from 'discord.js';
|
||||
|
||||
export const SUPPORTED_LOCALES: Locale[] = [
|
||||
Locale.EnglishUS,
|
||||
Locale.SpanishES,
|
||||
Locale.Croatian,
|
||||
Locale.Russian,
|
||||
Locale.Ukrainian,
|
||||
Locale.ChineseCN,
|
||||
];
|
||||
export const SUPPORTED_DISCORD_LOCALES = Object.values(
|
||||
LOCALE_FILES,
|
||||
) as Locale[];
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Locale } from 'discord.js';
|
||||
import { SUPPORTED_LOCALES } from './constants';
|
||||
import { SUPPORTED_DISCORD_LOCALES } from './constants';
|
||||
|
||||
export type TranslationFragmentTree = {
|
||||
[key: string]: TranslationFragment;
|
||||
@@ -8,7 +8,7 @@ export type TranslationFragmentTree = {
|
||||
};
|
||||
export type TranslationFragment = string | TranslationFragmentTree;
|
||||
|
||||
export const translations = SUPPORTED_LOCALES.reduce<
|
||||
export const translations = SUPPORTED_DISCORD_LOCALES.reduce<
|
||||
Partial<Record<Locale, TranslationFragment>>
|
||||
>(
|
||||
(table, locale) => ({
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { Locale } from 'discord.js';
|
||||
import { translations } from './strings';
|
||||
import { SUPPORTED_LOCALES } from './strings/constants';
|
||||
import { SUPPORTED_DISCORD_LOCALES } from './strings/constants';
|
||||
|
||||
export function translator(localeRaw: Locale) {
|
||||
const locale =
|
||||
localeRaw !== Locale.EnglishUS && SUPPORTED_LOCALES.includes(localeRaw)
|
||||
localeRaw !== Locale.EnglishUS &&
|
||||
SUPPORTED_DISCORD_LOCALES.includes(localeRaw)
|
||||
? localeRaw
|
||||
: Locale.EnglishUS;
|
||||
const strings = translations[locale]!;
|
||||
|
||||
@@ -46,4 +46,5 @@ export * from './votes';
|
||||
export * from './createDefaultProvisions';
|
||||
export * from './metaSortTank';
|
||||
export * from './romanize';
|
||||
export * from './supportedLocales';
|
||||
export * from './youtubers';
|
||||
@@ -0,0 +1,10 @@
|
||||
export const SUPPORTED_LOCALES = ['en', 'es', 'hr', 'ru', 'uk', 'cn'];
|
||||
export const LOCALE_FILES: Record<(typeof SUPPORTED_LOCALES)[number], string> =
|
||||
{
|
||||
en: 'en-US',
|
||||
es: 'es-ES',
|
||||
hr: 'hr',
|
||||
ru: 'ru',
|
||||
uk: 'uk',
|
||||
cn: 'zh-CN',
|
||||
};
|
||||
@@ -2,9 +2,15 @@
|
||||
|
||||
import react from '@astrojs/react';
|
||||
import sitemap from '@astrojs/sitemap';
|
||||
import { SUPPORTED_LOCALES } from '@blitzkit/core';
|
||||
import { defineConfig } from 'astro/config';
|
||||
|
||||
export default defineConfig({
|
||||
i18n: {
|
||||
defaultLocale: 'en',
|
||||
locales: SUPPORTED_LOCALES,
|
||||
},
|
||||
|
||||
devToolbar: { enabled: false },
|
||||
output: 'static',
|
||||
site: 'https://blitzkit.app',
|
||||
|
||||
Reference in new issue
Block a user