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?

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.

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

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.

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

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?

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.

I solved this issue with a small plugin (GitHub - canbekcan/discourse-localized-badges · GitHub). You may create your own github with this and change the language files. You do not need migration but if you need check db folder, or remove db folder.

Plugin works as adding all language information into configlocales. There are some files and you may create your own language files. After you finished translate, you need to add your repo into app.yml (if you use docker) and then rebuild. As @nat mentioned above, just name new badges as badges.your_badge.name. It will automatically, show the normal name as you defined into the language files. Whenever you update your current language files, you may update from admin panel instead of rebuild the app.

You may check the structure of the files and make your own language files into locales folder, but files are so sensitive with spaces :slight_smile:

Note: This is my solution to the issue of badge languages. If there is a better one, I would like to hear :slight_smile: