mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +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]!;
|
||||
|
||||
Reference in new issue
Block a user