importexport

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2022 License: MIT Imports: 23 Imported by: 1

Documentation

Index

Examples

Constants

View Source
const (
	WarningLevelMinor               WarningLevel = "minor"
	WarningLevelMajor               WarningLevel = "major"
	WarningKindTranslationVariables WarningKind  = "translation-variable"
	WarningKindTranslationReference WarningKind  = "translation-reference"
)

Variables

View Source
var (
	FormatI18n       = Format{"i18n"}
	FormatRaw        = Format{"raw"}
	FormatTypescript = Format{"typescript"}
)
View Source
var (
	//go:embed templates
	Content embed.FS
)

Functions

func CleanKey

func CleanKey(s string) string

TODO: implement

func CreateInterpolationMapForOrganization

func CreateInterpolationMapForOrganization(db types.Storage, orgID string) (orgInterpolatorMap, error)

Creates an prioritized interpolationmap from an organization

func ExportByGoTemplate

func ExportByGoTemplate(templateName string, project types.ExtendedProject, i18n I18N, w io.Writer) error

func ExportExtendedProject added in v0.8.0

func ExportExtendedProject(l logger.AppLogger, ep types.ExtendedProject, locales []string, localeKey LocaleKeyEnum, format Format, localeFilter []string) (out interface{}, contentType string, err error)

ExportExtendedProject exports a project into a fileformat. If contentType is "", the format is a marshallable format, and can therefore be further marshalled into json, toml, yaml etc. On the other hand, some formats are not marshallable, and therefore are already ready to be returned to the user directly

for instance, typescript-format would return simply a []byte, with the contentType set to 'application/typescript'

func ExportExtendedProjectToI18Next added in v0.8.0

func ExportExtendedProjectToI18Next(l logger.AppLogger, ep types.ExtendedProject, locales []string, localeKey LocaleKeyEnum) (out map[string]interface{}, err error)

func FlattenExtendedCategories added in v0.8.1

func FlattenExtendedCategories(ec map[string]types.ExtendedCategory) (map[string]types.ExtendedCategory, map[string]types.ExtendedTranslation)

FlattenExtendedCategories returns a map of categories and translations by their keys

func FlattenStringMap added in v0.8.1

func FlattenStringMap(prefix string, src map[string]interface{}, dest map[string]string, allowOverwrites bool) error

Expects a map of arbitriry nestings of

Example
data := map[string]interface{}{
	"General": map[string]interface{}{
		"Create": "Create it",
		"Add":    "Add it",
	},
}

described := map[string]string{}

err := FlattenStringMap("", data, described, false)
sorted := utils.SortedMapKeys(described)
fmt.Println(err)
for _, k := range sorted {
	fmt.Println(k, described[k])
}
Output:

<nil>
General.Add Add it
General.Create Create it

func GetMapPaths

func GetMapPaths(input interface{}, paths ...string) (n [][]string, err error)

returns the map as a slice of paths where the last item in the path is the value. Fot translations, this is ok, since they are strings in any case.

func I18NNodeToI18Next

func I18NNodeToI18Next(in I18N) (map[string]interface{}, error)

func ImportI18NTranslation

func ImportI18NTranslation(

	locales types.Locales,
	localeHint *types.Locale,
	base types.Project,
	source types.CreatorSource,
	input map[string]interface{},
) (*Import, []Warning, error)

i18n-translations are either: a root-elemenent of type locale as key, or the category as key, or the translation as key. Every leaf-node must be of type string

func InferTitle

func InferTitle(s string) string

TODO: This should be a bit smarter.

func PrepareTemplates

func PrepareTemplates() *template.Template

func Prettier

func Prettier(s string) (string, error)

func SplitTranslationAndContext

func SplitTranslationAndContext(s, sep string) (string, string)

Types

type ChangeRequest added in v0.8.1

type ChangeRequest struct {
	Kind    string
	Payload interface{}
}

func DescribeProjectContent added in v0.8.1

func DescribeProjectContent(p types.ExtendedProject, src map[string]interface{}) ([]ChangeRequest, error)

type ExportI18NOptions

type ExportI18NOptions struct {
	// Must be a key of locale
	LocaleKey    LocaleKey
	LocaleFilter []string
}

type ExportOptions added in v0.8.0

type ExportOptions struct {
	InOrg                  string
	Project                string
	Locales                []string
	LocaleKey, Format, Tag string
	NoFlatten              bool
}

type Format added in v0.8.0

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

func (Format) From added in v0.8.0

func (f Format) From(s string) Format

Deprecated, only used for earlier enums

func (Format) Is added in v0.8.0

func (f Format) Is(comparitor Format) bool

func (Format) String added in v0.8.0

func (f Format) String() string

type I18N

type I18N struct {
	Value string          `json:"value,omitempty"`
	Nodes map[string]I18N `json:"nodes,omitempty"`
}

func ExportI18N

func ExportI18N(ex types.ExtendedProject, options ExportI18NOptions) (node I18N, err error)

func (*I18N) AddNode

func (j *I18N) AddNode(node I18N, path []string)

func (I18N) MergeAsIfRootIsLocale

func (in I18N) MergeAsIfRootIsLocale(localeGetter LocaleLookerUpper) (I18NWithLocales, error)

func (I18N) ToLocaleAwere

func (in I18N) ToLocaleAwere(locale string) I18NWithLocales

func (I18N) ToMap

func (in I18N) ToMap() interface{}

type I18NWithLocales

type I18NWithLocales struct {
	// The keys should be the ID of the locale
	Value map[string]string          `json:"value,omitempty"`
	Nodes map[string]I18NWithLocales `json:"nodes,omitempty"`
}

func (I18NWithLocales) Merge

type Import

type Import struct {
	Categories map[string]types.ExtendedCategory
}

The Import reprecents values that should be created in the database. The keys in each map is of no importance except for temporarily tracking these values

type LocaleKey

type LocaleKey string
const (
	LocaleKeyIETF LocaleKey = "ietf"
	LocaleKeyISO1 LocaleKey = "iso1"
	LocaleKeyISO2 LocaleKey = "iso2"
	LocaleKeyISO3 LocaleKey = "iso3"
)

type LocaleKeyEnum added in v0.8.0

type LocaleKeyEnum struct {
	Name string
}

func (LocaleKeyEnum) From added in v0.8.0

Deprecated, only used for earlier enums

func (LocaleKeyEnum) FromLocale added in v0.8.1

func (f LocaleKeyEnum) FromLocale(l types.Locale) string

func (LocaleKeyEnum) Is added in v0.8.0

func (f LocaleKeyEnum) Is(comparitor LocaleKeyEnum) bool

func (LocaleKeyEnum) Matches added in v0.8.1

func (f LocaleKeyEnum) Matches(s string) bool

func (LocaleKeyEnum) String added in v0.8.0

func (f LocaleKeyEnum) String() string

type LocaleLookerUpper

type LocaleLookerUpper interface {
	GetLocaleID(string) string
}

Aweseome name

type LocaleMatch added in v0.8.1

type LocaleMatch struct {
	types.Locale
	KeyType LocaleKeyEnum
}

func InferLocales added in v0.8.1

func InferLocales(localeLike string, locales map[string]types.Locale) []LocaleMatch

type Node

type Node struct{ Root, MidPath, Value string }

type Warning

type Warning struct {
	Message string       `json:"message"`
	Error   error        `json:"error,omitempty"`
	Details interface{}  `json:"details,omitempty"`
	Level   WarningLevel `json:"level"`
	Kind    WarningKind  `json:"kind"`
}

func InferVariables

func InferVariables(translationValue, category, translation string, interpolationMaps []map[string]interface{}) ([]Warning, map[string]interface{}, []string)

func InferVariablesFromMultiple

func InferVariablesFromMultiple(translationValues []string, category, translation string, interpolationMaps []map[string]interface{}) ([]Warning, map[string]interface{}, []string)

type WarningKind

type WarningKind string

type WarningLevel

type WarningLevel string

Jump to

Keyboard shortcuts

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