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