config

package
v1.6.11 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package config Slightly object-oriented tx configuration package.

Usage:

import "github.com/transifex/cli/internal/txlib/config"

cfg, err := config.Load()  // Loads based on current directory
if err != nil { ... }

// Lets add a resource
cfg.AddResource(config.Resource{
    OrganizationSlug: "my_org",
    ProjectSlug: "my_project",
    ResourceSlug: "my_resource",
    FileFilter: "locale/<lang>.po",
    SourceFile: "locale/en.po",
    SourceLanguage: "en",
    Type: "PO",
})

cfg.Save()  // Saves changes to disk

resource := cfg.FindResource("my_org.my_project")

file, err := os.Open(resource.SourceFile)
if err != nil { ... }
defer file.Close()

resource.LanguageMappings["en_US"] = "en-us"
cfg.Save()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRootPath

func GetRootPath() (string, error)

Types

type Config

type Config struct {
	Root  *RootConfig
	Local *LocalConfig
}

func Load

func Load() (Config, error)

Load Transifex configuration from the usual paths:

- ~/.transifexrc for the root configuration

- ./.tx/config for the local configuration

If any of these files are missing, the relevant attribute will be set to nil.

TODO: Load local configuration from any parent folder's `.tx` folder.

func LoadFromPaths

func LoadFromPaths(rootPath, localPath string) (Config, error)

func (*Config) AddResource

func (cfg *Config) AddResource(resource Resource)

AddResource Adds a resource to the Local.Resources list

func (*Config) FindHost

func (cfg *Config) FindHost(hostname string) *Host

FindHost Return a Host reference that matches the argument.

func (*Config) FindResource

func (cfg *Config) FindResource(id string) *Resource

FindResource Return a Resource reference that matches the argument. The format of the argument is "<project_slug>.<resource_slug>"

func (*Config) FindResourcesByProject added in v0.0.2

func (cfg *Config) FindResourcesByProject(projectSlug string) []*Resource

FindResourcesByProject Returns a list of all the resources matching the given projectSlug

func (*Config) GetActiveHost

func (cfg *Config) GetActiveHost() *Host

GetActiveHost Return the URL that will be used based on the configuration.

The local configuration has a 'host' field in its 'main' section. That host points to a section in the root configuration. We return the rest_hostname of that section. The fallback value is `https://rest.api.transifex.com`

func (*Config) RemoveResource added in v0.0.2

func (cfg *Config) RemoveResource(r Resource)

RemoveResource Removes a resource from the Local Resources by creating a new list and replacing the existing list

func (*Config) Save

func (cfg *Config) Save() error

Save Save changes to disk

type Host

type Host struct {
	Name         string
	ApiHostname  string
	Hostname     string
	Username     string
	Password     string
	RestHostname string
	Token        string
}

type LocalConfig

type LocalConfig struct {
	Host             string
	LanguageMappings map[string]string
	Resources        []Resource
	Path             string
}

func (LocalConfig) Save

func (localCfg LocalConfig) Save() error

type Resource

type Resource struct {
	OrganizationSlug     string
	ProjectSlug          string
	ResourceSlug         string
	FileFilter           string
	SourceFile           string
	SourceLanguage       string
	Type                 string
	LanguageMappings     map[string]string
	Overrides            map[string]string
	MinimumPercentage    int
	ResourceName         string
	ReplaceEditedStrings bool
	KeepTranslations     bool
}

func (*Resource) GetAPv3Id added in v1.1.0

func (localCfg *Resource) GetAPv3Id() string

func (*Resource) GetName added in v1.4.0

func (resource *Resource) GetName() string

func (*Resource) Name

func (localCfg *Resource) Name() string

Name Return the name of a resource as it appears in the configuration file. The format is the same as the ID of the resource in APIv3

type RootConfig

type RootConfig struct {
	Hosts []Host
	Path  string
}

Jump to

Keyboard shortcuts

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