Package command as external app
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
f8b4c754a2
commit
cf878441b9
4 changed files with 3 additions and 53 deletions
|
@ -1,6 +1,6 @@
|
|||
#!/bin/bash
|
||||
python manage.py migrate
|
||||
python manage.py getlocales
|
||||
python manage.py loco
|
||||
python manage.py makemessages -l en -l de
|
||||
python manage.py compilemessages -f
|
||||
python manage.py getplzindex
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
import os
|
||||
import requests
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.utils.translation import trans_real
|
||||
from django.apps import apps
|
||||
from pflaenzli_django.settings import LOCO_API_KEY
|
||||
|
||||
API_URL = ' https://localise.biz/api/export/locale'
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Fetch translations from Loco (Localise.biz) and write them to message files'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
errors = 0
|
||||
|
||||
if LOCO_API_KEY is None or LOCO_API_KEY == '':
|
||||
self.stdout.write(self.style.ERROR('An API key is required'))
|
||||
return
|
||||
|
||||
app_config = apps.get_app_config('pflaenzli')
|
||||
app_path = app_config.path
|
||||
|
||||
for locale in trans_real.get_languages():
|
||||
url = f'{API_URL}/{locale}.po'
|
||||
self.stdout.write(f'Getting translations for locale {self.style.SUCCESS(locale)}')
|
||||
response = requests.get(url, auth=(LOCO_API_KEY, ''))
|
||||
|
||||
if response.status_code == 200:
|
||||
destination = f'{app_path}/locale/{locale}/LC_MESSAGES/django.po'
|
||||
self.stdout.write(f'Saving to {destination}')
|
||||
|
||||
os.makedirs(os.path.dirname(destination), exist_ok=True)
|
||||
|
||||
with open(destination, 'wb') as f:
|
||||
f.write(response.content)
|
||||
|
||||
self.stdout.write(self.style.SUCCESS(
|
||||
f'Locale {locale} successfully saved to {destination}\n'))
|
||||
|
||||
else:
|
||||
self.stdout.write(self.style.ERROR(
|
||||
f'There was an error processing the request to {url}: {response.status_code}\n'))
|
||||
errors += 1
|
||||
|
||||
if errors == len(trans_real.get_languages()):
|
||||
self.stdout.write(self.style.ERROR('No locales could be downloaded.'))
|
||||
elif errors > 1:
|
||||
self.stdout.write(self.style.WARNING('There were errors getting some locales.'))
|
||||
else:
|
||||
self.stdout.write(self.style.SUCCESS('All translations fetched and written to message files.'))
|
|
@ -50,6 +50,7 @@ INSTALLED_APPS = [
|
|||
"crispy_bootstrap5",
|
||||
"friendly_captcha",
|
||||
"django.contrib.sitemaps",
|
||||
"djangoloco",
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
crispy-bootstrap5==0.7
|
||||
Django==4.1.7
|
||||
djangoloco==1.0
|
||||
django-bootstrap5==22.2
|
||||
django-crispy-forms==2.0
|
||||
django-jquery==3.1.0
|
||||
|
|
Loading…
Reference in a new issue