mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-16 09:40:30 +08:00
* feat: Implement plugin internationalization support - Added support for plugins to provide localized names, descriptions, and configuration texts through JSON files in the `.astrbot-plugin/i18n` directory. - Updated various components to utilize the new internationalization functions, including `ConfigItemRenderer`, `ExtensionCard`, `ItemCard`, `ObjectEditor`, `PluginSetSelector`, and `TemplateListEditor`. - Enhanced the `usePluginI18n` utility to resolve plugin-specific translations based on the current locale. - Modified the `common` store to include an `i18n` field for plugin metadata. - Updated documentation to include guidelines for plugin internationalization. - Added tests to ensure proper loading of localization files and integration with plugin metadata. * perf: code quality * feat: update config path handling for internationalization support
34 lines
876 B
JavaScript
34 lines
876 B
JavaScript
import { useModuleI18n } from '@/i18n/composables'
|
|
import { usePluginI18n } from '@/utils/pluginI18n'
|
|
|
|
export function useConfigTextResolver(props = {}) {
|
|
const { tm, getRaw } = useModuleI18n('features/config-metadata')
|
|
const { configText } = usePluginI18n()
|
|
|
|
const translateIfKey = (value) => {
|
|
if (!value || typeof value !== 'string') return value
|
|
return getRaw(value) ? tm(value) : value
|
|
}
|
|
|
|
const hasPluginI18n = () => {
|
|
return Boolean(
|
|
props.pluginName
|
|
&& props.pluginI18n
|
|
&& Object.keys(props.pluginI18n).length > 0,
|
|
)
|
|
}
|
|
|
|
const resolveConfigText = (path, attr, fallback) => {
|
|
const fallbackText = translateIfKey(fallback) || ''
|
|
if (!hasPluginI18n()) {
|
|
return fallbackText
|
|
}
|
|
return configText(props.pluginI18n, path, attr, fallbackText)
|
|
}
|
|
|
|
return {
|
|
translateIfKey,
|
|
resolveConfigText,
|
|
}
|
|
}
|