Quick translation for a few custom menu items?

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 Like

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 Likes

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 Like

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 Like