smartling

package module
v2.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2016 License: MIT Imports: 15 Imported by: 0

README

Smartling

A client implementation of the Smartling Translation API in Go.

It consists of a library for use in other projects, and a CLI tool.

Using the Library

You can find documentation at http://godoc.org/github.com/99designs/smartling

import "github.com/99designs/smartling"

client := smartling.NewClient(apiKey, projectId)
client.List(smartling.ListRequest{
    Limit: 20,
})

CLI tool

The smartling CLI tool provides a familiar unix-like command interface to the Smartling API, as well as providing a project command to manage a project's local files.

Install it with go get github.com/99designs/smartling/cli/smartling or run it as a docker container e.g. docker run -v MyProject:/work 99designs/smartling ls

COMMANDS:
   ls           list remote files
   stat         display the translation status of a remote file
   get          downloads a remote file
   put          uploads a local file
   rename       renames a remote file
   rm           removes a remote file
   lastmodified shows when a remote file was modified last
   locales      list the locales for the project
   project      manage local project files
The smartling project command

The smartling project commands are designed for some common use-cases in a dev or CI environment.

COMMANDS:
   files  lists the local files
   status show the status of the project's remote files
   pull   translate local project files using Smartling as a translation memory
   push   upload local project files that contain untranslated strings

"Pushing" uploads files to a smartling project using a prefix. By default it uses the git branch name , but you can also specifiy the wanted prefix as an argument. A hash is also used in the prefix to prevent clobbering.

"Pulling" translates local project files using Smartling as a translation memory.

Other cool features:

  • downloaded translation files are cached (default is 4 hours) in ~/.smartling/cache
  • operations mostly happen concurrently
  • filetypes get detected automatically
Configuration file

The CLI tool uses a project level config file called smartling.yml for configuration.

Example config:

# Required config
ApiKey: "11111111-2222-3333-4444-555555555555"             # Smartling API Key
ProjectId: "666666666"                                     # Smartling Project Id
Files:                                                     # Files in the project
  - translations/*.xlf                                     # Globbing can be used,
  - foo/bar.xlf                                            # as well as individual files

# Optional config
CacheMaxAge: "4h"                                          # How long to cache translated files for
FileType: "xliff"                                          # Override the detected file type
ParserConfig:                                              # Add a custom configuration
  placeholder_format_custom: "%[^%]+%"
PullFilePath: "{{ TrimSuffix .Path .Ext }}.{{.Locale}}{{.Ext}}" # The naming scheme when pulling files

Documentation

Overview

Package smartling is a client implementation of the Smartling Translation API as documented at https://docs.smartling.com/display/docs/Smartling+Translation+API

Index

Constants

View Source
const Format = "2006-01-02T15:04:05"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseUrl   string
	ApiKey    string
	ProjectId string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(apiKey string, projectId string) *Client

func NewSandboxClient

func NewSandboxClient(apiKey string, projectId string) *Client

func (*Client) Delete

func (c *Client) Delete(fileUri string) error

func (*Client) Get

func (c *Client) Get(req *GetRequest) ([]byte, error)

func (*Client) LastModified

func (c *Client) LastModified(req LastModifiedRequest) ([]LastModifiedItem, error)

func (*Client) List

func (c *Client) List(req ListRequest) ([]FileStatus, error)

func (*Client) Locales

func (c *Client) Locales() ([]Locale, error)

func (*Client) Rename

func (c *Client) Rename(oldFileUri, newFileUri string) error

func (*Client) SetHttpTimeout

func (c *Client) SetHttpTimeout(t time.Duration)

func (*Client) Status

func (c *Client) Status(fileUri, locale string) (FileStatus, error)

func (*Client) Upload

func (c *Client) Upload(localFilePath string, req *UploadRequest) (*UploadResponse, error)

func (*Client) UploadReader

func (c *Client) UploadReader(filename string, contents io.Reader, req *UploadRequest) (*UploadResponse, error)

type FaultTolerantClient

type FaultTolerantClient struct {
	*Client
	RetriesOnError int
}

FaultTolerantClient decorates a Client and retries requests when Smartling returns with an error

func (*FaultTolerantClient) Delete

func (c *FaultTolerantClient) Delete(fileUri string) (err error)

func (*FaultTolerantClient) Get

func (c *FaultTolerantClient) Get(req *GetRequest) (b []byte, err error)

func (*FaultTolerantClient) LastModified

func (c *FaultTolerantClient) LastModified(req LastModifiedRequest) (ii []LastModifiedItem, err error)

func (*FaultTolerantClient) List

func (c *FaultTolerantClient) List(req ListRequest) (ff []FileStatus, err error)

func (*FaultTolerantClient) Rename

func (c *FaultTolerantClient) Rename(oldFileUri, newFileUri string) (err error)

func (*FaultTolerantClient) Status

func (c *FaultTolerantClient) Status(fileUri, locale string) (f FileStatus, err error)

func (*FaultTolerantClient) Upload

func (c *FaultTolerantClient) Upload(localFilePath string, req *UploadRequest) (r *UploadResponse, err error)

type FileStatus

type FileStatus struct {
	FileUri              string      `json:"fileUri"`
	StringCount          int         `json:"stringCount"`
	WordCount            int         `json:"wordCount"`
	ApprovedStringCount  int         `json:"approvedStringCount"`
	CompletedStringCount int         `json:"completedStringCount"`
	LastUploaded         Iso8601Time `json:"lastUploaded"`
	FileType             FileType    `json:"fileType"`
}

func (FileStatus) AwaitingAuthorizationStringCount

func (fs FileStatus) AwaitingAuthorizationStringCount() int

func (FileStatus) InProgressStringCount

func (fs FileStatus) InProgressStringCount() int

func (FileStatus) NotCompletedStringCount

func (fs FileStatus) NotCompletedStringCount() int

type FileType

type FileType string
const (
	Android        FileType = "android"
	Ios            FileType = "ios"
	Gettext        FileType = "gettext"
	Html           FileType = "html"
	JavaProperties FileType = "javaProperties"
	Yaml           FileType = "yaml"
	Xliff          FileType = "xliff"
	Xml            FileType = "xml"
	Json           FileType = "json"
	Docx           FileType = "docx"
	Pptx           FileType = "pptx"
	Xlsx           FileType = "xlsx"
	Idml           FileType = "idml"
	Qt             FileType = "qt"
	Resx           FileType = "resx"
	Plaintext      FileType = "plaintext"
	Csv            FileType = "csv"
	Stringsdict    FileType = "stringsdict"
)

func FileTypeByExtension

func FileTypeByExtension(ext string) FileType

FileTypeByExtension returns the FileType associated with the file extension ext. The extension ext should begin with a leading dot, as in ".html". When ext has no associated type, FileTypeByExtension returns "".

type GetRequest

type GetRequest struct {
	FileUri                string        `url:"fileUri"`
	Locale                 string        `url:"locale,omitempty"`
	RetrievalType          RetrievalType `url:"retrievalType,omitempty"`
	IncludeOriginalStrings bool          `url:"includeOriginalStrings,omitempty"`
}

type Iso8601Time added in v1.0.0

type Iso8601Time time.Time

func (Iso8601Time) EncodeValues added in v1.0.0

func (it Iso8601Time) EncodeValues(key string, v *url.Values) error

func (Iso8601Time) MarshalJSON added in v1.0.0

func (it Iso8601Time) MarshalJSON() ([]byte, error)

func (*Iso8601Time) UnmarshalJSON added in v1.0.0

func (it *Iso8601Time) UnmarshalJSON(data []byte) error

type LastModifiedItem

type LastModifiedItem struct {
	Locale       string      `json:"locale"`
	LastModified Iso8601Time `json:"lastModified"`
}

type LastModifiedRequest

type LastModifiedRequest struct {
	FileUri           string `url:"fileUri"`
	LastModifiedAfter string `url:"lastModifiedAfter,omitempty"`
	Locale            string `url:"locale"`
}

type LastModifiedResponse

type LastModifiedResponse struct {
	Items []LastModifiedItem `json:"items"`
}

type ListCondition

type ListCondition string
const (
	HaveAtLeastOneUnapproved ListCondition = "haveAtLeastOneUnapproved"
	HaveAtLeastOneApproved   ListCondition = "haveAtLeastOneApproved"
	HaveAtLeastOneTranslated ListCondition = "haveAtLeastOneTranslated"
	HaveAllTranslated        ListCondition = "haveAllTranslated"
	HaveAllApproved          ListCondition = "haveAllApproved"
	HaveAllUnapproved        ListCondition = "haveAllUnapproved"
)

type ListRequest

type ListRequest struct {
	Locale             string          `url:"locale,omitempty"`
	UriMask            string          `url:"uriMask,omitempty"`
	FileTypes          []FileType      `url:"fileTypes,omitempty"`
	LastUploadedAfter  *Iso8601Time    `url:"lastUploadedAfter,omitempty"`
	LastUploadedBefore *Iso8601Time    `url:"lastUploadedBefore,omitempty"`
	Offset             int             `url:"offset,omitempty"`
	Limit              int             `url:"limit,omitempty"`
	Conditions         []ListCondition `url:"conditions,omitempty"`
	OrderBy            string          `url:"orderBy,omitempty"`
}

type ListResponse

type ListResponse struct {
	FileCount int          `json:"fileCount"`
	Files     []FileStatus `json:"fileList"`
}

type Locale

type Locale struct {
	Name       string `json:"name"`
	Locale     string `json:"locale"`
	Translated string `json:"translated"`
}

type LocalesResponse

type LocalesResponse struct {
	Locales []Locale `json:"locales"`
}

type RetrievalType

type RetrievalType string
const (
	Pending                     RetrievalType = "pending"
	Published                   RetrievalType = "published"
	Pseudo                      RetrievalType = "pseudo"
	ContextMatchingInstrumented RetrievalType = "contextMatchingInstrumented"
)

type SmartlingResponse

type SmartlingResponse struct {
	Code     string          `json:"code"`
	Messages []string        `json:"messages"`
	Data     json.RawMessage `json:"data"`
}

func (SmartlingResponse) Error

func (sr SmartlingResponse) Error() string

func (SmartlingResponse) IsError

func (sr SmartlingResponse) IsError() bool

func (SmartlingResponse) IsNotFoundError

func (sr SmartlingResponse) IsNotFoundError() bool

func (SmartlingResponse) IsResourceLockedError

func (sr SmartlingResponse) IsResourceLockedError() bool

func (SmartlingResponse) IsValidationError

func (sr SmartlingResponse) IsValidationError() bool

type UploadRequest

type UploadRequest struct {
	FileUri          string            `url:"fileUri,"`
	Approved         bool              `url:"approved,omitempty"`
	LocalesToApprove []string          `url:"localesToApprove,omitempty"`
	FileType         FileType          `url:"fileType"`
	CallbackUrl      *url.URL          `url:"callbackUrl,omitempty"`
	ParserConfig     map[string]string `url:"-"`
}

func (*UploadRequest) AddParserConfig

func (u *UploadRequest) AddParserConfig(k, v string)

type UploadResponse

type UploadResponse struct {
	OverWritten bool `json:"overWritten"`
	StringCount int  `json:"stringCount"`
	WordCount   int  `json:"wordCount"`
}

Directories

Path Synopsis
Godeps
_workspace/src/github.com/codegangsta/cli
Package cli provides a minimal framework for creating and organizing command line Go applications.
Package cli provides a minimal framework for creating and organizing command line Go applications.
_workspace/src/github.com/google/go-querystring/query
Package query implements encoding of structs into URL query parameters.
Package query implements encoding of structs into URL query parameters.
_workspace/src/gopkg.in/yaml.v2
Package yaml implements YAML support for the Go language.
Package yaml implements YAML support for the Go language.
cli

Jump to

Keyboard shortcuts

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