Translation Progress Badge
A small image that shows how much of your Locize project is translated. Put it in a README, in your documentation or on your website. It updates by itself when your translations change.
You build the badge from a URL. You need no dashboard step, and nothing has to be enabled.
What the badge shows
| Badge | Figure | Example |
|---|---|---|
| Project | all versions, all languages | Locize: 100% translated |
| Version | all languages of one version | Locize: production: 100% translated |
| Language | one language in one version | Locize: de: 100% translated |
- The figure is the number of translated segments divided by the number of all segments, over all namespaces, rounded to two decimals (e.g.
49.48%). - The reference language counts too. It is usually 100% translated, so a project or version figure is higher than the average of your target languages. For the figure of one target language, use a language badge.
- The figures come from the same translation statistics as the progress in the Locize dashboard.
How it works
- Locize keeps a small JSON file with the progress figures of your project on the CDN, the badge data:
- Standard CDN:
https://api.lite.locize.app/badgedata/{projectId} - Pro CDN:
https://api.locize.app/badgedata/{projectId}
- Standard CDN:
- Locize rewrites this file whenever translations are saved and whenever a version is published.
- shields.io, a free badge service, draws the badge: its Dynamic JSON Badge reads one figure from the file and renders it as an SVG image.
The badge data looks like this:
{
"versions": {
"production": {
"languages": {
"en": { "name": "English", "nativeName": "English", "isReferenceLanguage": true, "translated": 1, "translatedPercentage": 100 },
"de": { "name": "German", "nativeName": "Deutsch", "isReferenceLanguage": false, "translated": 0.9, "translatedPercentage": 90 }
},
"translated": 0.95,
"translatedPercentage": 95
}
},
"translated": 0.95,
"translatedPercentage": 95
}translatedPercentageis the figure in percent,translatedthe same figure as a fraction from 0 to 1.- A language code with a region (e.g.
de-CH) also carries"region": "CH". - The file is public and allows cross-origin requests, so you can also fetch it from your own code and show the figures any way you like.
Before you start
| You need | Where to find it |
|---|---|
| Project id | In your project settings in Locize; it is also part of every CDN URL of your project |
| CDN type | In your project settings in Locize; see CDN types: Standard vs. Pro |
| Version name (version and language badge) | Your project's versions, e.g. latest or production |
| Language code (language badge) | Your project's languages, exactly as in Locize, e.g. de or de-CH |
Nothing to enable:
- Every project has badge data as soon as it has translation statistics, i.e. after the first saved translation. No plan, add-on or setting is needed.
- Publishing is not required: saving translations already updates the badge data.
- The badge data stays public even when your translations are published as private downloads. It contains your version names, language codes and names, and the progress figures; no keys and no translations.
The badge URL
https://img.shields.io/badge/dynamic/json?url={badgeDataUrl}&query={query}&label=Locize&suffix=%25%20translated| Parameter | Required | Value | Default |
|---|---|---|---|
url | yes | the badge data URL of your project (see above) | |
query | yes | which figure to show (see the next table) | |
label | no | text on the left, e.g. Locize | custom badge |
prefix | no | text before the figure, e.g. de%3A%20 for de: | none |
suffix | no | text after the figure, e.g. %25%20translated for % translated | none, the bare number (e.g. 95) |
color | no | colour of the right part: hex without # (e.g. 2096F3) or a colour name | blue |
labelColor | no | colour of the left part | grey |
style | no | flat, flat-square, plastic, for-the-badge or social | flat |
cacheSeconds | no | how long shields.io caches the badge; values below its default are ignored | set by shields.io |
- Write texts URL-encoded:
%25for%,%20for a space,%3Afor:. - shields.io offers a few more parameters, e.g. a logo; see the Dynamic JSON Badge documentation.
Which figure (query):
| Badge | query (readable) | query (URL-encoded, ready to paste) |
|---|---|---|
| Project | $.translatedPercentage | %24.translatedPercentage |
| Version | $.versions['production'].translatedPercentage | %24.versions%5B'production'%5D.translatedPercentage |
| Language | $.versions['production'].languages['de'].translatedPercentage | %24.versions%5B'production'%5D.languages%5B'de'%5D.translatedPercentage |
Replace production and de with your version name and language code. Keep the brackets and quotes: they also work for names with dots or hyphens, such as v1.2 or de-CH.
Copy-ready snippets
Replace YOUR_PROJECT_ID with your project id. The snippets use the Standard CDN; on the Pro CDN, use api.locize.app instead of api.lite.locize.app.
Markdown (e.g. a README on GitHub or GitLab):
[](https://www.locize.com)HTML:
<a href="https://www.locize.com">
<img src="https://img.shields.io/badge/dynamic/json?url=https://api.lite.locize.app/badgedata/YOUR_PROJECT_ID&query=%24.translatedPercentage&label=Locize&suffix=%25%20translated&color=2096F3&style=plastic" alt="Translation progress">
</a>- The link around the image is up to you: your Locize project, your contribution guide for translators, or the Locize website. The shields.io
linkparameter does not work in an<img>tag or in Markdown, so wrap the image in a link instead. color=2096F3andstyle=plasticgive the look of Locize; leave them out for the shields.io defaults.
Examples
Both examples use a public Locize demo project on the Pro CDN.
Version badge for the version production:
Language badge for German (de) in the version production:
For one badge per language, repeat the language badge with each language code.
Updates and caching
- Locize rewrites the badge data when translations are saved and when a version is published.
- The badge can lag behind the dashboard by up to about an hour: the CDN caches the badge data for up to one hour, and shields.io and GitHub cache the image as well.
Troubleshooting
| The badge shows | Cause | Fix |
|---|---|---|
no result | The version name or language code does not exist (check spelling and case), the Pro CDN host is used for a Standard CDN project, or a Pro CDN project has no badge data yet | Correct the name, use api.lite.locize.app, or save a translation once |
resource not found | The Standard CDN host is used for a Pro CDN project, or a Standard CDN project has no badge data yet | Use api.locize.app, or save a translation once |
custom badge: 95 | label and suffix are missing | Add &label=Locize&suffix=%25%20translated |
| An old figure | Caching | Wait up to an hour |
Open the badge data URL in the browser to see which case applies.