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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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).
Types ¶
This section is empty.