mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 02:37:05 +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 CommandWrapper from '../components/CommandWrapper';
|
||||
import NoData, { NoDataType } from '../components/NoData';
|
||||
@@ -33,13 +33,14 @@ async function render(
|
||||
{ region, id }: ResolvedPlayer,
|
||||
{ start, end, name }: ResolvedPeriod,
|
||||
filters: StatFilters,
|
||||
locale: Locale,
|
||||
) {
|
||||
const { nickname } = await getAccountInfo(region, id);
|
||||
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
||||
const clanImage = clan ? emblemIdToURL(clan.emblem_set_id) : undefined;
|
||||
const diffedTankStats = await getStatsInPeriod(region, id, start, end);
|
||||
const { stats, supplementary } = await filterStats(diffedTankStats, filters);
|
||||
const filterDescriptions = await filtersToDescription(filters);
|
||||
const filterDescriptions = await filtersToDescription(filters, locale);
|
||||
|
||||
return (
|
||||
<CommandWrapper>
|
||||
@@ -82,7 +83,7 @@ export const statsCommand = new Promise<CommandRegistry>(async (resolve) => {
|
||||
});
|
||||
|
||||
return Promise.all([
|
||||
render(player, period, filters),
|
||||
render(player, period, filters, interaction.locale),
|
||||
buttonRefresh(interaction, path),
|
||||
getBlitzStarsLinkButton(player.region, player.id),
|
||||
]);
|
||||
@@ -98,7 +99,7 @@ export const statsCommand = new Promise<CommandRegistry>(async (resolve) => {
|
||||
const period = resolvePeriodFromButton(player.region, 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 TreeType = (typeof TREE_TYPES)[number];
|
||||
|
||||
// BIG TODO: REMOVE THIS AFTER LOCALIZATION
|
||||
export const TREE_TYPE_NAMES: Record<TreeType, string> = {
|
||||
researchable: 'Tech tree',
|
||||
premium: 'Premium',
|
||||
|
||||
@@ -1,24 +1,28 @@
|
||||
import { TREE_TYPE_NAMES } from '../../components/Tanks';
|
||||
import { encyclopediaInfo } from '../blitz/encyclopediaInfo';
|
||||
import { Locale } from 'discord.js';
|
||||
import { translator } from '../localization/translator';
|
||||
import { StatFilters } from '../statistics/filterStats';
|
||||
import { TIER_ROMAN_NUMERALS, Tier, tankDefinitions } from './tankDefinitions';
|
||||
|
||||
export async function filtersToDescription({
|
||||
nation,
|
||||
tier,
|
||||
tankType,
|
||||
treeType,
|
||||
tank,
|
||||
}: StatFilters) {
|
||||
const awaitedEncyclopediaInfo = await encyclopediaInfo;
|
||||
export async function filtersToDescription(
|
||||
{ nation, tier, tankType, treeType, tank }: StatFilters,
|
||||
locale: Locale,
|
||||
) {
|
||||
const { translate } = translator(locale);
|
||||
const awaitedTankDefinitions = await tankDefinitions;
|
||||
const info: string[] = [];
|
||||
|
||||
// TODO: somehow localize tank names?
|
||||
if (tank) return awaitedTankDefinitions[tank].name;
|
||||
if (nation) info.push(awaitedEncyclopediaInfo.vehicle_nations[nation]);
|
||||
if (tier) info.push(`Tier ${TIER_ROMAN_NUMERALS[tier as Tier]}`);
|
||||
if (tankType) info.push(awaitedEncyclopediaInfo.vehicle_types[tankType]);
|
||||
if (treeType) info.push(TREE_TYPE_NAMES[treeType]);
|
||||
if (nation) info.push(translate(`common.nations.${nation}`));
|
||||
if (tier) {
|
||||
info.push(
|
||||
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) {
|
||||
const { translate } = translator(locale);
|
||||
|
||||
if (period === 'career') return translate('bot.common.periods.career');
|
||||
if (period === 'today') return translate('bot.common.periods.today');
|
||||
return translate('bot.common.periods.days', [period]);
|
||||
@@ -25,6 +24,7 @@ export default function resolvePeriodFromCommand(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
forcedPeriod?: PeriodType,
|
||||
) {
|
||||
const { translate } = translator(interaction.locale);
|
||||
let name: string;
|
||||
let start: number;
|
||||
let end: number;
|
||||
@@ -38,7 +38,10 @@ export default function resolvePeriodFromCommand(
|
||||
const startDaysAgoMin = Math.min(startOption, endOption);
|
||||
const endDaysAgoMax = Math.max(startOption, endOption);
|
||||
|
||||
name = `${startDaysAgoMin} - ${endDaysAgoMax} days`;
|
||||
name = translate('bot.common.periods.custom', [
|
||||
`${startDaysAgoMin}`,
|
||||
`${endDaysAgoMax}`,
|
||||
]);
|
||||
start = getTimeDaysAgo(region, endDaysAgoMax);
|
||||
end = getTimeDaysAgo(region, startDaysAgoMin);
|
||||
} else {
|
||||
|
||||
@@ -27,7 +27,7 @@ export function translator(localeRaw: Locale) {
|
||||
console.warn(
|
||||
`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];
|
||||
embeddedString += chunk;
|
||||
});
|
||||
|
||||
return embeddedString;
|
||||
}
|
||||
|
||||
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": {
|
||||
"common": {
|
||||
"wn8": {
|
||||
@@ -58,6 +85,11 @@
|
||||
"today": "Today",
|
||||
"days": "%s days",
|
||||
"custom": "%s - %s days"
|
||||
},
|
||||
|
||||
"filters": {
|
||||
"none": "No filters",
|
||||
"tier": "Tier %s"
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in new issue
Block a user