# API 定制文本作用域

**URL:** https://meta.discourse.org/t/api-scope-for-customized-texts/303299
**Category:** Feature
**Created:** [2024年四月10日 20:38 UTC](https://meta.discourse.org/t/api-scope-for-customized-texts/303299 "2024-04-10T20:38:02Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![mattdm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mattdm/32/216484_2.png) [@mattdm](https://meta.discourse.org/u/mattdm)
#### Post date: [2024年四月10日 20:38 UTC](https://meta.discourse.org/t/api-scope-for-customized-texts/303299/1 "2024-04-10T20:38:02Z")

</div>

用例是与翻译同步 – 请参阅

> [@What's the best way to programmatically fetch (and write) customized text strings for translations?](https://meta.discourse.org/t/whats-the-best-way-to-programmatically-fetch-and-write-customized-text-strings-for-translations/258859/):
>
> I have used the web admin interface to change quite a few Discourse strings. Out of expediency[[1]](#footnote-1258700-1) I have ignored the non-English versions. This means, of course, that they’re out of sync. In Fedora, we use Weblate for community-powered translations. (See [https://translate.fedoraproject.org/](https://translate.fedoraproject.org/)). I’d love to hook this up, ideally so that there’s an entirely automatic workflow where when a string is updated in English via the admin interface, it is sent to Weblate, and when there is a translation, i…

我想提供一个可以读取和写入自定义文本的 API 密钥，但不能执行任何其他操作。

虽然读取所有覆盖的字符串可能没有害处，但最好还能根据主要语言（在我的例子中是英语）进一步限制写入。这将：

1. 禁止写入该语言的字符串
2. 仅当主要语言字符串不是默认值时，才允许写入其他语言的字符串
3. 允许将非主要语言的字符串重置为其默认值

（第三条规则允许重置，即使主要语言字符串已自定义；这将允许在出于某种原因需要删除翻译时删除它们。）

仅仅限制访问范围 `/admin/customize/site_texts` 将是一个不错的初步尝试。然而，对 `site_text[locale]` 写入甚至某些 `site_text[value]` 的进一步（可配置）限制最终似乎很重要，因为如果此类密钥泄露或被盗，它可能被用来涂污网站（或插入非常隐蔽的垃圾链接等）。
