Add documentation and source
Added documentation, source and extra files.
This commit is contained in:
30
source/translation/.idea/Translation.iml
generated
Normal file
30
source/translation/.idea/Translation.iml
generated
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="django" name="Django">
|
||||
<configuration>
|
||||
<option name="rootFolder" value="$MODULE_DIR$" />
|
||||
<option name="settingsModule" value="translation/settings.py" />
|
||||
<option name="manageScript" value="manage.py" />
|
||||
<option name="environment" value="<map/>" />
|
||||
<option name="doNotUseTestRunner" value="false" />
|
||||
<option name="trackFilePattern" value="" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.idea" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3 (training)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="PyDocumentationSettings">
|
||||
<option name="format" value="GOOGLE" />
|
||||
<option name="myDocStringFormat" value="Google" />
|
||||
</component>
|
||||
<component name="TemplatesService">
|
||||
<option name="TEMPLATE_CONFIGURATION" value="Django" />
|
||||
</component>
|
||||
</module>
|
12
source/translation/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
12
source/translation/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,12 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="GrazieInspection" enabled="false" level="TYPO" enabled_by_default="false" />
|
||||
<inspection_tool class="LanguageDetectionInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
|
||||
<option name="processCode" value="true" />
|
||||
<option name="processLiterals" value="true" />
|
||||
<option name="processComments" value="true" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
6
source/translation/.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
source/translation/.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
8
source/translation/.idea/modules.xml
generated
Normal file
8
source/translation/.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/translation.iml" filepath="$PROJECT_DIR$/.idea/translation.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
11
source/translation/.idea/workspace.xml
generated
Normal file
11
source/translation/.idea/workspace.xml
generated
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectViewState">
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showExcludedFiles" value="false" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="settings.editor.selected.configurable" value="configurable.group.tools" />
|
||||
</component>
|
||||
</project>
|
11
source/translation/README.md
Normal file
11
source/translation/README.md
Normal file
@ -0,0 +1,11 @@
|
||||
# Procedure for generating translations
|
||||
|
||||
1. Define the default language in your `settings.py`.
|
||||
1. All your strings should be in the default language.
|
||||
1. Optional: Define available languages by adding the `LANGUAGES` setting if you want.
|
||||
|
||||
# For a Django app
|
||||
|
||||
- Create `locale` directory in your Django app. Django won't create it by itself.
|
||||
- Check your app is registered in `INSTALLED_APPS`.
|
||||
- `makemessages -l <language>`
|
9
source/translation/birds/__init__.py
Normal file
9
source/translation/birds/__init__.py
Normal file
@ -0,0 +1,9 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class BirdsConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "birds"
|
||||
|
||||
|
||||
default_app_config = "birds.BirdsConfig"
|
1
source/translation/birds/admin/__init__.py
Normal file
1
source/translation/birds/admin/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .bird import BirdAdmin
|
15
source/translation/birds/admin/bird.py
Normal file
15
source/translation/birds/admin/bird.py
Normal file
@ -0,0 +1,15 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from birds.models import Bird
|
||||
|
||||
|
||||
@admin.register(Bird)
|
||||
class BirdAdmin(admin.ModelAdmin):
|
||||
"""
|
||||
Administration configuration for birds.
|
||||
|
||||
"""
|
||||
|
||||
list_display = ["id", "uuid", "vernacular_name", "scientific_name", "weight"]
|
||||
list_editable = ["vernacular_name", "scientific_name", "weight"]
|
||||
readonly_fields = ["uuid"]
|
92
source/translation/birds/locale/fr/LC_MESSAGES/django.po
Normal file
92
source/translation/birds/locale/fr/LC_MESSAGES/django.po
Normal file
@ -0,0 +1,92 @@
|
||||
# SOME DESCRIPTIVE TITLE.
|
||||
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||
# This file is distributed under the same license as the PACKAGE package.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2021-04-23 16:28+0200\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
"Language: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
||||
|
||||
#: birds/models/bird.py:13
|
||||
msgid "UUID"
|
||||
msgstr "UUID"
|
||||
|
||||
#: birds/models/bird.py:14
|
||||
msgid "vernacular name"
|
||||
msgstr "nom courant"
|
||||
|
||||
#: birds/models/bird.py:15
|
||||
msgid "scientific name"
|
||||
msgstr "nom scientifique"
|
||||
|
||||
#: birds/models/bird.py:16
|
||||
msgid "weight"
|
||||
msgstr "poids"
|
||||
|
||||
#: birds/models/bird.py:17
|
||||
msgctxt "bird (adjective)"
|
||||
msgid "extinct"
|
||||
msgstr "disparu"
|
||||
|
||||
#: birds/models/bird.py:20
|
||||
msgid "bird"
|
||||
msgstr "oiseau"
|
||||
|
||||
#: birds/models/bird.py:21
|
||||
msgid "birds"
|
||||
msgstr "oiseaux"
|
||||
|
||||
#: birds/templates/birds/translation-page.html:7
|
||||
msgid "example page"
|
||||
msgstr "page d'exemple"
|
||||
|
||||
#: birds/templates/birds/translation-page.html:11
|
||||
msgid "The crazy dog"
|
||||
msgstr "Le chien fou"
|
||||
|
||||
#: birds/templates/birds/translation-page.html:12
|
||||
msgctxt "task completion"
|
||||
msgid "done"
|
||||
msgstr "terminée"
|
||||
|
||||
#: birds/templates/birds/translation-page.html:13
|
||||
#, fuzzy, python-format
|
||||
#| msgid "The page title is %(text_title)s."
|
||||
msgid "The page title is %(str_title)s."
|
||||
msgstr "Le titre de la page est %(str_title)s."
|
||||
|
||||
#: birds/templates/birds/translation-page.html:15
|
||||
#, fuzzy, python-format
|
||||
#| msgid ""
|
||||
#| "\n"
|
||||
#| " There is %(counter)s bird on the roof.\n"
|
||||
#| " "
|
||||
#| msgid_plural ""
|
||||
#| "\n"
|
||||
#| " There are %(counter)s birds on the roof.\n"
|
||||
#| " "
|
||||
msgid ""
|
||||
"\n"
|
||||
" There is %(counter)s bird on the roof.\n"
|
||||
" "
|
||||
msgid_plural ""
|
||||
"\n"
|
||||
" There are %(counter)s birds on the roof.\n"
|
||||
" "
|
||||
msgstr[0] ""
|
||||
"\n"
|
||||
"Il y a %(counter)s oiseau sur le toit."
|
||||
msgstr[1] ""
|
||||
"\n"
|
||||
"Il y a %(counter)s oiseaux sur le toit."
|
30
source/translation/birds/migrations/0001_initial.py
Normal file
30
source/translation/birds/migrations/0001_initial.py
Normal file
@ -0,0 +1,30 @@
|
||||
# Generated by Django 3.2 on 2021-04-15 16:24
|
||||
|
||||
from django.db import migrations, models
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Bird',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('uuid', models.UUIDField(default=uuid.uuid4, verbose_name='UUID')),
|
||||
('vernacular_name', models.CharField(max_length=64, unique=True, verbose_name='vernacular name')),
|
||||
('scientific_name', models.CharField(max_length=64, unique=True, verbose_name='scientific name')),
|
||||
('weight', models.PositiveIntegerField(default=100, verbose_name='weight')),
|
||||
('is_extinct', models.BooleanField(default=False, verbose_name='extinct')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'bird',
|
||||
'verbose_name_plural': 'birds',
|
||||
},
|
||||
),
|
||||
]
|
0
source/translation/birds/migrations/__init__.py
Normal file
0
source/translation/birds/migrations/__init__.py
Normal file
1
source/translation/birds/models/__init__.py
Normal file
1
source/translation/birds/models/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .bird import Bird
|
22
source/translation/birds/models/bird.py
Normal file
22
source/translation/birds/models/bird.py
Normal file
@ -0,0 +1,22 @@
|
||||
from uuid import uuid4
|
||||
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _, pgettext_lazy
|
||||
|
||||
|
||||
class Bird(models.Model):
|
||||
"""
|
||||
Bird definition.
|
||||
|
||||
"""
|
||||
|
||||
uuid = models.UUIDField(default=uuid4, verbose_name=_("UUID"))
|
||||
vernacular_name = models.CharField(max_length=64, unique=True, verbose_name=_("vernacular name"))
|
||||
scientific_name = models.CharField(max_length=64, unique=True, verbose_name=_("scientific name"))
|
||||
weight = models.PositiveIntegerField(default=100, verbose_name=_("weight"))
|
||||
is_extinct = models.BooleanField(default=False, verbose_name=pgettext_lazy("bird (adjective)", "extinct"))
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("bird")
|
||||
verbose_name_plural = _("birds")
|
||||
app_label = "birds"
|
@ -0,0 +1,22 @@
|
||||
{% load i18n %}
|
||||
{# Context: bird_count (int) #}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
{% translate "example page" as str_title %}
|
||||
<title>{{ str_title|title }}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{% translate "The crazy dog" %}</h1>
|
||||
<p>Task status: {% translate "done" context "task completion" %}</p>
|
||||
<p>{% blocktranslate %}The page title is {{ str_title }}.{% endblocktranslate %}</p>
|
||||
<p>
|
||||
{% blocktranslate count counter=bird_count %}
|
||||
There is {{ counter }} bird on the roof.
|
||||
{% plural %}
|
||||
There are {{ counter }} birds on the roof.
|
||||
{% endblocktranslate %}
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
3
source/translation/birds/tests.py
Normal file
3
source/translation/birds/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
1
source/translation/birds/views/__init__.py
Normal file
1
source/translation/birds/views/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .base import *
|
9
source/translation/birds/views/base.py
Normal file
9
source/translation/birds/views/base.py
Normal file
@ -0,0 +1,9 @@
|
||||
from annoying.decorators import render_to
|
||||
from django.conf import settings
|
||||
from django.http import HttpRequest
|
||||
|
||||
|
||||
@render_to("birds/translation-page.html")
|
||||
def view_translation_page(request: HttpRequest) -> dict:
|
||||
print(settings.LANGUAGES)
|
||||
return {"bird_count": 1}
|
BIN
source/translation/database.sqlite3
Normal file
BIN
source/translation/database.sqlite3
Normal file
Binary file not shown.
22
source/translation/manage.py
Normal file
22
source/translation/manage.py
Normal file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "translation.settings")
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
0
source/translation/translation/__init__.py
Normal file
0
source/translation/translation/__init__.py
Normal file
16
source/translation/translation/asgi.py
Normal file
16
source/translation/translation/asgi.py
Normal file
@ -0,0 +1,16 @@
|
||||
"""
|
||||
ASGI config for translation project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "translation.settings")
|
||||
|
||||
application = get_asgi_application()
|
143
source/translation/translation/settings.py
Normal file
143
source/translation/translation/settings.py
Normal file
@ -0,0 +1,143 @@
|
||||
"""
|
||||
Django settings for translation project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 3.2.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/3.2/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/3.2/ref/settings/
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = "django-insecure-r=!!xd$ss4&14j#pj&!@w0ks!x@6-t*f*v03iu+a+)rjqza$@z"
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"django_extensions",
|
||||
"birds",
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
"django.middleware.security.SecurityMiddleware",
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
"django.middleware.csrf.CsrfViewMiddleware",
|
||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
"django.middleware.locale.LocaleMiddleware", # Added to enable translation in views
|
||||
]
|
||||
|
||||
ROOT_URLCONF = "translation.urls"
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": [],
|
||||
"APP_DIRS": True,
|
||||
"OPTIONS": {
|
||||
"context_processors": [
|
||||
"django.template.context_processors.debug",
|
||||
"django.template.context_processors.request",
|
||||
"django.contrib.auth.context_processors.auth",
|
||||
"django.contrib.messages.context_processors.messages",
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = "translation.wsgi.application"
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": BASE_DIR / "database.sqlite3",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
# {
|
||||
# "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
||||
# },
|
||||
{
|
||||
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
|
||||
},
|
||||
{
|
||||
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
|
||||
},
|
||||
{
|
||||
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/3.2/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = "en-us"
|
||||
|
||||
TIME_ZONE = "UTC"
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/3.2/howto/static-files/
|
||||
|
||||
STATIC_URL = "/static/"
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||
|
||||
# Media paths
|
||||
|
||||
MEDIA_URL = "/media/"
|
||||
MEDIA_ROOT = BASE_DIR / "media"
|
||||
|
||||
# Caching setup
|
||||
CACHES = {
|
||||
"default": {
|
||||
"BACKEND": "django.core.cache.backends.memcached.PyMemcacheCache",
|
||||
"LOCATION": "127.0.0.1:11211",
|
||||
}
|
||||
}
|
26
source/translation/translation/urls.py
Normal file
26
source/translation/translation/urls.py
Normal file
@ -0,0 +1,26 @@
|
||||
"""translation URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/3.2/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
|
||||
from birds.views import view_translation_page
|
||||
|
||||
urlpatterns = [
|
||||
path("admin/", admin.site.urls),
|
||||
path("", view_translation_page),
|
||||
]
|
16
source/translation/translation/wsgi.py
Normal file
16
source/translation/translation/wsgi.py
Normal file
@ -0,0 +1,16 @@
|
||||
"""
|
||||
WSGI config for translation project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "translation.settings")
|
||||
|
||||
application = get_wsgi_application()
|
Reference in New Issue
Block a user