I’ve got an “Article” content type with Internationalization enabled, however, when trying to fill my english version I don’t see the “Fill in from another locale” as it is with my “Product” content type. Any idea where I should look at ?
While I’ve found the solution, I’ve also created a python script to duplicate an entry from one local to another. I’m posting it here in case it could be useful to someone who need a scriptable tool.
import requests
import json
import sys, getopt
urlBase = "COPY HERE YOUR STRAPI URL BASE: https://strapi.mydomain.com/api"
token = "COPY HERE YOUR API KEY WITH WRITE ACCESS"
# ---------------
# --- duplicate
# ---------------
def duplicate(contentType, id, source, target):
url = urlBase +"/"+contentType+"s/"+id
print(url)
parameters = {"locale" : source, "populate" : "*"}
headers = {"Authorization": "Bearer "+token}
reponse = requests.get(url,params=parameters, headers=headers)
data = reponse.json()
print(json.dumps(data,indent=4))
# --- manipulate the data
data["data"]["attributes"]["locale"]=target
del data["data"]["attributes"]["createdAt"]
del data["data"]["attributes"]["updatedAt"]
del data["data"]["attributes"]["publishedAt"]
# --- create the same data for new locale
url = urlBase +"/"+contentType+"s/"+id+"/localizations"
reponse = requests.post(url,headers=headers,json=data["data"]["attributes"])
print(json.dumps(data,indent=4))
###############################
# --- MAIN
################################
def main(argv):
opts, args = getopt.getopt(argv,"hc:i:s:t:",["contentType=","contentTypeId=","localeSource=","localeTarget="])
for opt, arg in opts:
if opt == '-h':
print ('''python strapi-duplicate.py --contentType (or -c) <contentType> --contentTypeId (or -i) <id> --localeSource (or -s) <locale> --localeTarget (or -t) <locale>
ex: python strapi-duplicate.py -contentType article -contentTypeId 1 -localeSource fr -localeTarget en ''')
sys.exit()
elif opt in ("-c", "--contentType"):
contentType = arg
elif opt in ("-i", "--contentTypeId"):
id = arg
elif opt in ("-s", "--localeSource"):
source = arg
elif opt in ("-t", "--localeTarget"):
target = arg
else:
print("Error: unknown option "+opt)
sys.exit(1)
duplicate(contentType, id, source, target)
###############
# --- bootstrap to run as a script
###############
if __name__ == "__main__":
main(sys.argv[1:])
And some usage exemples :
python strapi-duplicate.py -h
python strapi-duplicate.py -c article -i 1 -s fr -t de
python strapi-duplicate.py -contentType article -contentTypeId 1 -localeSource fr -localeTarget en
This is not a good solution for me. Have you tried this with collection types with fields that are non localized? Meaning fields that should be the same for all localization.
In my case, I have a bunch (eg, images that should be shared accross all localizations). So, if I move forward with your suggestion, I end up loosing all values on fields that are not localized, and it’s very frustrating. I’ll expand the steps you outlined:
with the content manager go to the content type for which you want to duplicate the content for another language
make sure a non-localized field exists on that collection type
select the language on the drop down list in the right side
click right away on save
**** Note how you already loosed data on non-localized fields from the original language ****
the “fill in from another locale” appears
click on it
localized fields (the remaining ones) will be copied over to the new language
—> Conclusion: Data is lost
Anyone experiencing the same? I’m currently on strapi 4.14.4
Thanks
Hi @roygardo ,
It was already strange to me that a save is a required step to see the “Fill in from another Locale”.
It’s even more strange when you tell me that unlocalized fields are re-initialized.
What I understand is that when clicking on “Fill in from another Locale”, the unlocalized fields are then not filled in ?
Probably a good topic for the Strapi’s developers.
A workaround I found, while this issue remains unresolved, is to use the REST API to create every localized version. This approach does not overwrite existing data in the original language. When you open it, the ‘Fill with another locale’ button is available. By clicking on it, you can populate the common elements. After that, you can edit the localizable fields with the translations!