What's the best way to programmatically fetch (and write) customized text strings for translations?

There’s no need to keep track of anything on your site. You should be able to implement it stateless.

  • For polling, you need to send a GET request to the following path on your site:
    /admin/customize/site_texts.json?locale=en&overridden=true&page=0

    Adjust the locale parameter to your needs. The API returns up to 50 results and supports pagination (page parameter).
    The JSON will include { "extras" : { "has_more" : true } } when there are more results.

  • Updating a translation override works by sending a PUT request to the following path:
    /admin/customize/site_texts/<id>

    Replace <id> with the ID of the string you want to translate, e.g. “js.user.username.instructions”.

    The payload of the PUT request must be form data (Content-Type: application/x-www-form-urlencoded; charset=UTF-8) and must include the following attributes:

    • site_text[value]: the translation
    • site_text[locale]: the locale, e.g. “en”

Essentially you need to use the same API calls that the Customize Text admin interface uses.