Language server
Install the transglot language server to see translations beside your keys, flag missing ones, and extract hardcoded strings in Neovim, JetBrains IDEs, Helix, Sublime Text or any other editor with an LSP client.
@transglot/lsp is a Language Server Protocol server. Any editor with an LSP client can start it and get the same features, configured once per editor.
Features
- Missing translations as diagnostics. In a JSON source file that one of your
sourcesrules names, every key with no translation in a target locale is flagged:"cart.title" is missing a translation in: fr, de. - Hover. Hovering a key shows its translation in every target locale.
- CodeLens. A summary line above each key, such as
fr: Bonjour · de: Hallo · es: Hola. - Extract to transglot key. On a string literal in a
.js,.jsx,.tsor.tsxfile, the code action Extract to transglot key adds the string to your messages file under a generated key, replaces the literal with an i18n call such ast('key'), and offers Push key to transglot to upload the messages file.
Diagnostics, hover and CodeLens work on the JSON formats: json_flat, json_nested, laravel_json and flutter_arb. The server downloads each target locale from the project, so it shows what the project holds rather than your local target files.
Requirements
- Node.js 20 or later.
- A deploy token with the pull ability, plus push to upload extracted keys. See Deploy tokens.
- A
transglot.jsonin the workspace root. The server reads itssourcesrules to know which files are source files. See Configuration file.
Version 0.1.0 of the server cannot read a transglot.json whose rules use metadata, unity_csv or unreal_po. It then logs transglot: could not load transglot.json and shows no diagnostics.
Install
npm install -g @transglot/lspThis puts a transglot-lsp command on your PATH. It speaks LSP over stdio.
Settings
The server reads its settings from the initializationOptions your editor sends when it starts the server. They are read once, at start.
Prop
Type
Keep the token out of files you commit. The examples below read it from the TRANSGLOT_TOKEN environment variable where the editor allows it.
Set up your editor
Neovim
Neovim 0.11 and later configure language servers with vim.lsp.config:
vim.lsp.config('transglot', {
cmd = { 'transglot-lsp' },
filetypes = { 'json', 'javascript', 'javascriptreact', 'typescript', 'typescriptreact' },
root_markers = { 'transglot.json', '.git' },
init_options = {
serverUrl = 'https://api.transglot.ai',
token = os.getenv('TRANSGLOT_TOKEN'),
messagesFile = 'src/messages/en.json',
i18nFunction = 't',
format = 'json_flat',
},
})
vim.lsp.enable('transglot')Use your usual LSP keymaps: hover with K, code actions with gra, diagnostics in the location list.
JetBrains IDEs
IntelliJ IDEA, WebStorm, PhpStorm and the other JetBrains IDEs (2023.2 and later) run external language servers through the free LSP4IJ plugin.
Install LSP4IJ
In Settings → Plugins → Marketplace, search for LSP4IJ, install it and restart the IDE.
Add the server
Open Settings → Languages & Frameworks → Language Servers, select + and choose New Language Server. Set:
- Name:
transglot - Command:
transglot-lsp - Mappings → File name patterns:
*.json,*.js,*.jsx,*.ts,*.tsx
Add the settings
Under Configuration → Initialization Options, paste:
{
"serverUrl": "https://api.transglot.ai",
"token": "tgl_xxx",
"messagesFile": "src/messages/en.json",
"i18nFunction": "t",
"format": "json_flat"
}Replace tgl_xxx with your token and select Apply. LSP4IJ's LSP Consoles tool window shows the server's log if nothing appears.
If the IDE cannot find transglot-lsp, use the full path that which transglot-lsp prints as the command.
Helix
[language-server.transglot]
command = "transglot-lsp"
[language-server.transglot.config]
serverUrl = "https://api.transglot.ai"
token = "tgl_xxx"
messagesFile = "src/messages/en.json"
[[language]]
name = "json"
language-servers = ["vscode-json-language-server", "transglot"]
[[language]]
name = "typescript"
language-servers = ["typescript-language-server", "transglot"]Keep each language's existing servers in its language-servers list and add transglot.
Sublime Text
With the LSP package installed, open Preferences → Package Settings → LSP → Settings and add a client:
{
"clients": {
"transglot": {
"enabled": true,
"command": ["transglot-lsp"],
"selector": "source.json | source.js | source.jsx | source.ts | source.tsx",
"initializationOptions": {
"serverUrl": "https://api.transglot.ai",
"token": "tgl_xxx",
"messagesFile": "src/messages/en.json"
}
}
}
}Other editors
Any LSP client that can start a stdio server works: run transglot-lsp and pass the settings as initialization options.
Commands
The server registers transglot.pushKey, which pushes messagesFile to the project. Extract to transglot key offers it as Push key to transglot after it writes a key, and when it succeeds the editor shows how many keys were created.
Troubleshooting
Messages from the server appear in your editor's LSP log:
| Message | Cause |
|---|---|
transglot: not connected. Set serverUrl and token in the LSP initializationOptions. | One of the two required settings is missing. |
transglot: could not load transglot.json: ... | The file is missing from the workspace root, is invalid, or uses a field or format version 0.1.0 does not read. |
transglot: pull fr failed: ... | The token lacks pull, or the locale is not a language of the project. |
Editor and IDE plugins
Bring transglot into your editor through the language server, and into your AI coding assistant through the MCP server.
File formats
Every file format transglot reads and writes, the identifier you use for it in configuration and the API, and how keys, plurals and placeholders map.