Documentation
¶
Overview ¶
Package stringtable provides DayZ stringtable.csv primitives and pofile integration.
Use ParseCSVFile and WriteCSVFile for CSV workflows, ParseLanguages and DefaultLanguages for language handling, and the pofile integration helpers to convert between CSV rows and gettext PO catalogs. Use UpdateBuildHeaders to optionally manage standard PO/POT build headers and content hash.
Index ¶
- Constants
- Variables
- func CatalogFromTableLanguage(table *Table, language string) (*pofile.Catalog, error)
- func CatalogSetFromTable(table *Table, languages []string) (map[string]*pofile.Catalog, error)
- func ContainsLanguage(list []string, language string) bool
- func ExtractLanguageName(path string) string
- func FormatCSV(table *Table) ([]byte, error)
- func FormatCSVWithOptions(table *Table, options *WriteOptions) ([]byte, error)
- func LanguageCode(language string) (string, bool)
- func LanguageNameFromCode(code string) (string, bool)
- func MergeCatalogLanguage(table *Table, language string, catalog *pofile.Catalog, options MergeOptions) error
- func MergeCatalogSet(table *Table, catalogs map[string]*pofile.Catalog, options MergeOptions) error
- func ParseCatalogDir(dir string) (map[string]*pofile.Catalog, error)
- func ParseLanguages(value string) []string
- func ReadCatalogSet(dir string) (map[string]*pofile.Catalog, error)
- func SelectLanguages(available, include, exclude []string) []string
- func TemplateCatalogFromTable(table *Table) (*pofile.Catalog, error)
- func UpdateBuildHeaders(catalog *pofile.Catalog, options HeaderOptions) bool
- func UpdateCatalogFromTable(table *Table, language string, existing *pofile.Catalog) (*pofile.Catalog, error)
- func WriteCSVFile(path string, table *Table) error
- func WriteCSVFileWithOptions(path string, table *Table, options *WriteOptions) error
- func WriteCatalogSet(dir string, catalogs map[string]*pofile.Catalog) error
- type HeaderOptions
- type MergeOptions
- type Row
- type Table
- type WriteOptions
Constants ¶
const ( // DefaultContentHashHeader is the default PO header for content hash. DefaultContentHashHeader = "X-Content-Hash" // DefaultSourceHashHeader is the default PO header for source hash. DefaultSourceHashHeader = "X-CSV-Hash" )
Variables ¶
var ( // ErrNilTable indicates nil table argument. ErrNilTable = errors.New("table is nil") // ErrNilCatalog indicates nil PO catalog argument. ErrNilCatalog = errors.New("catalog is nil") // ErrInvalidHeader indicates invalid CSV header shape. ErrInvalidHeader = errors.New("invalid stringtable csv header") // ErrDuplicateKey indicates duplicate key in CSV rows. ErrDuplicateKey = errors.New("duplicate key") )
var DefaultLanguages = []string{
"english",
"czech",
"german",
"russian",
"polish",
"hungarian",
"italian",
"spanish",
"french",
"chinese",
"japanese",
"portuguese",
"chinesesimp",
}
DefaultLanguages is the default DayZ language order.
Functions ¶
func CatalogFromTableLanguage ¶
CatalogFromTableLanguage builds language-specific PO catalog from CSV table.
func CatalogSetFromTable ¶
CatalogSetFromTable builds PO catalogs for requested languages.
func ContainsLanguage ¶
ContainsLanguage reports whether language exists in list.
func ExtractLanguageName ¶
ExtractLanguageName extracts language from "/path/lang.po" path.
func FormatCSVWithOptions ¶
func FormatCSVWithOptions(table *Table, options *WriteOptions) ([]byte, error)
FormatCSVWithOptions serializes table into stringtable CSV bytes.
func LanguageCode ¶ added in v0.1.1
LanguageCode returns language code for DayZ language name.
func LanguageNameFromCode ¶ added in v0.1.1
LanguageNameFromCode returns DayZ language name for language code.
func MergeCatalogLanguage ¶
func MergeCatalogLanguage( table *Table, language string, catalog *pofile.Catalog, options MergeOptions, ) error
MergeCatalogLanguage applies PO translations into one CSV table language.
func MergeCatalogSet ¶
func MergeCatalogSet( table *Table, catalogs map[string]*pofile.Catalog, options MergeOptions, ) error
MergeCatalogSet applies multiple PO catalogs into table language columns.
func ParseCatalogDir ¶
ParseCatalogDir loads all *.po files from directory by language filename.
func ParseLanguages ¶
ParseLanguages parses comma-separated language list.
func ReadCatalogSet ¶
ReadCatalogSet loads all *.po files from directory by language filename.
func SelectLanguages ¶
SelectLanguages returns deterministic language list using include/exclude.
func TemplateCatalogFromTable ¶
TemplateCatalogFromTable builds POT-like catalog from CSV table.
func UpdateBuildHeaders ¶
func UpdateBuildHeaders(catalog *pofile.Catalog, options HeaderOptions) bool
UpdateBuildHeaders updates optional build headers and returns whether effective catalog content changed (by content hash).
func UpdateCatalogFromTable ¶
func UpdateCatalogFromTable( table *Table, language string, existing *pofile.Catalog, ) (*pofile.Catalog, error)
UpdateCatalogFromTable updates catalog entries using table rows.
func WriteCSVFile ¶
WriteCSVFile writes table as stringtable CSV file.
func WriteCSVFileWithOptions ¶
func WriteCSVFileWithOptions(path string, table *Table, options *WriteOptions) error
WriteCSVFileWithOptions writes table as stringtable CSV file.
Types ¶
type HeaderOptions ¶
type HeaderOptions struct {
// ProjectVersion sets Project-Id-Version when non-empty.
ProjectVersion string `json:"project_version,omitempty" yaml:"project_version,omitempty"`
// Generator sets X-Generator when non-empty.
Generator string `json:"generator,omitempty" yaml:"generator,omitempty"`
// SourceHash writes source hash to source hash header when non-empty.
SourceHash string `json:"source_hash,omitempty" yaml:"source_hash,omitempty"`
// ContentHashHeader overrides content hash header name.
ContentHashHeader string `json:"content_hash_header,omitempty" yaml:"content_hash_header,omitempty"`
// SourceHashHeader overrides source hash header name.
SourceHashHeader string `json:"source_hash_header,omitempty" yaml:"source_hash_header,omitempty"`
// WriteStandardHeaders writes MIME and language headers when missing.
WriteStandardHeaders bool `json:"write_standard_headers,omitempty" yaml:"write_standard_headers,omitempty"`
// WriteHash writes content hash into hash header.
WriteHash bool `json:"write_hash,omitempty" yaml:"write_hash,omitempty"`
// WriteDateOnChange updates creation/revision date only when content changed.
WriteDateOnChange bool `json:"write_date_on_change,omitempty" yaml:"write_date_on_change,omitempty"`
// Template switches date header to POT-Creation-Date (otherwise PO-Revision-Date).
Template bool `json:"template,omitempty" yaml:"template,omitempty"`
}
HeaderOptions controls optional build/header updates for PO/POT catalogs.
type MergeOptions ¶
type MergeOptions struct {
// DisableOriginalOnEmpty disables original fallback when msgstr is empty.
DisableOriginalOnEmpty bool `json:"no_fallback_empty,omitempty" yaml:"no_fallback_empty,omitempty"`
// DisableOriginalOnNoTranslate disables original fallback for "notranslate".
DisableOriginalOnNoTranslate bool `json:"no_fallback_notranslate,omitempty" yaml:"no_fallback_notranslate,omitempty"`
// DisableOriginalOnMissing disables original fallback when entry is missing.
DisableOriginalOnMissing bool `json:"no_fallback_missing,omitempty" yaml:"no_fallback_missing,omitempty"`
}
MergeOptions controls PO-to-CSV translation merge behavior.
type Row ¶
type Row struct {
// Translations stores values per language column.
Translations map[string]string `json:"translations,omitempty" yaml:"translations,omitempty"`
// Key is value from "Language" column.
Key string `json:"key" yaml:"key"`
// Original is value from "original" column.
Original string `json:"original" yaml:"original"`
}
Row is one stringtable.csv entry.
type Table ¶
type Table struct {
// Languages defines translation column order after key+original columns.
Languages []string `json:"languages,omitempty" yaml:"languages,omitempty"`
// Rows stores key/original and per-language values.
Rows []Row `json:"rows,omitempty" yaml:"rows,omitempty"`
}
Table is a DayZ stringtable CSV model.
func ParseCSVFile ¶
ParseCSVFile parses stringtable CSV file from disk.
func ParseCSVReader ¶
ParseCSVReader parses stringtable CSV from reader.
func (*Table) EnsureLanguage ¶
EnsureLanguage appends missing language to column order.
type WriteOptions ¶
type WriteOptions struct {
// UseTableLanguagesOnly writes only table header languages as-is.
// When false, writer emits all default DayZ languages plus any extra
// languages found in table data.
UseTableLanguagesOnly bool `json:"use_table_languages_only,omitempty" yaml:"use_table_languages_only,omitempty"`
}
WriteOptions controls CSV serialization behavior.