smartling

package module
v0.0.0-...-be95181 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2025 License: MIT Imports: 7 Imported by: 0

README

Smartling SDK in Golang

Examples

Examples are located in the example_*_test.go files.

Examples suited for use with real user accounts, so to run examples you need at least obtain your User ID and Token Secret.

Then, obtained User ID, Token Secret and other parameters should be populated in the example_credentials_test.go file.

To run all examples, just run go test.

To run specific example it must be specified like go test -run Projects_List (will run example from examples_projects_list_test.go).

Documentation

Overview

Package smartling is a client implementation of the Smartling Translation API v2 as documented at https://help.smartling.com/v1.0/reference

Index

Constants

View Source
const (
	// RetrieveDefault specifies that Smartling will decide what type of
	// translation will be returned.
	RetrieveDefault RetrievalType = ""

	// RetrievePending specifies that Smartling returns any translations
	// (including non-published translations)
	RetrievePending = "pending"

	// RetrievePublished specifies that Smartling returns only
	// published/pre-published translations.
	RetrievePublished = "published"

	// RetrievePseudo specifies that Smartling returns a modified version of
	// the original text with certain characters transformed and the text
	// expanded.
	RetrievePseudo = "pseudo"

	// RetrieveChromeInstrumented specifies that Smartling returns a modified
	// version of the original file with strings wrapped in a specific set of
	// Unicode symbols that can later be recognized and matched by the Chrome
	// Context Capture Extension
	RetrieveChromeInstrumented = "contextMatchingInstrumented"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIClient

type APIClient interface {
	Authenticate() error
	DeleteFile(projectID string, uri string) error
	DownloadFile(projectID string, uri string) (io.Reader, error)
	DownloadTranslation(projectID string, localeID string, request FileDownloadRequest) (io.Reader, error)
	GetFileStatus(projectID string, fileURI string) (*smfile.FileStatus, error)
	GetProjectDetails(projectID string) (*ProjectDetails, error)
	Import(projectID string, localeID string, request smfile.ImportRequest) (*FileImportResult, error)
	ListAllFiles(projectID string, request smfile.FilesListRequest) ([]smfile.File, error)
	ListProjects(accountID string, request smfile.ProjectsListRequest) (*ProjectsList, error)
	RenameFile(projectID string, oldURI string, newURI string) error
}

type FileDownloadRequest

type FileDownloadRequest struct {
	smfile.FileURIRequest

	Type            RetrievalType
	IncludeOriginal bool
}

FileDownloadRequest represents optional parameters for file download operation.

func (FileDownloadRequest) GetQuery

func (request FileDownloadRequest) GetQuery() url.Values

GetQuery returns URL values representation of download file query params.

type FileImportResult

type FileImportResult struct {
	WordCount               int
	StringCount             int
	TranslationImportErrors []string
}

type FilesList

type FilesList struct {
	// TotalCount is a total files count.
	TotalCount int

	// Items contains all files matched by request.
	Items []smfile.File
}

FilesList represents file list reply from Smartling APIa.

type HttpAPIClient

type HttpAPIClient struct {
	Client *smclient.Client
}

HttpAPIClient represents http Smartling API client.

func NewHttpAPIClient

func NewHttpAPIClient(userID, tokenSecret string) *HttpAPIClient

NewHttpAPIClient returns new http Smartling API client with specified authentication data.

func (*HttpAPIClient) Authenticate

func (c *HttpAPIClient) Authenticate() error

Authenticate checks that access and refresh tokens are valid and refreshes them if needed.

func (*HttpAPIClient) DeleteFile

func (c *HttpAPIClient) DeleteFile(
	projectID string,
	uri string,
) error

DeleteFile removes specified files from project.

func (*HttpAPIClient) DownloadFile

func (c *HttpAPIClient) DownloadFile(
	projectID string,
	uri string,
) (io.Reader, error)

DownloadFile downloads original file from project.

func (*HttpAPIClient) DownloadTranslation

func (c *HttpAPIClient) DownloadTranslation(
	projectID string,
	localeID string,
	request FileDownloadRequest,
) (io.Reader, error)

DownloadTranslation downloads specified translated file for specified locale. Check FileDownloadRequest for more options.

func (*HttpAPIClient) GetFileStatus

func (c *HttpAPIClient) GetFileStatus(
	projectID string,
	fileURI string,
) (*smfile.FileStatus, error)

GetFileStatus returns file status.

func (*HttpAPIClient) GetProjectDetails

func (c *HttpAPIClient) GetProjectDetails(
	projectID string,
) (*ProjectDetails, error)

GetProjectDetails returns project details for specified project.

func (*HttpAPIClient) Import

func (c *HttpAPIClient) Import(
	projectID string,
	localeID string,
	request smfile.ImportRequest,
) (*FileImportResult, error)

Import imports specified file as translation.

func (*HttpAPIClient) LastModified

func (c *HttpAPIClient) LastModified(
	projectID string,
	request smfile.FileLastModifiedRequest,
) (*smfile.FileLastModifiedLocales, error)

func (*HttpAPIClient) ListAllFiles

func (c *HttpAPIClient) ListAllFiles(
	projectID string,
	request smfile.FilesListRequest,
) ([]smfile.File, error)

ListAllFiles returns all files by request, even if it requires several API calls.

func (*HttpAPIClient) ListFileTypes

func (c *HttpAPIClient) ListFileTypes(
	projectID string,
) ([]smfile.FileType, error)

ListFileTypes returns file types list from specified project.

func (*HttpAPIClient) ListFiles

func (c *HttpAPIClient) ListFiles(
	projectID string,
	request smfile.FilesListRequest,
) (*FilesList, error)

ListFiles returns files list from specified project by specified request. Returned result is paginated, so check out TotalCount struct field in the reply. API can return only 500 files at once.

func (*HttpAPIClient) ListProjects

func (c *HttpAPIClient) ListProjects(
	accountID string,
	request smfile.ProjectsListRequest,
) (*ProjectsList, error)

ListProjects returns projects in specified account matching specified request.

func (*HttpAPIClient) LogRequest

func (c *HttpAPIClient) LogRequest(
	method string,
	url string,
	body []byte,
)

func (*HttpAPIClient) RenameFile

func (c *HttpAPIClient) RenameFile(
	projectID string,
	oldURI string,
	newURI string,
) error

RenameFile renames file to new URI.

type Locale

type Locale struct {
	// LocaleID is a unique locale ID.
	LocaleID string

	// Description describes locale.
	Description string

	// Enabled is a flag that represents is locale enabled or not.
	Enabled bool
}

Locale represents locale for translation.

type Project

type Project struct {
	// ProjectID is a unique project ID.
	ProjectID string

	// ProjectName is a human-friendly project name.
	ProjectName string

	// AccountUID is undocumented by Smartling API.
	AccountUID string

	// SourceLocaleID represents source locale ID for project.
	SourceLocaleID string

	// SourceLocaleDescription describes project's locale.
	SourceLocaleDescription string

	// Archived will be true if project is archived.
	Archived bool
}

Project represents detailed project information.

type ProjectDetails

type ProjectDetails struct {
	Project

	// TargetLocales represents target locales list.
	TargetLocales []Locale
}

ProjectDetails extends Project type to contain target locales list.

type ProjectsList

type ProjectsList struct {
	// TotalCount represents total count of projects.
	TotalCount int64

	// Items contains projects list by specified request.
	Items []Project
}

ProjectsList represents projects list under specified account.

type RetrievalType

type RetrievalType string

RetrievalType describes type of file download. https://help.smartling.com/v1.0/reference#get_projects-projectid-locales-localeid-file

Directories

Path Synopsis
api
mt
helpers
utc

Jump to

Keyboard shortcuts

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