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 ¶
- func GetRootPath() (string, error)
- type Config
- func (cfg *Config) AddResource(resource Resource)
- func (cfg *Config) FindHost(hostname string) *Host
- func (cfg *Config) FindResource(id string) *Resource
- func (cfg *Config) FindResourcesByProject(projectSlug string) []*Resource
- func (cfg *Config) GetActiveHost() *Host
- func (cfg *Config) RemoveResource(r Resource)
- func (cfg *Config) Save() error
- type Host
- type LocalConfig
- type Resource
- type RootConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetRootPath ¶
Types ¶
type Config ¶
type Config struct {
Root *RootConfig
Local *LocalConfig
}
func Load ¶
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 (*Config) AddResource ¶
AddResource Adds a resource to the Local.Resources list
func (*Config) FindResource ¶
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
FindResourcesByProject Returns a list of all the resources matching the given projectSlug
func (*Config) GetActiveHost ¶
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
RemoveResource Removes a resource from the Local Resources by creating a new list and replacing the existing list
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
}