This guide is intended for unix based OS, the script provided won't work on Windows terminal. If you'd like to contribute to improve and complete this guide, please write to us on the chat.
You can use the Import module to copy documents from a locale to another. Let's take the example where you want to duplicate all documents of the locale "en-us" into the "fr-fr" locale.
The Export module lets you download JSON files for your published document. The Import module allows you to import translations for existing documents. To achieve this, you need to import JSON files with this naming convention:
Plus the JSON files need to hold the target locale code, i.e.,
The example below will help you bulk duplicate documents from a locale to another by:
- quickly isolating the exported JSON documents for the source locale (i.e., en-us)
- bulk changing the value of the lang property (basically bulk editing the JSON file to replace
- renaming JSON files in bulk with the expected file naming convention, so it can be imported as translations of existing documents
Going back to our example, to duplicate all documents of the locale "en-us" into the "fr-fr" locale:
1. First thing if not done yet, create the "fr-fr" locale from the settings of your repository.
2. Head to the settings, export your repository content: you will get a ZIP archive containing a JSON file for each published documents in your repository.
3. If you already have content in multiple languages in your repository, you might want to isolate the JSON files of the main locale (in our example, say "en-us"). As you cannot filter while exporting from the Prismic UI, you'll have to run this simple command locally to isolate "en-us" document into a specific folder.
4. Install "json" (a CLI tool to work with JSON):
npm install -g json
5. Create a file with this script in the local folder where the JSON files you want to copy are stored, call it
sed -i '' -e 's/"lang":"en-us"/"lang":"fr-fr"/g' *.json
for filename in ./*.json; do
grouplang=$(json -f $filename grouplang)
mv "$filename" "$prefix$grouplang$targetlocale$filetype"
5. Allow execution of this script
chmod +x localize.sh
6. Run the script:
Your files should be renamed and look like this:
7. If you don't have any documents in the locale you're bulk importing in, you can go directly to the step 12.
If you have existing documents in the locale you're bulk importing in, you'll have to override these documents with the new version you just created at the step 6.
We'll have to rename these new JSON files that we just created with the existing document JSON filename in order to import them in Prismic.
8. Copy these new files in the parent folder where the other exported files are.
9. Create a file
override_existing_translation.sh in the parent folder and copy paste the following script.
for filename in ./translate_*.json; do
grouplang=$(json -f $filename grouplang)
locale=$(json -f $filename lang)
for filename2 in ./X*.json; do
grouplang2=$(json -f $filename2 grouplang)
locale2=$(json -f $filename2 lang)
if [ $grouplang = $grouplang2 ] && [ $locale = $locale2 ]
newName = $filename2
mv "$filename" "$filename2"
10. Allow execution of this script
chmod +x override_existing_translation.sh
11. Run the script:
The existing documents of your locale are now removed from your folder and the new translations are renamed as the previous existing documents.
12. Select all the files and compress them into a ZIP archive.
13. Head to the Import section of your repository, upload that archive, launch the import.
Imported documents are always staged into an import release. This helps you check the correctness of the import before publishing the release (have a careful check as you can not rollback the publication of a release).
Before publishing that release, check that the imported documents are correctly associated with the original version (just open some documents, and switch the language dropdown to verify it's associated with their corresponding "en-us" version)
Tip: translators could work on the duplicated documents directly into the Import release. Once they are done with the translation of one document, they can either publish it or move it into another release (for approval or preview purposes for instance).
If you'd like to contribute to improve and complete this guide, please write to us on the chat.