translations

package
v0.21.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package translations reads and writes language files for the sync command. Currently only the flat-JSON format used by every Norcube-internal project is implemented (`{"key": "value", ...}`).

All readers return map[string]string with values stripped of nothing — empty strings are preserved as empty translations. All writers emit a stable key order (sorted, case-sensitive) so diffs from sync are minimal and reviewable.

Index

Constants

View Source
const FlatJSONExt = ".json"

FlatJSONExt is the file extension we read/write for the flat-json format. Files are named "<language-code>.json" (e.g. "cs.json", "en-US.json") inside the namespace directory.

Variables

This section is empty.

Functions

func LangCodeFromFileName

func LangCodeFromFileName(name string) string

LangCodeFromFileName is the inverse of LangFileName. Returns the code stripped of its extension, or empty when the filename does not look like a flat-json translation file.

func LangFileName

func LangFileName(code string) string

LangFileName returns the canonical filename for the given language code inside a flat-json directory. The code is *not* normalized — what the backend gives us is what we write to disk, so the file names match the backend's view exactly.

func ListLangsInDir

func ListLangsInDir(dir string) (codes []string, paths []string, err error)

ListLangsInDir scans dir for files matching the flat-json convention and returns the discovered language codes (basename minus ".json"), sorted, plus the absolute paths in matching order.

Subdirectories and dotfiles are skipped. A missing dir is not an error — returns (nil, nil) so init/sync can treat "directory not yet created" the same as "no languages yet".

func ReadFlatJSON

func ReadFlatJSON(path string) (map[string]string, error)

ReadFlatJSON loads a flat-JSON translation file. Missing files return (nil, os.ErrNotExist) so callers can decide whether absence is an error or an empty-state.

The JSON must decode to map[string]string — nested objects, numbers, and arrays are rejected (these would silently corrupt a sync round trip otherwise).

func WriteFlatJSON

func WriteFlatJSON(path string, data map[string]string) error

WriteFlatJSON serializes data to path with sorted keys, two-space indentation, and a trailing newline. The write is atomic (temp + rename) so a crash mid-write can never leave a half-written file.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL