0.1.22 4db9699

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	// 2. Get the localizations from the strings.yml file
21	localizations, err := getLocalizations(a)
22	if err != nil {
23		return nil, fmt.Errorf("failed to get localizations: %w", err)
24	}
25
26	// 3. Return the localizations for the given language
27	if localization, ok := localizations[lang]; ok {
28		result := make(map[string]interface{})
29		for k, v := range localization {
30			result[k] = v
31		}
32		return result, nil
33	}
34
35	return nil, fmt.Errorf("language %s is not available", lang)
36}
37
38// getLocalizations function returns the localizations from the strings.yml file
39func getLocalizations(a *server.App) (Localizations, error) {
40	var loc Localizations
41
42	err := yaml.Unmarshal(a.LocYML, &loc)
43	if err != nil {
44		return loc, fmt.Errorf("failed to unmarshal strings.yml: %w", err)
45	}
46
47	return loc, nil
48}
49
50// Helper function to check if a slice contains a string
51func contains(slice []string, str string) bool {
52	for _, v := range slice {
53		if v == str {
54			return true
55		}
56	}
57	return false
58}

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 7

Tags 106

↑↓ moveenter openesc close