Enjoy matching translated strings and their translation keys right in the GUI

AI 生成的摘要

The discussion introduces a new feature allowing users to enter “Translation Superman” mode, which displays translation keys alongside translated strings directly in the Discourse GUI. This tool benefits translators by helping them match strings to keys and aids developers by revealing where specific HTML is rendered within Handlebars templates, facilitating easier contributions to the codebase. Note that this feature is temporary unless configured otherwise. To enable it permanently, users can activate the verbose localization site setting. For a one-time session, they can run I18n.enableVerboseLocalizationSession() in the browser console. Once active, every translated string is logged in the browser console with a unique incremental number, which is also appended to the string itself on the page. This functionality resets upon reloading the page unless the permanent setting is enabled.

So, now you can enter the Translation Superman mode and see something like this:


What can we do with this?

  1. Match translated strings and their translation keys right in the GUI, which I hope is a good news for translators.

  2. Quickly find where a particular piece of HTML is rendered in Handlebards templates since almost every text is internationalized. This, I believe, is a good news for those who want to learn Discourse and contribute but finds it difficult to understand what is where. So you just get the translation key and find it in the Discourse codebase quickly in your favorite IDE.

This functionality is gone as soon as the Discourse tab is reloaded in your browser.

How to become the Translation Superman?

  1. For a permanent setting, go to site settings and enable verbose localization.

  2. For one-time session, enable it in console:
    I18n.enableVerboseLocalizationSession()
    From that point on when you reload the page you will get a localization session. Once you close the tab, it will go away.

  3. From now on, each time a single string is translated, 2 things will happen:
    a. The used translation key and corresponding translation options are logged in the browser console with a unique incremental number.
    b. The incremental number is appended to the translated string.

27 个赞