Files
Fabric/internal/tools/custom_patterns/custom_patterns.go
Kayvan Sylvan e9b1b88d86 feat: replace hardcoded error strings with i18n translation keys
- Replace hardcoded error messages with `i18n.T()` calls across Go source files
- Add ~80 new translation keys to all locale files (en, de, es, fa, fr, it, ja, pt-BR, pt-PT, zh)
- Internationalize error strings in chat, attachment, storage, and template packages
- Internationalize error strings in plugin registry, server, and utility modules
- Internationalize githelper, notifications, patterns, and sessions modules
- Add i18n support for DigitalOcean, Gemini, and OpenAI-compatible providers
- Sort existing locale keys alphabetically in JSON files
- chore: incoming 2019 changelog entry
2026-02-21 13:28:52 -08:00

68 lines
1.9 KiB
Go

package custom_patterns
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/danielmiessler/fabric/internal/i18n"
"github.com/danielmiessler/fabric/internal/plugins"
)
func NewCustomPatterns() (ret *CustomPatterns) {
label := "Custom Patterns"
ret = &CustomPatterns{}
ret.PluginBase = &plugins.PluginBase{
Name: i18n.T("custom_patterns_label"),
SetupDescription: i18n.T("custom_patterns_setup_description") + " " + i18n.T("optional_marker"),
EnvNamePrefix: plugins.BuildEnvVariablePrefix(label),
ConfigureCustom: ret.configure,
}
ret.CustomPatternsDir = ret.AddSetupQuestionWithEnvName("Directory", false,
i18n.T("custom_patterns_directory_question"))
return
}
type CustomPatterns struct {
*plugins.PluginBase
CustomPatternsDir *plugins.SetupQuestion
}
func (o *CustomPatterns) configure() error {
if o.CustomPatternsDir.Value != "" {
// Expand home directory if needed
if strings.HasPrefix(o.CustomPatternsDir.Value, "~/") {
if homeDir, err := os.UserHomeDir(); err == nil {
o.CustomPatternsDir.Value = filepath.Join(homeDir, o.CustomPatternsDir.Value[2:])
}
}
// Convert to absolute path
if absPath, err := filepath.Abs(o.CustomPatternsDir.Value); err == nil {
o.CustomPatternsDir.Value = absPath
}
// Check if directory exists, create only if it doesn't
if _, err := os.Stat(o.CustomPatternsDir.Value); os.IsNotExist(err) {
if err := os.MkdirAll(o.CustomPatternsDir.Value, 0755); err != nil {
// Log the error but don't clear the value - let it persist in env file
fmt.Printf(i18n.T("custom_patterns_warning_create_directory"), o.CustomPatternsDir.Value, err)
}
}
}
return nil
}
// IsConfigured returns true if a custom patterns directory has been set
func (o *CustomPatterns) IsConfigured() bool {
// First configure to load values from environment variables
o.Configure()
// Check if the plugin has been configured with a directory
return o.CustomPatternsDir.Value != ""
}