Skip to content
Lokalise API v2 Golang client library.
Go
Branch: master
Clone or download
Latest commit 600ef3a Oct 28, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
integration_test Merge branch refactoring_v3 into master Oct 6, 2019
.gitignore Added Branches Oct 15, 2019
README.md Update README.md Oct 28, 2019
api.go Added Branches Oct 15, 2019
client.go refactoring v2 & services implementation Oct 1, 2019
error.go refactoring v0.1 Sep 4, 2019
go.mod Added Branches Oct 15, 2019
go.sum Merge branch refactoring_v3 into master Oct 6, 2019
pagination.go updates for repeatable list Oct 14, 2019
service.go Merge branch refactoring_v3 into master Oct 6, 2019
svc_branch.go Renamed svc Oct 15, 2019
svc_comment.go Merge branch refactoring_v3 into master Oct 6, 2019
svc_contributor.go contributor bugfix & simplified code in SDK Oct 14, 2019
svc_file.go Parameter fix Oct 22, 2019
svc_key.go some other changes Oct 8, 2019
svc_language.go Merge branch refactoring_v3 into master Oct 6, 2019
svc_order.go Parameters corrected. Oct 21, 2019
svc_paymentcard.go Merge branch refactoring_v3 into master Oct 6, 2019
svc_project.go got strings back) Oct 7, 2019
svc_screenshot.go fix again svc_screenshot; fix svc_key Oct 7, 2019
svc_snapshot.go Merge branch refactoring_v3 into master Oct 6, 2019
svc_task.go Opts types change Oct 7, 2019
svc_team.go TeamService fix Oct 7, 2019
svc_teamuser.go Merge branch refactoring_v3 into master Oct 6, 2019
svc_teamusergroup.go Type fix Oct 22, 2019
svc_translation.go Parameters corrected. Oct 21, 2019
svc_translationprovider.go Parameters corrected. Oct 21, 2019
svc_translationstatus.go Merge branch refactoring_v3 into master Oct 6, 2019
svc_webhook.go webhook struct fix Oct 11, 2019

README.md

Lokalise API v2 official Golang client library

Index

Getting Started

Installation and usage

# Go Modules
require github.com/lokalise/go-lokalise-api master

Import into your code and refer it as lokalise.

import "github.com/lokalise/go-lokalise-api"

var newKey lokalise.NewKey

Initializing the client

token := os.Getenv("lokalise_token")
client, err := lokalise.New(token)

General options

You can set global API parameters with the ClientOption functions during the initialization. The following functions are available:

  • WithBaseURL
  • WithRetryCount
  • WithRetryTimeout
  • WithConnectionTimeout
  • WithDebug
  • WithPageLimit

Usage:

Api, err := lokalise.New(
    "token-string",
    lokalise.WithDebug(true),
    ...
)

Objects and models

Individual objects are represented as instances of according structs. Different objects are used for creating and updating in most cases.

Here are some object types:

  • Create/Update request objects, i.e. NewKey, NewContributor etc

  • Response objects: single/multiple, i.e. KeyResponse/KeysResponse and special , i.e. DeleteKeyResponse. There is no separate ErrorResponse - errors are encapsulated into concrete method's response.

  • List options that are used for sending certain options and pagination, i.e. KeyListOptions.

Request options and pagination

Some resources, such as Projects, Keys, Files, Tasks, Screenshots, Translations have optional parameters for List method (Keys also have an option for Retrieve). These parameters should be set before calling.

All request options could be set inline and separately:

// separately:
keys := client.Keys()
keys.SetListOptions(lokalise.KeyListOptions{
    IncludeTranslations: 1,
    IncludeComments: 1,
})

resp, err := keys.List("{PROJECT_ID}")

// inline:
client.Keys().WithListOptions(lokalise.KeyListOptions{Limit: 3}).List("{PROJECT_ID}")

There are two parameters, used for pagination: Limit and Page.

t := Api.Teams()
t.SetPageOptions(lokalise.PageOptions{
    Page:  2,
    Limit: 10,
})

resp, err := t.List()

Available resources

Comments

List project comments

projectId := "aaaabbbb.cccc"
c := Api.Comments()
c.SetPageOptions(lokalise.PageOptions{Page: 1, Limit: 20})
resp, err := c.ListProject(projectId)

List key comments

projectId := "aaaabbbb.cccc"
keyId := 26835183
c := Api.Comments()
c.SetPageOptions(lokalise.PageOptions{Page: 1, Limit: 20})
resp, err := c.ListByKey(projectId, keyId)

Create

c := lokalise.NewComment{Comment: "My new comment"}
resp, err := Api.Comments().Create(projectId, keyId, []lokalise.NewComment{c})

Retrieve

...
commentId := 26835183
resp, err := Api.Comments().Retrieve(projectId, keyId, commentId)

Delete

...
resp, err := Api.Comments().Delete(projectId, keyId, commentId)

Contributors

List all contributors

projectId := "aaaabbbb.cccc"
pageOpts := lokalise.PageOptions{Page: 1, Limit: 20}

c := Api.Contributors()
c.SetPageOptions(pageOpts)
c.List(projectId)

Create contributors

contributorCreate := lokalise.NewContributor{
    Email:    "some@ema.il",
    Fullname: "New contributor",
    Permission: lokalise.Permission{
        IsAdmin:     true,
        IsReviewer:  true,
        Languages:   []lokalise.Language{{LangISO: "en", IsWritable: true}},
        AdminRights: []string{"upload", "download"},
    },
}
resp, err := Api.Contributors().Create(projectId, []lokalise.NewContributor{contributorCreate})

Retrieve contributor

userId := 47913 
resp, err := Api.Contributors().Retrieve(projectId, userId)

Update contributor

...
permissionUpdate := lokalise.Permission{
    IsReviewer: true,
    IsAdmin: false,
    AdminRights: []string{"keys", "upload", "download"},
}
resp, err := Api.Contributors().Update(projectId, userId, permissionUpdate)
You can’t perform that action at this time.