0

I need to translate certain text in a twig template to one of several languages, depending on the Language selected for the node being displayed. I've installed the Interface Translation module (without translation files because I don't want the interface translated) and added custom translations for the text I want translated. This works perfectly using {{ "text to translate"|t }} in the template.

Here's the problem: When I'm at a page like "/es/node/50" (Spanish), Drupal "shifts to /es mode" by adding /es to menu entries, admin links, etc. I assume this is expected, but I don't want it. I simply want to use Drupal's built-in translation capability (via |t) to translate things I specify. I don't want any other pages to get an /es prefix.

I want to select a language for a node and then have translation capacity for that node's template only, without affecting anything else in the site.

Is this simply outside the use case for the Interface Translation module? Or is there a combination of modules/settings to make it possible?

I've fiddled with this for hours (days) and have read documentation and many posts without success.

1

Drupal has very advanced Multi-lingual capabilities, so it's safe to assume that you can configure your site according to your needs. You just have to learn a bit about Drupal multilingual fundamentals and see how your needs fit in there.

It seems your question is about how languages are selected and displayed, and not about Interface translation. You probably already understand the difference between content and interface, and that the strings you put into the templates are part of the interface. And you probably want to be able to view content in different languages while keeping the interface language the same.

Under Configuration > Regional and language > Languages > Detection and selection you can choose to set that your Content language selection should work differently from the Interface language selection.

Enable that option Customize Content language detection to differ from Interface text language detection settings and then also enable the Content language Detection method (Determines the content language from a request parameter.) and it should be ordered to be your first enabled method.

This way you will be able to view Spanish nodes while keeping the English interface. This is happening through the parameter that is being added to the URL. Instead of:

/es/node/50

you will have:

/node/50?language_content_entity=es

With interface language kept as English, your menus and other links will lead to the English side of things, but you will be able to view translated content.

  • Thanks @prkos. I believe I tried most of what you suggest, but I never saw a url with ?language_content_entity=es on it, so I missed something. I'll give it another try. – Marshall Morrise Mar 22 at 17:33
  • Thanks again, @prkos. I should have mentioned that everything you surmise about my understanding and my goals in your second paragraph is correct. What I missed before is the part about the request parameter, so I'll give it another try. It seems like I should be able to install and use content translation without installing interface translation (since I don't want it), but having tried that, I couldn't see where I could input custom translations outside of the interface translation screens. – Marshall Morrise Mar 22 at 21:18
  • I haven't tried that particular combination, but I think you should be able to have Content translation without Interface translation. You'd always have English interface for example, but nodes/content could be translated, and I guess there would have to be special links how to view them. It may be that the Translate interface module is that fundamental you can't do without it, but since you mentioned translating strings from templates you definitely can't go without it. Strings in templates are part of the interface, they're not content. – prkos Mar 23 at 0:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.