mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: filter localizations
This commit is contained in:
1 parent
49d0dbe86d
commit
96a9e5b938
6 files changed
+65
-22
No files matched your search
@@ -1,4 +1,4 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { Locale, SlashCommandBuilder } from 'discord.js';
|
||||||
import AllStatsOverview from '../components/AllStatsOverview';
|
import AllStatsOverview from '../components/AllStatsOverview';
|
||||||
import CommandWrapper from '../components/CommandWrapper';
|
import CommandWrapper from '../components/CommandWrapper';
|
||||||
import NoData, { NoDataType } from '../components/NoData';
|
import NoData, { NoDataType } from '../components/NoData';
|
||||||
@@ -33,13 +33,14 @@ async function render(
|
|||||||
{ region, id }: ResolvedPlayer,
|
{ region, id }: ResolvedPlayer,
|
||||||
{ start, end, name }: ResolvedPeriod,
|
{ start, end, name }: ResolvedPeriod,
|
||||||
filters: StatFilters,
|
filters: StatFilters,
|
||||||
|
locale: Locale,
|
||||||
) {
|
) {
|
||||||
const { nickname } = await getAccountInfo(region, id);
|
const { nickname } = await getAccountInfo(region, id);
|
||||||
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
||||||
const clanImage = clan ? emblemIdToURL(clan.emblem_set_id) : undefined;
|
const clanImage = clan ? emblemIdToURL(clan.emblem_set_id) : undefined;
|
||||||
const diffedTankStats = await getStatsInPeriod(region, id, start, end);
|
const diffedTankStats = await getStatsInPeriod(region, id, start, end);
|
||||||
const { stats, supplementary } = await filterStats(diffedTankStats, filters);
|
const { stats, supplementary } = await filterStats(diffedTankStats, filters);
|
||||||
const filterDescriptions = await filtersToDescription(filters);
|
const filterDescriptions = await filtersToDescription(filters, locale);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CommandWrapper>
|
<CommandWrapper>
|
||||||
@@ -82,7 +83,7 @@ export const statsCommand = new Promise<CommandRegistry>(async (resolve) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
render(player, period, filters),
|
render(player, period, filters, interaction.locale),
|
||||||
buttonRefresh(interaction, path),
|
buttonRefresh(interaction, path),
|
||||||
getBlitzStarsLinkButton(player.region, player.id),
|
getBlitzStarsLinkButton(player.region, player.id),
|
||||||
]);
|
]);
|
||||||
@@ -98,7 +99,7 @@ export const statsCommand = new Promise<CommandRegistry>(async (resolve) => {
|
|||||||
const period = resolvePeriodFromButton(player.region, interaction);
|
const period = resolvePeriodFromButton(player.region, interaction);
|
||||||
const filters = getFiltersFromButton(interaction);
|
const filters = getFiltersFromButton(interaction);
|
||||||
|
|
||||||
return await render(player, period, filters);
|
return await render(player, period, filters, interaction.locale);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -17,6 +17,7 @@ export const TREE_TYPES = ['researchable', 'premium', 'collector'] as const;
|
|||||||
export type TankType = (typeof TANK_TYPES)[number];
|
export type TankType = (typeof TANK_TYPES)[number];
|
||||||
export type TreeType = (typeof TREE_TYPES)[number];
|
export type TreeType = (typeof TREE_TYPES)[number];
|
||||||
|
|
||||||
|
// BIG TODO: REMOVE THIS AFTER LOCALIZATION
|
||||||
export const TREE_TYPE_NAMES: Record<TreeType, string> = {
|
export const TREE_TYPE_NAMES: Record<TreeType, string> = {
|
||||||
researchable: 'Tech tree',
|
researchable: 'Tech tree',
|
||||||
premium: 'Premium',
|
premium: 'Premium',
|
||||||
|
|||||||
@@ -1,24 +1,28 @@
|
|||||||
import { TREE_TYPE_NAMES } from '../../components/Tanks';
|
import { Locale } from 'discord.js';
|
||||||
import { encyclopediaInfo } from '../blitz/encyclopediaInfo';
|
import { translator } from '../localization/translator';
|
||||||
import { StatFilters } from '../statistics/filterStats';
|
import { StatFilters } from '../statistics/filterStats';
|
||||||
import { TIER_ROMAN_NUMERALS, Tier, tankDefinitions } from './tankDefinitions';
|
import { TIER_ROMAN_NUMERALS, Tier, tankDefinitions } from './tankDefinitions';
|
||||||
|
|
||||||
export async function filtersToDescription({
|
export async function filtersToDescription(
|
||||||
nation,
|
{ nation, tier, tankType, treeType, tank }: StatFilters,
|
||||||
tier,
|
locale: Locale,
|
||||||
tankType,
|
) {
|
||||||
treeType,
|
const { translate } = translator(locale);
|
||||||
tank,
|
|
||||||
}: StatFilters) {
|
|
||||||
const awaitedEncyclopediaInfo = await encyclopediaInfo;
|
|
||||||
const awaitedTankDefinitions = await tankDefinitions;
|
const awaitedTankDefinitions = await tankDefinitions;
|
||||||
const info: string[] = [];
|
const info: string[] = [];
|
||||||
|
|
||||||
|
// TODO: somehow localize tank names?
|
||||||
if (tank) return awaitedTankDefinitions[tank].name;
|
if (tank) return awaitedTankDefinitions[tank].name;
|
||||||
if (nation) info.push(awaitedEncyclopediaInfo.vehicle_nations[nation]);
|
if (nation) info.push(translate(`common.nations.${nation}`));
|
||||||
if (tier) info.push(`Tier ${TIER_ROMAN_NUMERALS[tier as Tier]}`);
|
if (tier) {
|
||||||
if (tankType) info.push(awaitedEncyclopediaInfo.vehicle_types[tankType]);
|
info.push(
|
||||||
if (treeType) info.push(TREE_TYPE_NAMES[treeType]);
|
translate('bot.common.filters.tier', [TIER_ROMAN_NUMERALS[tier as Tier]]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (tankType) info.push(translate(`common.tank_type_short.${tankType}`));
|
||||||
|
if (treeType) info.push(translate(`common.tree_type.${treeType}`));
|
||||||
|
|
||||||
return info.length === 0 ? 'No filters' : info.join(', ');
|
return info.length === 0
|
||||||
|
? translate('bot.common.filters.none')
|
||||||
|
: info.join(', ');
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,6 @@ import { PeriodSize, PeriodType } from './addPeriodSubCommands';
|
|||||||
|
|
||||||
export function getPeriodOptionName(period: PeriodSize, locale: Locale) {
|
export function getPeriodOptionName(period: PeriodSize, locale: Locale) {
|
||||||
const { translate } = translator(locale);
|
const { translate } = translator(locale);
|
||||||
|
|
||||||
if (period === 'career') return translate('bot.common.periods.career');
|
if (period === 'career') return translate('bot.common.periods.career');
|
||||||
if (period === 'today') return translate('bot.common.periods.today');
|
if (period === 'today') return translate('bot.common.periods.today');
|
||||||
return translate('bot.common.periods.days', [period]);
|
return translate('bot.common.periods.days', [period]);
|
||||||
@@ -25,6 +24,7 @@ export default function resolvePeriodFromCommand(
|
|||||||
interaction: ChatInputCommandInteraction<CacheType>,
|
interaction: ChatInputCommandInteraction<CacheType>,
|
||||||
forcedPeriod?: PeriodType,
|
forcedPeriod?: PeriodType,
|
||||||
) {
|
) {
|
||||||
|
const { translate } = translator(interaction.locale);
|
||||||
let name: string;
|
let name: string;
|
||||||
let start: number;
|
let start: number;
|
||||||
let end: number;
|
let end: number;
|
||||||
@@ -38,7 +38,10 @@ export default function resolvePeriodFromCommand(
|
|||||||
const startDaysAgoMin = Math.min(startOption, endOption);
|
const startDaysAgoMin = Math.min(startOption, endOption);
|
||||||
const endDaysAgoMax = Math.max(startOption, endOption);
|
const endDaysAgoMax = Math.max(startOption, endOption);
|
||||||
|
|
||||||
name = `${startDaysAgoMin} - ${endDaysAgoMax} days`;
|
name = translate('bot.common.periods.custom', [
|
||||||
|
`${startDaysAgoMin}`,
|
||||||
|
`${endDaysAgoMax}`,
|
||||||
|
]);
|
||||||
start = getTimeDaysAgo(region, endDaysAgoMax);
|
start = getTimeDaysAgo(region, endDaysAgoMax);
|
||||||
end = getTimeDaysAgo(region, startDaysAgoMin);
|
end = getTimeDaysAgo(region, startDaysAgoMin);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export function translator(localeRaw: Locale) {
|
|||||||
console.warn(
|
console.warn(
|
||||||
`Undefined translation at "${pathItem}" in "${path}" for locale "${locale}"; falling back to en-US`,
|
`Undefined translation at "${pathItem}" in "${path}" for locale "${locale}"; falling back to en-US`,
|
||||||
);
|
);
|
||||||
return translator(Locale.EnglishUS).translate(path);
|
return translator(Locale.EnglishUS).translate(path, literals);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,6 +51,8 @@ export function translator(localeRaw: Locale) {
|
|||||||
if (index !== 0) embeddedString += literals[index - 1];
|
if (index !== 0) embeddedString += literals[index - 1];
|
||||||
embeddedString += chunk;
|
embeddedString += chunk;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return embeddedString;
|
||||||
}
|
}
|
||||||
|
|
||||||
return resolvedString;
|
return resolvedString;
|
||||||
|
|||||||
@@ -1,4 +1,31 @@
|
|||||||
{
|
{
|
||||||
|
"common": {
|
||||||
|
"nations": {
|
||||||
|
"ussr": "USSR",
|
||||||
|
"germany": "Germany",
|
||||||
|
"usa": "USA",
|
||||||
|
"china": "China",
|
||||||
|
"uk": "Britain",
|
||||||
|
"france": "France",
|
||||||
|
"japan": "Japan",
|
||||||
|
"european": "Europe",
|
||||||
|
"other": "Hybrid"
|
||||||
|
},
|
||||||
|
|
||||||
|
"tank_type_short": {
|
||||||
|
"lightTank": "Light",
|
||||||
|
"mediumTank": "Medium",
|
||||||
|
"heavyTank": "Heavy",
|
||||||
|
"AT-SPG": "TD"
|
||||||
|
},
|
||||||
|
|
||||||
|
"tree_type": {
|
||||||
|
"researchable": "Tech tree",
|
||||||
|
"premium": "Premium",
|
||||||
|
"collector": "Collector"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
"bot": {
|
"bot": {
|
||||||
"common": {
|
"common": {
|
||||||
"wn8": {
|
"wn8": {
|
||||||
@@ -58,6 +85,11 @@
|
|||||||
"today": "Today",
|
"today": "Today",
|
||||||
"days": "%s days",
|
"days": "%s days",
|
||||||
"custom": "%s - %s days"
|
"custom": "%s - %s days"
|
||||||
|
},
|
||||||
|
|
||||||
|
"filters": {
|
||||||
|
"none": "No filters",
|
||||||
|
"tier": "Tier %s"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user