78 lines
2.0 KiB
Go
78 lines
2.0 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
// Run from the repository root: go run ./tools/translations [check|update].
|
|
// Extraction, merging and checks are shared with Cthulhu through
|
|
// screenreader-common's catalogtool; this file holds Fenrir's rules.
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"git.stormux.org/storm/screenreader-common/i18n/catalogtool"
|
|
"github.com/pelletier/go-toml/v2"
|
|
)
|
|
|
|
var config = catalogtool.Config{
|
|
Domain: "fenrir",
|
|
Project: "Fenrir",
|
|
Command: "go run ./tools/translations",
|
|
CatalogDir: "internal/i18n/locale",
|
|
SourceRoot: "internal",
|
|
Rules: catalogtool.Rules{
|
|
Calls: []string{"i18n.T", "i18n.Format", ".say", ".failed"},
|
|
Plural: []string{"i18n.N"},
|
|
Keys: []string{"Label", "Title"},
|
|
AllValueFiles: []string{"internal/command/descriptions.go", "internal/punctuation/emoticons.go"},
|
|
Tags: []string{"label", "quick"},
|
|
Vars: func(name string) bool {
|
|
return name == "MenuTitle" || strings.HasPrefix(name, "tutorial") && name != "tutorialMode"
|
|
},
|
|
},
|
|
Shared: catalogtool.Shared{Emoji: true, QuickSettings: true, InternalUI: true, VoiceProfiles: true},
|
|
DynamicFile: "tools/translations/dynamic.json",
|
|
Extra: punctuationNames,
|
|
}
|
|
|
|
func main() {
|
|
mode := ""
|
|
if len(os.Args) > 1 {
|
|
mode = os.Args[1]
|
|
}
|
|
if err := catalogtool.Run(config, mode, os.Stdout); err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
// punctuationNames adds symbol names from punctuation profiles marked for
|
|
// translation.
|
|
func punctuationNames(add func(id, ref string)) error {
|
|
profiles, err := filepath.Glob("config/punctuation/*.toml")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, path := range profiles {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var profile struct {
|
|
Translate bool
|
|
Symbols map[string]string
|
|
}
|
|
if err := toml.Unmarshal(data, &profile); err != nil {
|
|
return err
|
|
}
|
|
if profile.Translate {
|
|
for _, name := range profile.Symbols {
|
|
add(name, path)
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|