crowdin

package
v0.0.0-...-8eba3d0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEventNotSupported error for event key not yet supported
	ErrEventNotSupported = merry.Sentinel("event not supported")
)
View Source
var ErrRequestFailed = merry.Sentinel("Request failed")

ErrRequestFailed error for failed requests

Functions

func HandleEvent

func HandleEvent(ctx context.Context, services services, event cloudevents.Event) (err error)

HandleEvent for events from PubSub (or other CloudEvent source)

Types

type Approval

type Approval struct {
	ID            int    `json:"id"`
	TranslationID int    `json:"translationId"`
	StringID      int    `json:"stringId"`
	LanguageID    string `json:"languageId"`
}

Approval model

type Client

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

Client for crowdin interactions

func New

func New(config Config, queries *sqlc.Queries, readonly bool) *Client

New client for requests

func (*Client) List

func (c *Client) List(ctx context.Context) ([]Translation, error)

List translations in crowdin

func (*Client) SaveTranslations

func (c *Client) SaveTranslations(objects []TranslationSource) error

SaveTranslations stores updated translations from the objects, if they are changed

func (*Client) Sync

func (c *Client) Sync(ctx context.Context) error

Sync synchronizes translations from Crowdin to Handler and Handler to Crowdin

type Config

type Config struct {
	Token      string
	ProjectIDs []int
}

Config for the client

type Directory

type Directory struct {
	ID    int    `json:"id,omitempty"`
	Name  string `json:"name"`
	Title string `json:"title,omitempty"`
}

Directory model

type File

type File struct {
	ID          int    `json:"id"`
	Name        string `json:"name"`
	Title       string `json:"title"`
	DirectoryID int    `json:"directoryId"`
}

File model

type Language

type Language struct {
	ID string `json:"id"`
}

Language model

type Object

type Object[T any] struct {
	Data T `json:"data"`
}

Object is the base of all responses in Crowdin

type Options

type Options struct {
	Project      Project
	DirectoryID  int
	Translations []Translation
}

Options are common options for every translation collection

type Pagination

type Pagination struct {
	Limit  int `json:"limit"`
	Offset int `json:"offset"`
}

Pagination contains simple pagination data

type Project

type Project struct {
	ID               int        `json:"id"`
	SourceLanguageId string     `json:"sourceLanguageId"`
	TargetLanguages  []Language `json:"targetLanguages"`
}

Project model

type Result

type Result[T any] struct {
	Object[T]
	Pagination Pagination
}

Result extends Object with Pagination data

type SimpleTranslation

type SimpleTranslation struct {
	ID       string
	ParentID string
	Values   map[string]string
	Language string
	Changed  bool
}

SimpleTranslation contains info about the translation object as stored in the database

type String

type String struct {
	ID         int    `json:"id"`
	FileID     int    `json:"fileId"`
	Text       string `json:"text"`
	Identifier string `json:"identifier"`
	Context    string `json:"context"`
	IsHidden   bool   `json:"isHidden"`
}

String model

type StringTranslation

type StringTranslation struct {
	StringID      int    `json:"stringId"`
	TranslationID int    `json:"translationId"`
	Text          string `json:"text"`
}

StringTranslation model

type Translation

type Translation struct {
	Collection string
	ID         string
	Field      string
	Value      string
	Language   string
}

Translation contains data for a specific translation key

func GetTranslationsFromZip

func GetTranslationsFromZip(zipFile string) ([]Translation, error)

GetTranslationsFromZip retrieves translations from a zip containing csv files

type TranslationHandler

type TranslationHandler[T any, TUpdate any] struct {
	Collection      string
	Fetch           func(ctx context.Context, language string) ([]T, error)
	ConvertToUpdate func(item SimpleTranslation) TUpdate
	Save            func(ctx context.Context, item TUpdate) error
	GetContext      func(identifier string) string
}

TranslationHandler handles translations

func NewTranslationHandler

func NewTranslationHandler[T any, TUpdate any](
	collection string,
	fetch func(ctx context.Context, language string) ([]T, error),
	convertToUpdate func(item SimpleTranslation) TUpdate,
	save func(ctx context.Context, item TUpdate) error,
	getContext func(identifier string) string) TranslationHandler[T, TUpdate]

NewTranslationHandler creates a handler from functions

type TranslationSource

type TranslationSource interface {
	GetCollection() string
	GetItemID() int
	GetLanguage() string
	// GetValues returns a field mapped dictionary with the translation source as value, identifier as key
	GetValues() map[string]string
}

TranslationSource is an object which contains fields that can be translated

Jump to

Keyboard shortcuts

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