Add custom locale in Strapi Admin
Strapi has a predefined list of available locales. These locales can be selected for content translation. The available list is defined inside a
JSON file available at this path of your strapi project:
Within the settings for the internationalization plugin the admin UI would allow for selecting locales, as shown here:
In case custom locales are required, e.g. for supporting special dialects, the JSON file could be edited and the admin UI needs to be rebuilt. In order to make this in a reproducible way, the patch-package node package can be used.
The following steps are required to achieve this:
- Within the strapi project the
patch-packagepackage can be installed with
npm i patch-package --save-dev.
"postinstall": "patch-package"within the
- Edit the
iso-locales.jsonfile found on the path given above according to your requirements
- Apply the patch with the command
npx patch-package @strapi/plugin-i18n
Within the project folder of the strapi project a
patches folder was created. This folder can be added to git. The
postinstall lifecycle script inside
package.json would be triggered on every
npm install execution. This makes the chagnes in
node_modules reproducible and by that the custom locales available inside the strapi admin.