mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 02:37:05 +02:00
feat: rename
This commit is contained in:
1 parent
b71feca802
commit
bf0246ec26
3 files changed
+17
-17
No files matched your search
@@ -1,9 +1,9 @@
|
||||
import { Locale } from 'discord.js';
|
||||
import { locales } from '../localization/strings';
|
||||
import { SUPPORTED_LOCALES } from '../localization/strings';
|
||||
import { translator } from '../localization/translator';
|
||||
|
||||
export function localizationObject(path: string, literals?: string[]) {
|
||||
return locales.reduce<Partial<Record<Locale, string>>>(
|
||||
return SUPPORTED_LOCALES.reduce<Partial<Record<Locale, string>>>(
|
||||
(localizations, locale) => {
|
||||
const { translate } = translator(locale);
|
||||
return {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Locale } from 'discord.js';
|
||||
|
||||
export const locales: Locale[] = [Locale.EnglishUS, Locale.SpanishES];
|
||||
export const SUPPORTED_LOCALES: Locale[] = [Locale.EnglishUS, Locale.SpanishES];
|
||||
|
||||
export type TranslationFragmentTree = {
|
||||
[key: string]: TranslationFragment;
|
||||
@@ -9,15 +9,13 @@ export type TranslationFragmentTree = {
|
||||
};
|
||||
export type TranslationFragment = string | TranslationFragmentTree;
|
||||
|
||||
export const translations = locales
|
||||
.map((locale) => ({
|
||||
locale,
|
||||
translations: require(`../../lang/${locale}.json`),
|
||||
}))
|
||||
.reduce(
|
||||
(table, { locale, translations }) => ({
|
||||
...table,
|
||||
[locale]: translations,
|
||||
}),
|
||||
{},
|
||||
) as Record<Locale, TranslationFragment>;
|
||||
export const translations = SUPPORTED_LOCALES.map((locale) => ({
|
||||
locale,
|
||||
translations: require(`../../lang/${locale}.json`),
|
||||
})).reduce(
|
||||
(table, { locale, translations }) => ({
|
||||
...table,
|
||||
[locale]: translations,
|
||||
}),
|
||||
{},
|
||||
) as Record<Locale, TranslationFragment>;
|
||||
@@ -1,8 +1,10 @@
|
||||
import { Locale } from 'discord.js';
|
||||
import { locales, translations } from './strings';
|
||||
import { SUPPORTED_LOCALES, translations } from './strings';
|
||||
|
||||
export function translator(localeRaw: Locale) {
|
||||
const locale = locales.includes(localeRaw) ? localeRaw : Locale.EnglishUS;
|
||||
const locale = SUPPORTED_LOCALES.includes(localeRaw)
|
||||
? localeRaw
|
||||
: Locale.EnglishUS;
|
||||
const strings = translations[locale];
|
||||
|
||||
function translate(path: string, literals?: string[]): string {
|
||||
|
||||
Reference in new issue
Block a user