This project will use the Weblate API to fetch the current translated percent for the CircuitPython project into different languages and display it along with a progress bar illustration.

If you're having difficulty running this example, it could be because your MagTag CircuitPython firmware or library needs to be upgraded! Please be sure to follow to install the latest CircuitPython Firmware and then also replace/update ALL the MagTag-specific libraries mentioned here

Custom Font

This project script uses two custom bdf font files. Download the full project zip in the code block below and copy leaguespartan18.bdf and leaguespartan11.bdf into the /fonts directory on your CIRCUITPY drive. Create the fonts directory if it doesn't exist yet. Copy into the main (root) directory of the CIRCUITPY drive.

# SPDX-FileCopyrightText: 2020 Tim C, written for Adafruit Industries
# SPDX-License-Identifier: Unlicense
Pull the current translated percent of CircuitPython
from Weblate and show it on the screen with text
and a progress bar.

Copy leaguespartan18.bdf and leaguespartan11.bdf
into fonts/ on your CIRCUITPY drive.
from adafruit_magtag.magtag import MagTag
from adafruit_progressbar.progressbar import ProgressBar

# Set up where we'll be fetching data from
NAME_LOCATION = ["name"]
PERCENT_LOCATION = ["translated_percent"]
URL_LOCATION = ["url"]

magtag = MagTag(

# name
        ( // 2) - 1,
    text_anchor_point=(0.5, 0.5),

# percentage
def textpercent_transform(val):
    return "Translated: {}%".format(val)

        ( // 2) - 1,
    text_anchor_point=(0.5, 0.5),

def texturl_transform(val):
    return val.replace("https://", "")  # remove known prefix!

        ( // 2) - 1,
        ( - 8,
    text_anchor_point=(0.5, 1.0),

# set progress bar width and height relative to board's display
BAR_WIDTH = - 80

BAR_X = // 2 - BAR_WIDTH // 2
BAR_Y = 66

# Create a new progress_bar object at (x, y)
progress_bar = ProgressBar(
    BAR_X, BAR_Y, BAR_WIDTH, BAR_HEIGHT, 1.0, bar_color=0x999999, outline_color=0x000000

timestamp = None

    value = magtag.fetch()
    print("Response is", value)
    progress_bar.progress = value[1] / 100.0
    magtag.exit_and_deep_sleep(24 * 60 * 60)  # one day
except (ValueError, RuntimeError) as e:
    print("Some error occurred, retrying! -", e)
    magtag.exit_and_deep_sleep(60)  # one minute

Code Overview

The MagTag library handles the text once it is up. Initialize it with the Weblate API url and data path to the translated percent value. The API returns back JSON data like this:

    "total": 14688,
    "total_words": 79509,
    "last_change": "2020-11-26T23:24:10.488034Z",
    "recent_changes": 142,
    "translated": 9141,
    "translated_words": 48720,
    "translated_percent": 62.2,
    "translated_words_percent": 61.2,
    "translated_chars": 286810,
    "translated_chars_percent": 61.3,
    "total_chars": 467279,
    "fuzzy": 82,
    "fuzzy_percent": 0.5,
    "failing": 99,
    "failing_percent": 0.6,
    "name": "CircuitPython",
    "url": ""

The program gets the translated_percent, url, and name values. Inside the main loop magtag.fetch() will return these values. It captures the results into a variable and then uses it to update the progress bar. The display must be refreshed after updating the progress.

The code uses the adafruit_magtag library to fetch the data from Weblate, and to show the text output on the display. The library creates its own displayio.Group internally that is shown on the display. Add a progress bar to that Group like this:

This guide was first published on Dec 02, 2020. It was last updated on Dec 02, 2020.

This page (Weblate Translated Percent) was last updated on May 15, 2022.

Text editor powered by tinymce.