|
| 1 | +import type { ArcscordFileData } from "../arcscord_file/type"; |
| 2 | + |
| 3 | +export function replaceI18nVariables(baseString: string, patterns: Record<string, string>): string { |
| 4 | + for (const [key, value] of Object.entries(patterns)) { |
| 5 | + if (key === "path") { |
| 6 | + const pathPatternMatch = baseString.match(/\{\{path(.)\}\}/); |
| 7 | + if (pathPatternMatch) { |
| 8 | + const separator = pathPatternMatch[1]; |
| 9 | + const pathAlias = value.replace(/\//g, separator); |
| 10 | + baseString = baseString.replace(new RegExp(`\\{\\{path${separator}\\}\\}`, "g"), pathAlias); |
| 11 | + } |
| 12 | + continue; |
| 13 | + } |
| 14 | + baseString = baseString.replaceAll(`{{${key}}}`, value); |
| 15 | + } |
| 16 | + return baseString; |
| 17 | +} |
| 18 | + |
| 19 | +export function getCommandNameI18nPath(options: ArcscordFileData, variables: { |
| 20 | + name: string; |
| 21 | + path: string; |
| 22 | +}): string { |
| 23 | + return replaceI18nVariables( |
| 24 | + options.i18n?.defaultCommandNamePattern ?? "commands.{{path.}}.{{name}}.name", |
| 25 | + variables, |
| 26 | + ); |
| 27 | +}; |
| 28 | + |
| 29 | +export function getCommandDescriptionI18nPath(options: ArcscordFileData, variables: { |
| 30 | + name: string; |
| 31 | + path: string; |
| 32 | +}): string { |
| 33 | + return replaceI18nVariables( |
| 34 | + options.i18n?.defaultCommandDescriptionPattern ?? "commands.{{path.}}.{{name}}.description", |
| 35 | + variables, |
| 36 | + ); |
| 37 | +}; |
| 38 | + |
| 39 | +export function getSubCommandNameI18nPath(options: ArcscordFileData, variables: { |
| 40 | + name: string; |
| 41 | + path: string; |
| 42 | + subName: string; |
| 43 | +}): string { |
| 44 | + return replaceI18nVariables( |
| 45 | + options.i18n?.defaultSubCommandNamePattern ?? "commands.{{path.}}.{{name}}.{{subName}}.name", |
| 46 | + variables, |
| 47 | + ); |
| 48 | +} |
| 49 | + |
| 50 | +export function getSubCommandDescriptionI18nPath(options: ArcscordFileData, variables: { |
| 51 | + name: string; |
| 52 | + path: string; |
| 53 | + subName: string; |
| 54 | +}): string { |
| 55 | + return replaceI18nVariables( |
| 56 | + options.i18n?.defaultSubCommandDescriptionPattern ?? "commands.{{path.}}.{{name}}.{{subName}}.description", |
| 57 | + variables, |
| 58 | + ); |
| 59 | +} |
| 60 | + |
| 61 | +export function getSubCommandWithGroupNameI18nPath(options: ArcscordFileData, variables: { |
| 62 | + name: string; |
| 63 | + path: string; |
| 64 | + subName: string; |
| 65 | + groupName: string; |
| 66 | +}): string { |
| 67 | + return replaceI18nVariables( |
| 68 | + options.i18n?.defaultSubCommandWithGroupNamePattern ?? "commands.{{path.}}.{{name}}.{{groupName}}.{{subName}}.name", |
| 69 | + variables, |
| 70 | + ); |
| 71 | +} |
| 72 | + |
| 73 | +export function getSubCommandWithGroupDescriptionI18nPath(options: ArcscordFileData, variables: { |
| 74 | + name: string; |
| 75 | + path: string; |
| 76 | + subName: string; |
| 77 | + groupName: string; |
| 78 | +}): string { |
| 79 | + return replaceI18nVariables( |
| 80 | + options.i18n?.defaultSubCommandWithGroupDescriptionPattern ?? "commands.{{path.}}.{{name}}.{{groupName}}.{{subName}}.description", |
| 81 | + variables, |
| 82 | + ); |
| 83 | +} |
| 84 | + |
| 85 | +export function getSubCommandGroupNameI18nPath(options: ArcscordFileData, variables: { |
| 86 | + name: string; |
| 87 | + path: string; |
| 88 | + groupName: string; |
| 89 | +}): string { |
| 90 | + return replaceI18nVariables( |
| 91 | + options.i18n?.defaultSubCommandGroupNamePattern ?? "commands.{{path.}}.{{name}}.{{groupName}}.name", |
| 92 | + variables, |
| 93 | + ); |
| 94 | +} |
| 95 | + |
| 96 | +export function getSubCommandGroupDescriptionI18nPath(options: ArcscordFileData, variables: { |
| 97 | + name: string; |
| 98 | + path: string; |
| 99 | + groupName: string; |
| 100 | +}): string { |
| 101 | + return replaceI18nVariables( |
| 102 | + options.i18n?.defaultSubCommandGroupDescriptionPattern ?? "commands.{{path.}}.{{name}}.{{groupName}}.description", |
| 103 | + variables, |
| 104 | + ); |
| 105 | +} |
0 commit comments