goloc

package
v0.9.10 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultEmptyLocRegexp, _ = regexp.Compile("^$")

Functions

func ParseLocalizations

func ParseLocalizations(
	rawData [][]RawCell,
	platform Platform,
	formats Formats,
	tabName string,
	keyColumn string,
	errorIfMissing bool,
	emptyLocalizationRegexp *regexp.Regexp,
) (loc Localizations, formatArgs LocalizationFormatArgs, warnings []error, error error)

ParseLocalizations parses formats given the raw table data and returns, if successful, mappings for each localized string in different languages.

func Run

func Run(
	source Source,
	platform Platform,
	resDir string,
	keyColumn string,
	formatNameColumn string,
	defaultLocalization string,
	defaultLocalizationPath string,
	stopOnMissing bool,
	reportMissingLocalizations bool,
	defFormatName string,
	emptyLocalizationMatch *regexp.Regexp,
) error

Run launches the actual process of fetching, parsing and writing the localization files.

func WriteLocalizations

func WriteLocalizations(
	platform Platform,
	dir ResDir,
	localizations Localizations,
	formatArgs LocalizationFormatArgs,
	defLocLang Lang,
	defLocPath string,
) (error error)

WriteLocalizations writes localization files into platform-defined directories.

Types

type Cell

type Cell struct {
	// contains filtered or unexported fields
}

Cell represents a table cell.

func NewCell

func NewCell(tab string, row uint, column uint) *Cell

NewCell creates and returns a new Cell instance given tab name, row and column indices.

func (Cell) String

func (c Cell) String() string

type FallbackStringWriter

type FallbackStringWriter interface {
	FallbackString(args *LocalizedStringArgs) string
}

type FooterArgs

type FooterArgs struct {
	Lang Lang
}

FooterArgs encapsulates arguments to a function that returns a localization file footer for a given platform.

type FormatKey

type FormatKey = string

FormatKey represents a name of the format.

func FormatArgs

func FormatArgs(str string) (args []FormatKey)

type FormatStringArgs

type FormatStringArgs struct {
	Index  int
	Format string
}

FormatStringArgs encapsulates arguments to a function that returns the actual format specification for a given platform.

type Formats

type Formats = map[FormatKey]string

Formats represents a mapping between format names and platform-specific format descriptions.

func ParseFormats

func ParseFormats(
	rawData [][]RawCell,
	platform Platform,
	formatsTabName string,
	formatColumnTitle string,
	defFormatName string,
) (Formats, error)

ParseFormats parses formats given the raw table data and returns, if successful, mappings to the actual platform format for each format name.

type HeaderArgs

type HeaderArgs struct {
	Lang Lang
	Time time.Time
}

HeaderArgs encapsulates arguments to a function that returns a localization file header for a given platform.

type Key

type Key = string

Key represents a localized string key.

type Lang

type Lang = string

Lang represents a language code.

type LocalizationFormatArgs

type LocalizationFormatArgs map[Key][]FormatKey

LocalizationFormatArgs represents a mapping between a localized string key and its format arguments.

type Localizations

type Localizations map[Key]map[Lang]string

Localizations represents a mapping between a localized string key and it's values for different languages.

func (Localizations) Count

func (loc Localizations) Count() map[Lang]int

func (Localizations) Locales

func (loc Localizations) Locales() (locales []string)

func (Localizations) SortedKeys

func (loc Localizations) SortedKeys() (sortedKeys []Key)

type LocalizedStringArgs

type LocalizedStringArgs struct {
	Index      int
	IsLast     bool
	Lang       Lang
	Key        Key
	Value      string
	FormatArgs []string
}

LocalizedStringArgs encapsulates arguments to a function that returns the actual localized string for a given platform.

type Platform

type Platform interface {
	// Returns platform names that can be used to identify it in the sheet.
	Names() []string

	// Returns a full relative path to localization file for a given language.
	LocalizationFilePath(lang Lang, resDir ResDir) string

	// Returns header text. Returned string can be empty. Newlines must be included here if localization format requires them.
	Header(args *HeaderArgs) string

	// Returns actual localization binding for a given language. Newlines must be included here if localization format requires them.
	LocalizedString(args *LocalizedStringArgs) string

	// Returns footer text. Can be an empty string. Newlines must be included here if localization format requires them.
	Footer(args *FooterArgs) string

	// Returns nil if format is valid and non-nil error otherwise
	ValidateFormat(format string) error

	// Returns an actual format string taking the argument position into consideration.
	// Example 1: format strings on Android are positional (with position starting from 1). In this case invocation of IndexedFormatString(0, "s") would return "%1$s".
	// Example 2: format strings on iOS aren't positional. In this case invocation of IndexedFormatString(0, "@") would return "%@".
	FormatString(args *FormatStringArgs) string

	// Returns replacement characters for any special character that needs to be guarded in the platform resources.
	ReplacementChars() map[string]string
}

Platform represents an object responsible for specifying a format of the resulting localization file.

type PostprocessArgs

type PostprocessArgs struct {
	Localizations       Localizations
	Formats             Formats
	FormatArgs          LocalizationFormatArgs
	ResDir              ResDir
	DefaultLocalization Lang
}

PostprocessArgs encapsulates arguments for a postprocess function

type Postprocessor

type Postprocessor interface {
	Postprocess(args PostprocessArgs) error
}

type PreprocessArgs

type PreprocessArgs struct {
	Localizations       Localizations
	Formats             Formats
	FormatArgs          LocalizationFormatArgs
	ResDir              ResDir
	DefaultLocalization Lang
}

PreprocessArgs encapsulates arguments for a preprocess function

type Preprocessor

type Preprocessor interface {
	Preprocess(args PreprocessArgs) error
}

type RawCell

type RawCell = string

type ResDir

type ResDir = string

ResDir represents a resources directory path.

type Source

type Source interface {
	FormatsDocumentName() string
	LocalizationsDocumentName() string

	Formats() ([][]RawCell, error)
	Localizations() ([][]RawCell, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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