mirror of
https://github.com/danielmiessler/fabric.git
synced 2026-09-10 07:36:44 -04:00
- 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
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
// utils.go in template package for now
|
|
package template
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/user"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/danielmiessler/fabric/internal/i18n"
|
|
)
|
|
|
|
// ExpandPath expands the ~ to user's home directory and returns absolute path
|
|
// It also checks if the path exists
|
|
// Returns expanded absolute path or error if:
|
|
// - cannot determine user home directory
|
|
// - cannot convert to absolute path
|
|
// - path doesn't exist
|
|
func ExpandPath(path string) (string, error) {
|
|
// If path starts with ~
|
|
if strings.HasPrefix(path, "~/") {
|
|
usr, err := user.Current()
|
|
if err != nil {
|
|
return "", fmt.Errorf(i18n.T("template_utils_failed_get_home_dir"), err)
|
|
}
|
|
// Replace ~/ with actual home directory
|
|
path = filepath.Join(usr.HomeDir, path[2:])
|
|
}
|
|
|
|
// Convert to absolute path
|
|
absPath, err := filepath.Abs(path)
|
|
if err != nil {
|
|
return "", fmt.Errorf(i18n.T("template_utils_failed_get_absolute_path"), err)
|
|
}
|
|
|
|
// Check if path exists
|
|
if _, err := os.Stat(absPath); err != nil {
|
|
return "", fmt.Errorf(i18n.T("template_utils_path_not_exist"), err)
|
|
}
|
|
|
|
return absPath, nil
|
|
}
|