Unable to add a new language for the admin ui

Hi. I recently had to add an unsupported admin panel language in Strapi.
I found out that even though we can define custom lang in the config.locales and add translations in the config.translations, we still are unable to show that custom language as its definition is missing in the languageNativeNames const.
So my workaround, although a rough one, was to clone the ./node_modules/@strapi/admin/admin/src/translations/languageNativeNames.js file, add my missing custom lang, add the file in the extended translations dir (./src/admin/extensions/translations), in my case bg,

const languageNativeNames = {
  ar: 'العربية',
  bg: 'Български',
  cs: 'Čeština',

and then replace that file in the node_modules where it is originally defined.
Now, node_modules of course will be overridden quite often, so I added an npm command that runs with my develop and build commands.

"scripts": {
    "translate": "cp -a ./src/admin/extensions/translations/. ./node_modules/@strapi/admin/admin/src/translations",
    "develop": "npm run translate && npm run strapi develop",
    "start": "strapi start",
    "build": "npm run translate && npm run strapi build",
    "strapi": "strapi"
  },

And my ./src/admin/app.js has the following structure:

export default {
  config: {
    locales: ['bg'],
    translations: {
      bg: {
        "Auth.form.welcome.title": "Добре дошли!"
      }
    },
    bootstrap(app) {
      console.log(app);
    },
  }
};

I went event further and copied an original translation file en.json, named it bg.json (translated it, or started at least) and I copy it to the ./node_modules/@strapi/admin/admin/src/translations folder each time when I run my custom translate command.

As I find this solution far from perfect, at least I hope it can give an option to someone who really needs supporting a custom language in the Strapi admin.

If there is a better way or I have missed something from the documentation, please let me know.

So now my admin panel looks like that:

3 Likes