goweblate

package module
v1.0.18 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2023 License: MIT Imports: 10 Imported by: 0

README

Golang API library for Weblate

Status

Partly working.

not stable api, breaking changes are frequent

Example usage

package main

import (
	"fmt"

	"github.com/sirupsen/logrus"

	"gitlab.com/gajdusek/goweblate"
)

func main() {
	// Set logging level, details: https://github.com/sirupsen/logrus
	// Trace level very long and contains also api responses
	// Debug is for developers
	// Info and above are user oriented
	logrus.SetLevel(logrus.DebugLevel)
	// url to your weblate api
	// secret key for weblate user
	// if you provide secret for user without admin rights, some features will not be available depending on provided permissions
	weblate := goweblate.New("https://weblate.example.com/api/", "SECRETKEY")
	if weblate == nil {
		panic("cannot connect to weblate")
	}
	fmt.Println("Projects", weblate.GetAllProjects())
	fmt.Println("Users", weblate.GetAllUsers())
	fmt.Println("Groups", weblate.GetAllGroups())
	for _, project := range weblate.GetAllProjects() {
		fmt.Println("Components", project.GetAllComponents())
	}
}

Public clases and methods

classDiagram
	Weblate "1" --> "*" User
	Weblate "1" --> "*" Group
	Weblate "1" --> "*" Project
	User "*" --> "*" Group
	Group "*" --> "*" User
	Project "1" --> "*" Component
	Component "1" --> "*" Translation

	class Weblate{
		GetAllUsers() []*User
		GetUser(userName string) *User

		GetAllGroups() []*Group
		GetGroup(groupID int) *Group 
		GetGroupByName(groupName string) *Group 
		GetGroupByURL(url string) (*Group, error)

		GetAllProjects() []*Project 
		GetProject(slug string) *Project
		CreateProject(name, slug, web, sourceLanguage string) (*Project, error)
		NewProject(name, slug, web, sourceLanguage string) (*Project, error)

	}
	
	class User{
		GetUserName() string
		GetFullName() string
		GetEmail() string
		GetEmail() string
		IsActive() bool
		SetActive(active bool) error
		IsSuperuser() bool
		SetSuperuser(superuser bool) error
		GetDateJoined() string 
		GetGroups() []*Group
		AddToGroup(group *Group)
	}
	
	class Group{
		GetName() string
		GetID() int
		GetUsers() []*User
		AddUser(user *User)
		AddUserByName(userName string)
	}
	
	class Project{
		GetName() string
		GetSlug() string
		GetWeb() string
		GetSourceLanguage() string

		GetAllComponents() []*Component
		GetComponent(slug string) *Component
		CreateComponent(branch, name, slug, fileFormat, filemask, repo, template, vcs, push string) (*Component, error)
		NewComponent(branch, name, slug, fileFormat, filemask, repo, template, vcs, push string) (*Component, error)
	}

	class Component{
		GetBranch() string
		GetCheckFlags() string
		IsEditTemplate() bool
		GetEnforcedChecks() string
		GetFileFormat() string
		GetFilemask() string
		GetID() int
		GetLicenseURL() string
		GetLicense() string
		GetName() string
		GetNewBase() string
		GetNewLang() string
		GetPush() string
		GetRepo() string
		GetRestricted() bool
		GetSlug() string
		GetTemplate() string
		GetVcs() string

		GetTranslation(languageCode string) *Translation
		CreateTranslation(languageCode string) (*Translation, error)
		NewTranslation(languageCode string) (*Translation, error)
	}
	class Translation{
		GetLanguageCode() string 
		GetFilename() string
		IsSource() bool
	}

Documentation

Index

Constants

View Source
const (
	Untranslated     = 0
	NeedsEditing     = 10
	WaitingForReview = 20
	Approved         = 30
	ReadOnly         = 100
)

Variables

This section is empty.

Functions

func StateDict

func StateDict() func(int) string

StateDict map integer state to the string representation of the state

0:   "not translated"
10:  "needs editing"
20:  "translated"
30:  "approved"
100: "read only"

Types

type Addon added in v1.0.7

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

Addon struct

type Component

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

Component struct

func (*Component) AllowTranslationPropagation added in v1.0.18

func (c *Component) AllowTranslationPropagation() string

AllowTranslationPropagation getter

func (*Component) Branch

func (c *Component) Branch() string

Branch getter

func (*Component) CheckFlags

func (c *Component) CheckFlags() string

CheckFlags getter

func (*Component) CreateTranslation

func (c *Component) CreateTranslation(languageCode string) (*Translation, error)

CreateTranslation create new component from local data

func (*Component) DeleteTranslation added in v1.0.0

func (c *Component) DeleteTranslation(languageCode string) error

func (*Component) EditTemplate

func (c *Component) EditTemplate() bool

EditTemplate getter

func (*Component) EnableSuggestions added in v1.0.18

func (c *Component) EnableSuggestions() string

EnableSuggestions getter

func (*Component) FileFormat

func (c *Component) FileFormat() string

FileFormat getter

func (*Component) Filemask

func (c *Component) Filemask() string

Filemask getter

func (*Component) GetAllTranslations

func (c *Component) GetAllTranslations() []*Translation

GetAllTranslations return all component translations

func (*Component) GetTranslation

func (c *Component) GetTranslation(languageCode string) *Translation

GetTranslation return translation from api

func (*Component) ID

func (c *Component) ID() int

ID getter

func (*Component) InstallAddon added in v1.0.7

func (c *Component) InstallAddon(name string) (*Addon, error)

Install addon for a component

func (*Component) LanguageRegex added in v1.0.0

func (c *Component) LanguageRegex() string

LanguageRegex getter

func (*Component) License

func (c *Component) License() string

License getter

func (*Component) LicenseURL

func (c *Component) LicenseURL() string

LicenseURL getter

func (*Component) Name

func (c *Component) Name() string

Name getter

func (*Component) NewBase

func (c *Component) NewBase() string

NewBase getter

func (*Component) NewTranslation

func (c *Component) NewTranslation(languageCode string) (*Translation, error)

NewTranslation get translation or create if not exists

func (*Component) Project

func (c *Component) Project() *Project

Project getter

func (*Component) Push

func (c *Component) Push() string

Push getter

func (*Component) PushBranch

func (c *Component) PushBranch() string

PushBranch getter

func (*Component) Repo

func (c *Component) Repo() string

Repo getter

func (*Component) Restricted

func (c *Component) Restricted() bool

Restricted getter

func (*Component) Slug

func (c *Component) Slug() string

Slug getter

func (*Component) SourceLanguage

func (c *Component) SourceLanguage() string

SourceLanguage getter

func (*Component) String

func (c *Component) String() string

func (*Component) Template

func (c *Component) Template() string

Template getter

func (*Component) Translations

func (c *Component) Translations() []*Translation

Translations getter

func (*Component) Vcs

func (c *Component) Vcs() string

Vcs getter

type Group

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

Group struct

func (*Group) AddUser

func (g *Group) AddUser(user *User)

AddUser AddUser

func (*Group) AddUserByName

func (g *Group) AddUserByName(userName string)

AddUserByName AddUser by userName

func (*Group) ID

func (g *Group) ID() int

ID getter

func (*Group) Name

func (g *Group) Name() string

Name getter

func (*Group) String

func (g *Group) String() string

func (*Group) Users

func (g *Group) Users() []*User

Users getter

func (*Group) Weblate

func (g *Group) Weblate() *Weblate

Weblate getter

type Project

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

Project struct

func (*Project) Components

func (p *Project) Components() []*Component

Components getter

func (*Project) CreateComponent

func (p *Project) CreateComponent(branch, name, slug, fileFormat, filemask, languageRegex, repo, template, vcs, push, pushBranch, sourceLanguage string, editTemplate bool, check_flags string, allow_translation_propagation string, enable_suggestions string) (*Component, error)

CreateComponent create new component from local data

func (*Project) GetAllComponents

func (p *Project) GetAllComponents() []*Component

GetAllComponents return all project components

func (*Project) GetComponent

func (p *Project) GetComponent(slug string) *Component

GetComponent return component from api

func (*Project) Name

func (p *Project) Name() string

Name getter

func (*Project) NewComponent

func (p *Project) NewComponent(branch, name, slug, fileFormat, filemask, languageRegex, repo, template, vcs, push, pushBranch, sourceLanguage string, editTemplate bool, check_flags string, allow_translation_propagation string, enable_suggestions string) (*Component, error)

NewComponent get component or create if not exists

func (*Project) Slug

func (p *Project) Slug() string

Slug getter

func (*Project) SourceReview added in v1.0.8

func (p *Project) SourceReview() bool

SourceReview getter

func (*Project) String

func (p *Project) String() string

func (*Project) TranslationReview added in v1.0.8

func (p *Project) TranslationReview() bool

TranslationReview getter

func (*Project) Web

func (p *Project) Web() string

Web getter

func (*Project) Weblate

func (p *Project) Weblate() *Weblate

Weblate getter

type Translation

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

Translation struct

func (*Translation) Component

func (t *Translation) Component() *Component

Component getter

func (*Translation) DeleteTranslation added in v1.0.0

func (t *Translation) DeleteTranslation() error

func (*Translation) Filename

func (t *Translation) Filename() string

Filename getter

func (*Translation) GetAllUnits

func (t *Translation) GetAllUnits() []*Unit

GetAllUnits return all units for translation

func (*Translation) GetUnit

func (t *Translation) GetUnit(id int) *Unit

GetUnit return translation from api

func (*Translation) IsSource

func (t *Translation) IsSource() bool

IsSource getter

func (*Translation) LanguageCode

func (t *Translation) LanguageCode() string

LanguageCode getter

func (*Translation) String

func (t *Translation) String() string

func (*Translation) Units

func (t *Translation) Units() []*Unit

Units getter

type Unit

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

Unit struct

func (*Unit) Context

func (u *Unit) Context() string

Context getter

func (*Unit) Explanation

func (u *Unit) Explanation() string

Explanation getter

func (*Unit) ExplanationUpdate added in v1.0.0

func (u *Unit) ExplanationUpdate(explanation string) *Unit

ExplanationUpdate unit

Explanation and flags can be set only on source language

func (*Unit) ExtraFlags added in v1.0.0

func (u *Unit) ExtraFlags() string

ExtraFlags getter

func (*Unit) ExtraFlagsUpdate added in v1.0.0

func (u *Unit) ExtraFlagsUpdate(flags string) *Unit

ExtraFlagsUpdate unit

Explanation and flags can be set only on source language

func (*Unit) Flags

func (u *Unit) Flags() string

Flags getter

func (*Unit) FullUpdate added in v1.0.0

func (u *Unit) FullUpdate(state int, target []string, explanation, extraFlags string) *Unit

FullUpdate unit, with limitations based on the previous state and user rights

0    ->   10: OK
10   ->   20: OK
20   ->   30: review workflow must be set up on the project
30   ->   100: can not be done -> read-only can be set only via read-only flag
explanation and flags can be set only on source language, use partial update on translation languages

func (*Unit) ID

func (u *Unit) ID() int

ID getter

func (*Unit) Note

func (u *Unit) Note() string

Note getter

func (*Unit) Source

func (u *Unit) Source() []string

Source getter

func (*Unit) State

func (u *Unit) State() int

State getter

func (*Unit) String

func (u *Unit) String() string

func (*Unit) Target

func (u *Unit) Target() []string

Target getter

func (*Unit) Translation

func (u *Unit) Translation() *Translation

Translation getter

func (*Unit) TranslationUpdate added in v1.0.0

func (u *Unit) TranslationUpdate(state int, target []string, extraFlags string) *Unit

TranslationUpdate unit, with limitations based on the previous state and user rights

0    ->   10: OK
10   ->   20: OK
20   ->   30: review workflow must be set up on the project
30   ->   100: can not be done -> read-only can be set only via read-only flag
explanation and flags can be set only on source language, use full update to set them (only on source language)

func (*Unit) Url

func (u *Unit) Url() string

Url getter

type User

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

User struct

func (*User) AddToGroup

func (u *User) AddToGroup(group *Group) error

AddToGroup Add user to group

func (*User) DateJoined

func (u *User) DateJoined() string

DateJoined getter

func (*User) Email

func (u *User) Email() string

Email getter

func (*User) FullName

func (u *User) FullName() string

FullName getter

func (*User) GetDateJoined

func (u *User) GetDateJoined() string

GetDateJoined GetDateJoined

func (*User) GetGroups

func (u *User) GetGroups() []*Group

GetGroups GetGroups

func (*User) Groups

func (u *User) Groups() []*Group

Groups getter

func (*User) IsActive

func (u *User) IsActive() bool

IsActive getter

func (*User) IsSuperuser

func (u *User) IsSuperuser() bool

IsSuperuser IsSuperuser

func (*User) SetActive

func (u *User) SetActive(active bool) error

SetActive Set if user is active

func (*User) SetSuperuser

func (u *User) SetSuperuser(superuser bool) error

SetSuperuser Set if user is Superuser

func (*User) String

func (u *User) String() string

func (*User) UserName

func (u *User) UserName() string

UserName getter

func (*User) Weblate

func (u *User) Weblate() *Weblate

Weblate getter

type Weblate

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

Weblate basic library struct holds complete state

func New

func New(weblateURL, apiKey string) *Weblate

New instantiate Weblate object, use one instance per one Weblate system

func (*Weblate) CreateProject

func (w *Weblate) CreateProject(name, slug, web string, sourceReview, translationReview bool) (*Project, error)

CreateProject create new project from local data

func (*Weblate) GetAllGroups

func (w *Weblate) GetAllGroups() []*Group

GetAllGroups GetAllGroups

func (*Weblate) GetAllProjects

func (w *Weblate) GetAllProjects() []*Project

GetAllProjects GetAllProjects

func (*Weblate) GetAllUnits

func (w *Weblate) GetAllUnits() []*Unit

GetAllUnits return all units

func (*Weblate) GetAllUsers

func (w *Weblate) GetAllUsers() []*User

GetAllUsers GetAllUsers

func (*Weblate) GetComponent

func (w *Weblate) GetComponent(targetURL string) *Component

GetComponent return component from api recursively, based on url e.g. https://weblate.com/api/translations/test/test/ Url format: {site:https://weblate.com/api = it is ignored}/{project:test = to solve the project}/{component:test = to solve the component}/

func (*Weblate) GetGroup

func (w *Weblate) GetGroup(groupID int) *Group

GetGroup get group by id

func (*Weblate) GetGroupByName

func (w *Weblate) GetGroupByName(groupName string) *Group

GetGroupByName get group by name

func (*Weblate) GetGroupByURL

func (w *Weblate) GetGroupByURL(url string) (*Group, error)

GetGroupByURL get group by url

func (*Weblate) GetProject

func (w *Weblate) GetProject(slug string) *Project

GetProject return project from api

func (*Weblate) GetTranslation

func (w *Weblate) GetTranslation(targetURL string) *Translation

GetTranslation return translation from api recursively, based on url e.g. https://weblate.com/api/translations/test/test/en_devel/

Url format example:

{site:https://weblate.com/api -> it is ignored}/{project:test}/{component:test}/{language code:en_devel}

func (*Weblate) GetUser

func (w *Weblate) GetUser(userName string) *User

GetUser get user by userName

func (*Weblate) NewProject

func (w *Weblate) NewProject(name, slug, web string, sourceReview, translationReview bool) (*Project, error)

NewProject get project or create if not exists

Jump to

Keyboard shortcuts

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