Score:1

drupalTranslations is not defined

ec flag

I'm an Angular front-end developer. I work with a team that uses Drupal for content.

The scenario is that we use Drupal.t() to translate the strings.

When I translate the word from the back-office, it works, but I can't see the change on my page. So I tested it with another laptop from a colleague, and it works.

My colleague has drupalTranslations(), which gives him the translated strings.

When I run this function in my browser, it doesn't work. drupalTranslations() is not defined while Drupal and drupalSettings work.

Error Message

Do I have to install something?

FYI: We run the project with Docker (Drupal 9.x).

taggartJ avatar
cn flag
do you share a database ? or config ? do you have this module installed "Interface Translation" aka locale ?
Score:0
us flag

I'm able to replicate the issue on Drupal 9 with a simple javscript file

console.log(Drupal.t('Comments'))
console.log(Drupal.drupalTranslations('Comments'))

コメント
TypeError: Drupal.drupalTranslations is not a function

There appears to be an open issue (Text in Drupal.t() on some pages is not translated after installing a module [library cache problem]) related to this marked active but without progress since 2018. The issue relates to a caching bug.

I also found drupal-8-react-i18n-and-typescript which might help you along, but if you're using the same code as your colleague, I'm inclined to thing it is the cache bug.

Mario Steinitz avatar
id flag
Despite the original question being closed for not being detailed enough, you could improve your answer by providing e.g., a link to the open issue(s) you mentioned. This might help the original author of the question more than you just confirming that you can replicate the behavior and found related issues in the Drupal issue queues. Both of you are relatively new in this Drupal Answers group. It lives from to the point questions and answers that provide enough details to gain a solution for both, the original author, as well as future visitors.
tyler36 avatar
us flag
Thank you Mario. I copied my response to the same question on StackOverflow and it seems the links did not copy over. I updated my original answer with the missing URLs.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.