Find a translation key with verbose localization

Discourse allows you to customize all user facing text from your site’s Admin / Customize / Text page. In most cases, you can find the correct text to customize by copying the text you wish to update from the Discourse UI into the search box on the Text page. In some cases, it can be difficult to find the correct translation key. This is especially true if you would like to translate text that occurs in many places in the UI. For these cases, the verbose localization site setting can help you to find the text’s translation key.

Enabling the setting

Verbose localization can be enabled for all users on the site, or it can be enabled for an individual session. To enable the setting for all users, go to your site settings page and enable the verbose localization site setting.

To enable verbose localization for just your own session, open your browser’s web inspector on your Discourse site and then go to its console tab. At the javascript prompt, enter:

I18n.enableVerboseLocalizationSession()

You should then see something like this in the console:

image

The advantage of enabling the setting from the console is that other users on your site will not see the translation numbers when they visit the site.

Using verbose localization to find a translation key

When verbose localization is enabled you will see numbers displayed after all of your site’s customizable text:

You can use these numbers, along with your web inspector’s console, to find the translation keys for the text you wish to customize. For example, to customize text that relates to a user’s real name, browse to a place in the Discouse UI that contained the “Name” text that you want to update:

Then look for the corresponding translation number in your browser’s javascript console:

This tells you that the translation key associated with the text “Name” is user.name.title. Now go to your Admin / Customize / Text page and enter the translation key into the search box:

Click the text’s Edit button and update the text.

22 Likes