latest cdbcd03

localization.go RawHistoryFolder

1package render
2
3import (
4	"fmt"
5
6	"github.com/bnema/gordon/internal/server"
7	"gopkg.in/yaml.v3"
8)
9
10type Localizations map[string]map[string]map[string]interface{}
11
12// GetLocalization function returns the localization for the given language
13func GetLocalization(lang string, a *server.App) (map[string]interface{}, error) {
14	// 1. Check if the language is supported
15	supportedLanguages := []string{"en", "fr"} // Add more languages here
16	if !contains(supportedLanguages, lang) {
17		return nil, fmt.Errorf("language %s is not supported", lang)
18	}
19
20	fmt.Println("Language:", lang)
21
22	// 2. Get the localizations from the strings.yml file
23	localizations, err := getLocalizations(a)
24	if err != nil {
25		return nil, fmt.Errorf("failed to get localizations: %w", err)
26	}
27
28	// 3. Return the localizations for the given language
29	if localization, ok := localizations[lang]; ok {
30		result := make(map[string]interface{})
31		for k, v := range localization {
32			result[k] = v
33		}
34		return result, nil
35	}
36
37	return nil, fmt.Errorf("language %s is not available", lang)
38}
39
40// getLocalizations function returns the localizations from the strings.yml file
41func getLocalizations(a *server.App) (Localizations, error) {
42	var loc Localizations
43
44	err := yaml.Unmarshal(a.LocYML, &loc)
45	if err != nil {
46		return loc, fmt.Errorf("failed to unmarshal strings.yml: %w", err)
47	}
48
49	return loc, nil
50}
51
52// Helper function to check if a slice contains a string
53func contains(slice []string, str string) bool {
54	for _, v := range slice {
55		if v == str {
56			return true
57		}
58	}
59	return false
60}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 106

↑↓ moveenter openesc close