crowdin

package module
v0.0.0-...-0d436a3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2016 License: Apache-2.0 Imports: 14 Imported by: 3 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-crowdin

Crowdin API in Go - https://crowdin.com/page/api

Go Report Card Documentation

Install

go get github.com/medisafe/go-crowdin

Initialize
api := crowdin.New("token", "project-name")
API

📘 Check the doc - Documentation

Examples:

// get language status
files, err := api.GetLanguageStatus("ru")

// add file
result, err := api.AddFile(&crowdin.AddFileOptions{
    Type: "csv",
    Scheme: "identifier,source_or_translation,context",
    FirstLineContainsHeader: true,
    Files: map[string]string{
        "strings_profile_section.csv" : "local/path/to/strings_profile_section.csv",
    },
})
Debug

You can print the internal errors by enabling debug to true

api.SetDebug(true, nil)

You can also define your own io.Writer in case you want to persist the logs somewhere. For example keeping the errors on file

logFile, err := os.Create("crowdin.log")
api.SetDebug(true, logFile)
App Engine

Initialize app engine client and continue as usual

c := appengine.NewContext(r)
client := urlfetch.Client(c)

api := crowdin.New("token", "project-name")
api.SetClient(client)

Documentation

Author

Roman Kushnarenko - sromku

License

Apache License 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	What string
}

APIError holds data of errors returned from the API.

func (APIError) Error

func (e APIError) Error() string

type AccountDetails

type AccountDetails struct {
	Success  bool `json:"success"`
	Projects []struct {
		Role         string `json:"role"`
		Name         string `json:"name"`
		Identifier   string `json:"identifier"`
		Downloadable int    `json:"downloadable"`
		Key          string `json:"key"`
	} `json:"projects"`
}

AccountDetails is a response struct

type AddFileOptions

type AddFileOptions struct {
	// Note: Used only when uploading CSV (or XLS/XLSX) file to define data columns mapping.
	// Acceptable value is the combination of the following constants:
	// "identifier" — Column contains string identifier.
	// "source_phrase" — Column contains only source string (in result string will contain same string).
	// "source_or_translation" — Column contains source string but when exporting same column should contain translation (also when uploading existing translations, the value from this column will be used as a translated string).
	// "translation" — Column contains translated string (when imported file already contains translations).
	// "context" — Column contains some comments on source string. Context information.
	// "max_length" — Column contains max. length of translation for this string.
	// "none" — Do not import column.
	Scheme string

	// Used when uploading CSV (or XLS/XLSX) files via API. Defines whether first line should be imported or it contains columns headers. May not contain value.
	FirstLineContainsHeader bool

	// Files array that should be added to Crowdin project. Array keys should contain file names with path in Crowdin project.
	Files map[string]string

	// Acceptable values are:
	// empty value or "auto" — Try to detect file type by extension or MIME type
	// "gettext" — GNU GetText (*.po, *.pot)
	// "qtts" — Nokia Qt (*.ts)
	// "dklang" — Delphi DKLang (*.dklang)
	// "android" — Android (*.xml)
	// "resx" — .NET (*.resx)
	// "properties" — Java (*.properties)
	// "macosx" — Mac OS X / iOS (*.strings)
	// "blackberry" — BlackBerry (*.rrc)
	// "Symbian" — Symbian (*.lXX)
	// "flex" — Adobe Flex (*.properties)
	// "bada" — Samsung Bada (*.xml)
	// "txt" — Plain Text (*.txt)
	// "srt" — SubRip .srt (*.srt)
	// "sbv" — Youtube .sbv (*.sbv)
	// "xliff" — XLIFF (*.xliff)
	// "html" — HTML (*.html, *.htm, *.xhtml, *.xhtm)
	// "dtd" — Mozilla DTD (*.dtd)
	// "chrome" — Google Chrome Extension (*.json)
	// "yaml" — Ruby On Rails (*.yaml)
	// "csv" — Comma Separated Values (*.csv)
	// "rc" — Windows Resources (*.rc)
	// "wxl" — WiX Installer Resources (*.wxl)
	// "nsh" — NSIS Installer Resources (*.nsh)
	// "joomla" — Joomla localizable resources (*.ini)
	// "ini" — Generic INI (*.ini)
	// "isl" — ISL (*.isl)
	// "resw" — Windows 8 Metro (*.resw)
	// "resjson" — Windows 8 Metro (*.resjson)
	// "docx" — Microsoft Office and OpenOffice.org Documents (*.docx, *.dotx, *.odt, *.ott, *.xslx, *.xltx, *.pptx, *.potx, *.ods, *.ots, *.odg, *.otg, *.odp, *.otp, *.idml)
	// "md" — Markdown (*.md, *.text, *.markdown...)
	// "mediawiki" — MediaWiki (*.wiki, *.wikitext, *.mediawiki)
	// "play" — Play Framework
	// "haml" — Haml (*.haml)
	// "arb" — Application Resource Bundle (*.arb)
	// "vtt" — Video Subtitling and WebVTT (*.vtt)
	Type string
}

AddFileOptions used for AddFile() API call

type ChangeDirectoryOptions

type ChangeDirectoryOptions struct {
	// Full directory path that should be modified (e.g. /MainPage/AboutUs).
	Name string

	// New directory name.
	NewName string

	// New directory title to be displayed in Crowdin UI.
	Title string
}

ChangeDirectoryOptions are options for ChangeDirectory api call

type CreateProjectOptions

type CreateProjectOptions struct {
	// Project name.
	Name string

	// Project identifier. Should be unique among other Crowdin projects.
	Identifier string

	// Source files language. Should be a two letters language code.
	SourceLanguage string

	// An array of language codes project should be translate to.
	Languages []string

	// Project join policy. Acceptable values are: open, private
	JoinPolicy string
}

CreateProjectOptions are options for CreateProject api call

type Crowdin

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

Crowdin API wrapper

func New

func New(token, project string) *Crowdin

New - create new instance of Crowdin API.

func (*Crowdin) AddDirectory

func (crowdin *Crowdin) AddDirectory(directoryName string) (*responseGeneral, error)

AddDirectory - Add directory to Crowdin project. name - Directory name (with path if nested directory should be created).

func (*Crowdin) AddFile

func (crowdin *Crowdin) AddFile(options *AddFileOptions) (*responseAddFile, error)

AddFile - Add new file to Crowdin project.

func (*Crowdin) ChangeDirectory

func (crowdin *Crowdin) ChangeDirectory(options *ChangeDirectoryOptions) (*responseGeneral, error)

ChangeDirectory - Rename directory or modify its attributes. When renaming directory the path can not be changed (it means new_name parameter can not contain path, name only).

func (*Crowdin) CreateProject

func (crowdin *Crowdin) CreateProject(accountKey, loginUsername string, options *CreateProjectOptions) (*responseManageProject, error)

CreateProject - Create Crowdin project.

func (*Crowdin) DeleteDirectory

func (crowdin *Crowdin) DeleteDirectory(directoryName string) (*responseGeneral, error)

DeleteDirectory - Delete Crowdin project directory. All nested files and directories will be deleted too. name - Directory name (with path if nested directory should be created).

func (*Crowdin) DeleteFile

func (crowdin *Crowdin) DeleteFile(fileName string) (*responseGeneral, error)

DeleteFile - Delete file from Crowdin project. All the translations will be lost without ability to restore them

func (*Crowdin) DeleteProject

func (crowdin *Crowdin) DeleteProject() (*responseDeleteProject, error)

DeleteProject - Delete Crowdin project with all translations.

func (*Crowdin) DownloadTranslations

func (crowdin *Crowdin) DownloadTranslations(options *DownloadOptions) error

DownloadTranslations - Download ZIP file with translations. You can choose the language of translation you need or download all of them at once.

func (*Crowdin) EditProject

func (crowdin *Crowdin) EditProject(options *EditProjectOptions) (*responseManageProject, error)

EditProject - Edit Crowdin project.

func (*Crowdin) ExportFile

func (crowdin *Crowdin) ExportFile(options *ExportFileOptions) error

ExportFile - This method exports single translated files from Crowdin. Additionally, it can be applied to export XLIFF files for offline localization.

func (*Crowdin) ExportTranslations

func (crowdin *Crowdin) ExportTranslations() (*responseExportTranslations, error)

ExportTranslations - Build ZIP archive with the latest translations. Please note that this method can be invoked only once per 30 minutes (there is no such restriction for organization plans). Also API call will be ignored if there were no changes in the project since previous export. You can see whether ZIP archive with latest translations was actually build by status attribute ("built" or "skipped") returned in response.

func (*Crowdin) GetAccountProjects

func (crowdin *Crowdin) GetAccountProjects(accountKey, loginUsername string) (*AccountDetails, error)

GetAccountProjects - Get Crowdin Project details.

func (*Crowdin) GetLanguageStatus

func (crowdin *Crowdin) GetLanguageStatus(languageCode string) (*responseLanguageStatus, error)

GetLanguageStatus - Get the detailed translation progress for specified language. Language codes - https://crowdin.com/page/api/language-codes

func (*Crowdin) GetProjectDetails

func (crowdin *Crowdin) GetProjectDetails() (*ProjectInfo, error)

GetProjectDetails - Get Crowdin Project details

func (*Crowdin) GetTranslationsStatus

func (crowdin *Crowdin) GetTranslationsStatus() ([]TranslationStatus, error)

GetTranslationsStatus - Track overall translation and proofreading progresses of each target language

func (*Crowdin) SetClient

func (crowdin *Crowdin) SetClient(client *http.Client)

SetClient sets a custom http client. Can be useful in App Engine case.

func (*Crowdin) SetDebug

func (crowdin *Crowdin) SetDebug(debug bool, logWriter io.Writer)

SetDebug - traces errors if it's set to true.

func (*Crowdin) SetProject

func (crowdin *Crowdin) SetProject(token, project string) *Crowdin

SetProject set project details

func (*Crowdin) UpdateFile

func (crowdin *Crowdin) UpdateFile(options *UpdateFileOptions) (*responseGeneral, error)

UpdateFile - Upload latest version of your localization file to Crowdin

func (*Crowdin) UploadTranslations

func (crowdin *Crowdin) UploadTranslations(options *UploadTranslationsOptions) (*responseUploadTranslation, error)

UploadTranslations - Upload latest version of your localization file to Crowdin

type DownloadOptions

type DownloadOptions struct {
	// Language code or "all" to download a bundle with translations to all languages.
	Package string

	// Path to the file name that file will be exported to.
	LocalPath string
}

DownloadOptions are options for DownloadTranslations api call

type EditProjectOptions

type EditProjectOptions struct {
	// Project name.
	Name string

	// An array of language codes project should be translate to.
	Languages []string

	// Project join policy. Acceptable values are: open, private
	JoinPolicy string
}

EditProjectOptions are options for EditProject api call

type ExportFileOptions

type ExportFileOptions struct {
	// This parameter specifies a path to the file that should be exported from the project.
	CrowdinFile string

	// Crowdin language code.
	Language string

	// Path to the file name that file will be exported to.
	LocalPath string
}

ExportFileOptions are options for ExportFile api call

type ProjectInfo

type ProjectInfo struct {
	Files []struct {
		Name         string `json:"name"`
		NodeType     string `json:"node_type"`
		Created      string `json:"created"`
		LastUpdated  string `json:"last_updated"`
		LastAccessed string `json:"last_accessed"`
		LastRevision string `json:"last_revision"`
	} `json:"files"`
	Language struct {
		Name         string `json:"name"`
		Code         string `json:"code"`
		CanTranslate int    `json:"can_translate"`
		CanApprove   int    `json:"can_approve"`
	}
	Details struct {
		SourceLanguage struct {
			Name string `json:"name"`
			Code string `json:"code"`
		} `json:"source_language"`
		Name                  string `json:"name"`
		Identifier            string `json:"identifier"`
		Created               string `json:"created"`
		Description           string `json:"description"`
		JoinPolicy            string `json:"private"`
		LastBuild             string `json:"last_build"`
		LastActivity          string `json:"last_activity"`
		ParticipantsCount     string `json:"participants_count"`
		TotalStringsCount     string `json:"total_strings_count"`
		TotalWordsCount       string `json:"total_words_count"`
		DuplicateStringsCount int    `json:"duplicate_strings_count"`
		DuplicateWordsCount   int    `json:"duplicate_words_count"`
		InviteURL             struct {
			Translator  string `json:"translator"`
			Proofreader string `json:"proofreader"`
		} `json:"invite_url"`
	} `json:"details"`
}

ProjectInfo is a response struct

type TranslationStatus

type TranslationStatus struct {
	Name               string `json:"name"`
	Code               string `json:"code"`
	Phrases            string `json:"phrases"`
	Translated         string `json:"translated"`
	Approved           string `json:"approved"`
	Words              string `json:"words"`
	WordsTranslated    string `json:"words_translated"`
	WordsApproved      string `json:"words_approved"`
	TranslatedProgress int    `json:"translated_progress"`
	ApprovedProgress   int    `json:"approved_progress"`
}

TranslationStatus is a response struct

type UpdateFileOptions

type UpdateFileOptions struct {
	// Note: Used only when uploading CSV (or XLS/XLSX) file to define data columns mapping.
	// Acceptable value is the combination of the following constants:
	// "identifier" — Column contains string identifier.
	// "source_phrase" — Column contains only source string (in result string will contain same string).
	// "source_or_translation" — Column contains source string but when exporting same column should contain translation (also when uploading existing translations, the value from this column will be used as a translated string).
	// "translation" — Column contains translated string (when imported file already contains translations).
	// "context" — Column contains some comments on source string. Context information.
	// "max_length" — Column contains max. length of translation for this string.
	// "none" — Do not import column.
	Scheme string

	// Used when uploading CSV (or XLS/XLSX) files via API. Defines whether first line should be imported or it contains columns headers. May not contain value.
	FirstLineContainsHeader bool

	// Files array that should be added to Crowdin project. Array keys should contain file names with path in Crowdin project.
	Files map[string]string
}

UpdateFileOptions used for UpdateFile() API call

type UploadTranslationsOptions

type UploadTranslationsOptions struct {
	// Target language. With a single call it's possible to upload translations for several files but only into one of the languages.
	Language string

	// Translated files array. Array keys should contain file names in Crowdin.
	Files map[string]string

	// Defines whether to add translation if there is the same translation previously added. Acceptable values are: 0 or 1. Default is 0.
	ImportDuplicates string
}

UploadTranslationsOptions are options for UploadTranslations api call

Jump to

Keyboard shortcuts

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