How to override plugin translations?

Hello there!

I am trying to override “strapi-plugin-content-type-builder” translation files without modifying node_modules folder.

And for that, I have created “\extensions\strapi-plugin-content-type-builder\admin\src\translations” directory and added the modified language files in it in json format, also made an index.js like this one:

import en from './en.json';
import tr from './tr.json';

const trads = {
  en,
  tr
};

export default trads;

But it didn’t work. I still see the original translations that was is the json files in “node_modules\strapi-plugin-content-type-builder\admin\src\translations”

How can I override the original json files with the new ones? Thanks.

1 Like

So anyone?

Hi,

As soon as you want to extend an existing plugin you have to create a folder in the extensions folder. This folder should be named by the plugin ID: Strapi plugins - Strapi Developer Documentation

In your case I think that the strapi-plugin-content-type-builder ID is content-type-builder

1 Like

It worked! Thank you.

1 Like

Can you check the answer as a solution in order to help other people who have this kind of “issue” :wink:

Hi,

I’m using latest version of Strapi v4.1.11 and created following structure of content-type-builder extension:

Screenshot from 2022-05-16 09-51-25

pl.json:

{
  "plugin.name": "Modelowanie danych"
}

index.js:

import pl from './pl.json';

const trads = {
  pl,
};

export const languageNativeNames = {
  pl: 'Polski',
};

export default trads;

It still doesn’t override translation, even though I have content-type-builder directory name. I tried it with different keys in json, and it doesn’t work as well.

Did the override system changed in the newest version or am I doing something wrong? Thanks

1 Like

Hello

Did you find a solution to this
Simply overriding default structure from the repo in “extensions” directory doesn’t seem to work at all

Same here, I’m trying to override a script in the content-manager.

image

oh, I’ve found it!

It is written in the documentation:

You don’t need to recreate the file structure of the plugin. Instead, you override the controllers etc. in the strapi-server.js.

1 Like

It is still not clear to me how to override strapi plugin locales. Did anyone manage to succeed?

For strapi@4.x, you can override it like this. Then run npm run build before you run npm run develop

const config = {
    locales: [
      'en',
      'zh-Hans',
      'zh',
    ],
    translations: {
      'zh-Hans': {
        "content-type-builder.plugin.name": "类型创建器",
      },
    },
  };
  
  const bootstrap = (app) => {
    console.log(app);
  };
  
  export default {
    config,
    bootstrap,
  };
  

Refer to this doc: https://docs.strapi.io/dev-docs/admin-panel-customization#locales

Hi all,

this prefix with plugin name for each key-value pair really works.

Remark - I am adding “hr” (Croatian) language into the languageNativeNames.js via patch-package.

As a proof of concept, I tried this in app.js

import hr_plugin_upload from "./extensions/translations/hr-plugin-upload.json"

const keys = Object.keys(hr_plugin_upload)
let hr_plugin_upload_ex = {}
keys.forEach(k => {
  hr_plugin_upload_ex["upload." + k] = hr_plugin_upload[k]
})

And then:

export default {
  config: {
    locales: [
      'en', 'hr'
    ],
    translations: {
      'en': {
        // ...en,
        ...en_edit_views,
        ...en_custom
      },
      'hr': {
        ...hr,
        ...hr_edit_views,
        ...hr_custom,
        ...hr_plugin_upload_ex
      }
    }
  },
...

Finally! :slight_smile:

Now “only” table column names and enumeration values are not translated - but this is another problem.