Skip to main content

Plugin Translation

How to make your plugin support multi-language?

Since answer supports multiple languages, the plugin also needs to support multiple languages. The following is an example of how to make your plugin support multiple languages.

Translator Structure

In some plugins interface, you can see the Translator structure, which is used to support multiple languages.

For example, the ConfigField structure has a Title field of type Translator.

type ConfigField struct {
Name string `json:"name"`
Type ConfigType `json:"type"`
Title Translator `json:"title"`
Description Translator `json:"description"`
Required bool `json:"required"`
Value string `json:"value"`
UIOptions ConfigFieldUIOptions `json:"ui_options"`
Options []ConfigFieldOption `json:"options,omitempty"`

It's easy to build a Translator structure, just like this:

import (


The is the key of the translation file, which will be introduced later.

So, the first step is build a Translator structure for each field that needs to be translated.

Translation File

Make directory i18n in the root directory of your plugin, and then create a file named en_US.yaml in it.

The en_US.yaml file is used to store the English translation of the plugin.

The content of the en_US.yaml file is as follows:

other: GitHub
other: GitHub Connector
other: Connect to GitHub for third-party login
other: ClientID
other: Client ID of your GitHub application
other: ClientSecret
other: Client secret of your GitHub application
title: Login with GitHub
description: Login with GitHub
  • The plugin is the root key of the translation file.
  • The github_connector is the name of the plugin.
  • The backend is translation for the backend. The end of key like other is just for go-i18n to recognize the translation file.
  • The ui is translation for the frontend.

You can use the key like or plugin.github_connector.ui.login.title for translation.

Create a i18n.go file in the root directory of your plugin, and then add the following code:

package i18n

const (
ConnectorName = ""
InfoName = ""
InfoDescription = ""
ConfigClientIDTitle = "plugin.github_connector.backend.config.client_id.title"
ConfigClientIDDescription = "plugin.github_connector.backend.config.client_id.description"
ConfigClientSecretTitle = "plugin.github_connector.backend.config.client_secret.title"
ConfigClientSecretDescription = "plugin.github_connector.backend.config.client_secret.description"

The i18n.go file is used to store the key of the translation file.

Finally, the directory structure of the plugin is as follows:

├── github.go
├── go.mod
├── go.sum
└── i18n
├── en_US.yaml
├── translation.go
└── zh_CN.yaml

Backend Translation

You just need to return Translator structure with the key of the translation file.

func (g *GitHubConnector) ConnectorName() plugin.Translator {
return plugin.MakeTranslator(i18n.ConnectorName)

The Answer will automatically translate the key of the translation file into the corresponding language.