Quick translation for a few custom menu items?

AI-generated summary

The discussion revolves around translating custom menu items in the Hamburger menu using the Discourse API. tophee asks how to easily provide translations for custom menu items in multiple locales without creating a full plugin. eviltrout explains that I18n.t('some.key') can be used for translations, but these keys won’t appear in the admin interface unless defined in a plugin. cpradio suggests manually adding translations in the I18n.translations object for each language, such as I18n.translations.en.js.filters.tags = { title: "Tags", help: "View all Tags" };, replacing en with the appropriate language code. tophee seeks clarification on the correct file path for this code, and cpradio asks for the specific code used to add items to the Hamburger menu, referencing a guide tophee shared.

When I add a custom menu item, say to the Hamburger menu, is there an easy way to provide translations for those items for a couple of locales?

I’d assume that this has come up before but I don’t seem to come up with the right search terms…

How are you adding the custom menu item? Is it using our plugin api? If so there is probably a syntax I can share to help you do this.

I am on phone-only these days and can’t seem to be able to copy code out of the theme editor :confused: to paste here, but I think the answer is yes, I’m using the api (api.decorateWidget).

If you’re using api.decorateWidget you can call I18n.t('some.key') and it’ll be translated using our internal system.

Unfortunately that key will not show up in the admin > customize > text content because it doesn’t already exist.

Your best bet is to create a plugin to do this. Plugins can define new translations.

1 лайк

Thanks for the advice. I’m afraid it’s a bit of an overkill to create a plugin to translate a couple of terms into a couple of languages.

Actually, maybe there is a misunderstanding? I am not looking for the actual translations (I can do those myself for the time being) but for a way of having these translated words displayed if a user has selected the respective locale.

You would just have the following lines per language right?

  I18n.translations.en.js.filters.tags = { title: "Tags", help: "View all Tags" };
  I18n.translations.en.js.filters.unanswered = { title: "Unanswered", help: "View all Unanswered Topics" };

You would need to put in the correct paths, but the en would get replaced with each language variant.

3 лайка

Could you explain a bit more? What would be an example of a “right path”?

You would just copy the en version and replace “en” with the appropriate language identifier, such as, fa_ir

1 лайк

Okay, then my question is rather, where do I find this code:

In the custom JavaScript you used to create the hamburger menu item? … What code did you use to add items to the Hamburger Menu? (that may be the better question here)

This:

https://meta.discourse.org/t/how-to-edit-hamburger-menu-items/22167/11?u=tophee

1 лайк