How can badges and groups be localized (multilingual)?

How can badges and groups be localized (multilingual)? During setup, I noticed that the titles of badges and groups do not switch with the theme language. How can I make badges and groups follow the theme switch?

3 Likes

The ability to localize custom badges and groups for a multilingual site doesn’t exist yet — at the moment only posts, categories, and tags can be localized.

Okay, thank you. But why is it that the badges on this website (meta.discourse.org) switch language along with the theme? Is that caused by a translation feature? I suggest that the official team add multilingual customization settings for badges, groups, and tags; otherwise, multilingual users cannot understand the content of badges, groups, and tags.

2 Likes

There are some seeded badges on every site that are internationalised (i18n) through Crowdin.

Custom badges store name/description as plain text in the database. When I18n.t (internationalization feature) is called with a key like badges.my_custom_badge.name, there’s no matching translation, so it falls back to the stored DB value — same text for all locales.

There’s a workaround where admins can manually add translations for custom badge keys per locale.

You can customize your site texts at <your site>/admin/customize/site_texts.


Some concrete steps for you

  1. Create the badge
  • Go to /admin/badges → New Badge
  • Set name, description, icon, etc. as normal
  1. Derive the i18n key
  • The key pattern is badges.{snake_case_name}.name
  • The snake_case_name is the badge name lowercased with spaces replaced by underscores
  • So ā€œPokĆ©mon Masterā€ → badges.pokĆ©mon_master.name
  1. Add translation overrides
  • Go to /admin/customize/site_texts
  • Search for badges.pokĆ©mon_master
  • You’ll see keys like:
    • badges.pokĆ©mon_master.name
    • badges.pokĆ©mon_master.description
    • badges.pokĆ©mon_master.long_description
  • Switch to the target locale (e.g. 简体中文), click the key, and enter the translated text
  1. Repeat per locale
  • Switch locale in the dropdown, add translations for each language you need
    • .name - badge title
    • .description - short description shown on badge cards
    • .long_description - full description shown on the badge detail page

english

japanese

4 Likes

Hi! Thanks for the reply! How is the second step, finding the ā€œi18n key,ā€ implemented? I couldn’t find the location of the i18n key.

1 Like

You don’t really ā€œfindā€ it, just derive it from the name you will give the badge. (Will update the second step to use ā€œderiveā€ instead of ā€œfindā€)

So if you use ā€œBug Finderā€ as the badge name, the key will be badges.bug_finder.name

1 Like

I don’t know why, but searching for anything in /admin/customize/site_texts always prompts ā€œNo matching site texts foundā€. Do you know what is causing this?

1 Like

Oh apologies, I need to correct my previous steps!

The site texts admin page (/admin/customize/site_texts) can only find keys that already exist in Discourse’s translation files. So unfortunately custom badge keys like badges.pokĆ©mon_master.name don’t exist there, and searching for them would return nothing (which is the issue you’re running into).

The screenshots I shared were from a setup where I created the translation entries via the Rails console. The admin UI steps I gave won’t work as written. Sorry about the confusion. What actually works if you have console access, you can create translation overrides for custom badges:

# the key pattern is: badges.{name_in_snake_case}.{name|description|long_description}
# e.g. for a badge called "Pokemon Master":
TranslationOverride.upsert!("zh_CN", "badges.pokemon_master.name", "å®åÆę¢¦å¤§åøˆ")
TranslationOverride.upsert!("zh_CN", "badges.pokemon_master.description", "ä½ ēš„ęčæ°")

Once created via console, the translation will appear in /admin/customize/site_texts and can be edited from there going forward.

If you don’t have console access, this currently not possible. Localizing custom badges isn’t supported yet as @awesomerobot had mentioned.

3 Likes