refactor: separate UI translations from CV data
- Created separate ui-en.json and ui-es.json files for UI strings - Removed 'ui' section from cv-en.json and cv-es.json - Added LoadUI() function to load UI translations separately - Updated handlers to load UI data independently from CV data - Updated template to use .UI instead of .CV.UI This separation follows proper concerns: - CV JSON files contain only professional CV content - UI JSON files contain only application interface strings - Each can be updated independently without affecting the other
This commit is contained in:
@@ -51,6 +51,13 @@ func (h *CVHandler) Home(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Load UI translations
|
||||
ui, err := models.LoadUI(lang)
|
||||
if err != nil {
|
||||
HandleError(w, r, DataLoadError(err, "UI"))
|
||||
return
|
||||
}
|
||||
|
||||
// Calculate duration for each experience
|
||||
for i := range cv.Experience {
|
||||
cv.Experience[i].Duration = calculateDuration(
|
||||
@@ -78,6 +85,7 @@ func (h *CVHandler) Home(w http.ResponseWriter, r *http.Request) {
|
||||
// Prepare template data
|
||||
data := map[string]interface{}{
|
||||
"CV": cv,
|
||||
"UI": ui,
|
||||
"Lang": lang,
|
||||
"SkillsLeft": skillsLeft,
|
||||
"SkillsRight": skillsRight,
|
||||
@@ -120,6 +128,13 @@ func (h *CVHandler) CVContent(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Load UI translations
|
||||
ui, err := models.LoadUI(lang)
|
||||
if err != nil {
|
||||
HandleError(w, r, DataLoadError(err, "UI"))
|
||||
return
|
||||
}
|
||||
|
||||
// Calculate duration for each experience
|
||||
for i := range cv.Experience {
|
||||
cv.Experience[i].Duration = calculateDuration(
|
||||
@@ -147,6 +162,7 @@ func (h *CVHandler) CVContent(w http.ResponseWriter, r *http.Request) {
|
||||
// Prepare template data
|
||||
data := map[string]interface{}{
|
||||
"CV": cv,
|
||||
"UI": ui,
|
||||
"Lang": lang,
|
||||
"SkillsLeft": skillsLeft,
|
||||
"SkillsRight": skillsRight,
|
||||
|
||||
+25
-1
@@ -22,7 +22,6 @@ type CV struct {
|
||||
Courses []Course `json:"courses"`
|
||||
References []Reference `json:"references"`
|
||||
Other Other `json:"other"`
|
||||
UI UI `json:"ui"`
|
||||
Meta Meta `json:"meta"`
|
||||
}
|
||||
|
||||
@@ -212,3 +211,28 @@ func LoadCV(lang string) (*CV, error) {
|
||||
|
||||
return &cv, nil
|
||||
}
|
||||
|
||||
// LoadUI loads UI translations from a JSON file for the specified language
|
||||
func LoadUI(lang string) (*UI, error) {
|
||||
// Validate language
|
||||
if lang != "en" && lang != "es" {
|
||||
return nil, fmt.Errorf("unsupported language: %s", lang)
|
||||
}
|
||||
|
||||
// Determine which JSON file to load
|
||||
filename := fmt.Sprintf("data/ui-%s.json", lang)
|
||||
|
||||
// Read the JSON file
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading file %s: %w", filename, err)
|
||||
}
|
||||
|
||||
// Parse JSON
|
||||
var ui UI
|
||||
if err := json.Unmarshal(data, &ui); err != nil {
|
||||
return nil, fmt.Errorf("error parsing JSON: %w", err)
|
||||
}
|
||||
|
||||
return &ui, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user