strapi-plugin-translate icon indicating copy to clipboard operation
strapi-plugin-translate copied to clipboard

TypeError: Cannot read properties of undefined (reading 'post')

Open fabioklr opened this issue 3 years ago • 8 comments

Describe the bug After clicking 'Translate from another locale' in the editor mode of a post on Strapi, I get the 'Warning: Failed to translate locale' message. Authentication with the DeepL API seems to be working.

To Reproduce Steps to reproduce the behavior:

  1. Go to the Content Manager
  2. Create a new post, article or another object of a collection, write content in one language
  3. Switch to another locale, click 'Translate from another locale', choose the locale the original content was written in.
  4. Click 'Yes, fill in' and see the rror

Expected behavior I would have expected the translated text to show up in the empty text field of the secondary locale.

System (please complete the following information):

  • OS: Debian Linux 11 bullseye
  • Browser: chrome
  • Versions:
    • strapi: 4.8.2
    • strapi-plugin-deepl: 0.4.2

Plugin config

module.exports = {
  deepl: {
      enabled: false,
      config: {
            apiKey: 'my-api-key',
            freeApi: true,
            translatedFieldTypes: [
            'string',
            'text',
            'richtext',
            'component',
            'dynamiczone',
          ],
            translateRelations: true,
            glossaryId: 'customGlossary',
          },
    },
}

Full error message

TypeError: Cannot read properties of undefined (reading 'post')
    at wn (main.1680c8bb.js:761:1007)
    at onClick (main.1680c8bb.js:3069:251)
    at Object.V (main.1680c8bb.js:807:9306)
    at dt (main.1680c8bb.js:807:9467)
    at Ke (main.1680c8bb.js:807:9529)
    at Lr (main.1680c8bb.js:807:28928)
    at Di (main.1680c8bb.js:807:29380)
    at main.1680c8bb.js:807:34770
    at Zt (main.1680c8bb.js:811:18950)
    at un (main.1680c8bb.js:807:8469)

Additional context I am running my Strapi app in a Docker container.

fabioklr avatar Mar 26 '23 21:03 fabioklr

Hi @fabioklr, looks like you are using the deprecated version strapi-plugin-deepl: 0.4.2. Can you please update to strapi-plugin-translate with the strapi-provider-translate-deepl and see if this fixes your issue? Instructions can be found here: https://github.com/Fekide/strapi-plugin-translate/wiki/Upgrade-instructions

layaxx avatar Mar 27 '23 10:03 layaxx

Thank you for replying. I have updated to the new plugin and the DeepL provider. Now I don't get the error message anymore. However, when I press 'Translate from another locale', then select the original language and press 'Yes, fill in', it fills in the text in the original language without translating it. There are no error messages in the console and I get a success message on the screen. Am I missing something here?

BTW, I saw the message on npmjs.com which says that the package is deprecated. A similar message on Strapi's market page might help. Anyway, thanks for your work.

fabioklr avatar Mar 27 '23 14:03 fabioklr

Maybe the provider was not set up correctly. When starting strapi, is there a warning in the console that says provider is set to dummy by default. This only copies all values? Also, when you go to the translate page at /admin/plugins/translate, do you see your deepl usage statistic?

layaxx avatar Mar 27 '23 15:03 layaxx

The only warning I get when starting Strapi is that a deprecated feature is used, namely the Expect-CT header. But I am not seeing the warning you mentioned.

I do see usage statistics but they are not the same as the ones I see on DeepL's 'Usage' tab in the DeepL account view.

My current plugin config:

module.exports = {
  translate: {
      enabled: true,
      config: {
            provider: 'deepl',
            providerOptions: {
            apiKey: 'DEEPL_API_KEY',
            apiUrl: 'https://api-free.deepl.com',
          },
            translatedFieldTypes: [
            'string',
            { type: 'text', format: 'plain' },
            { type: 'richtext', format: 'markdown' },
            'component',
            'dynamiczone',
          ],
            translateRelations: true,
          },
    },
}

Of course I inserted the actual API key.

fabioklr avatar Mar 29 '23 17:03 fabioklr

Interesting, at least for me usage statistics do match between what our plugin shows and what https://www.deepl.com/account/usage shows.

Anyway, your plugin config looks fine. Can you please provide additional information:

  • your versions after the update (at least strapi, translate plugin and provider)
  • what locale are you translating to/from?
  • what kind of fields does the contentType you want to translate have?
  • can you make sure the fields are set to translate in the options? (https://github.com/Fekide/strapi-plugin-translate#configure-behavior-of-automated-translation)

layaxx avatar Mar 29 '23 21:03 layaxx

Here is what helped me fix this problem: place provider config in 'config/plugins.js'

@layaxx

  • Strapi version: 4.8.2, Translate plugin version: 1.1.2, Provider version: 1.1.2
  • I am translating from German to English
  • It has the following fields: text, rich text, media, enumeration and date
  • I did make sure that the fields are set to translate from the beginning

@AlexandraKartashovaFusion I moved the plugins.js file to the config/ folder instead of having two files in the development/ and production/ folders but this lead to a 'credentials' error.

fabioklr avatar Apr 05 '23 18:04 fabioklr

Does your deepl API usage (as reported by https://www.deepl.com/account/usage and by the plugin) increase after the "translation"?

I can not reproduce this at the moment. If you want to narrow the problem down, you could start by cloning this repo and see if the same issue happens with the strapi instance in the playground folder.

layaxx avatar Apr 07 '23 20:04 layaxx