feat: rename

This commit is contained in:
TrèsAbhi committed 2024-03-07 21:38:38 -06:00
1 parent b71feca802
commit bf0246ec26
3 files changed
+17 -17

No files matched your search

+2 -2
View File
@@ -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 {
+11 -13
View File
@@ -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(
})) (table, { locale, translations }) => ({
.reduce( ...table,
(table, { locale, translations }) => ({ [locale]: translations,
...table, }),
[locale]: translations, {},
}), ) as Record<Locale, TranslationFragment>;
{},
) as Record<Locale, TranslationFragment>;
+4 -2
View File
@@ -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 {