UwU suppowt
This commit is contained in:
parent
bece878aa2
commit
43f7414573
6 changed files with 139 additions and 3 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,6 +7,7 @@ loadproduction.sh
|
|||
runtileserver.sh
|
||||
test.py
|
||||
test.svg
|
||||
en_UW
|
||||
|
||||
.idea
|
||||
|
||||
|
|
|
@ -69,6 +69,7 @@ RUN --mount=type=cache,target=/pip-cache \
|
|||
-r requirements/rsvg.txt \
|
||||
-r requirements/sentry.txt \
|
||||
-r requirements/metrics.txt \
|
||||
-r requirements/uwu.txt \
|
||||
-r requirements/server-asgi.txt && \
|
||||
pip install --cache-dir /pip-cache uwsgi
|
||||
|
||||
|
@ -94,7 +95,9 @@ ENV C3NAV_DEBUG="" \
|
|||
USER c3nav
|
||||
WORKDIR /app
|
||||
|
||||
RUN /app/env/bin/python manage.py compilemessages && \
|
||||
RUN /app/env/bin/python manage.py makemessages -l en_UW && \
|
||||
/app/env/bin/python genuwu.py && \
|
||||
/app/env/bin/python manage.py compilemessages && \
|
||||
/app/env/bin/python manage.py collectstatic -l --no-input && \
|
||||
/app/env/bin/python manage.py compress && \
|
||||
rm -r /data/*
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import json
|
||||
import logging
|
||||
import re
|
||||
import typing
|
||||
from itertools import chain
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
|
@ -19,6 +21,30 @@ from c3nav.mapdata.utils.json import format_geojson
|
|||
|
||||
logger = logging.getLogger('c3nav')
|
||||
|
||||
if "en-UW" in settings.SELECTED_LANGUAGES:
|
||||
from uwuipy import Uwuipy
|
||||
uwu = Uwuipy(
|
||||
stutter_chance=0,
|
||||
face_chance=0,
|
||||
action_chance=0,
|
||||
exclamation_chance=0,
|
||||
nsfw_actions=False,
|
||||
power=4,
|
||||
)
|
||||
uwu_more = Uwuipy(
|
||||
stutter_chance=0,
|
||||
action_chance=0,
|
||||
exclamation_chance=0,
|
||||
power=4,
|
||||
)
|
||||
uwu_most = Uwuipy(
|
||||
stutter_chance=0,
|
||||
action_chance=0.05,
|
||||
face_chance=0.1,
|
||||
nsfw_actions=False,
|
||||
power=4,
|
||||
)
|
||||
|
||||
|
||||
def validate_geometry(geometry: BaseGeometry):
|
||||
if not isinstance(geometry, BaseGeometry):
|
||||
|
@ -145,11 +171,29 @@ class JSONField(models.TextField):
|
|||
return self.get_prep_value(value)
|
||||
|
||||
|
||||
special_pattern = r'(%%|%(\([^)]*\))?[^a-z]*[a-z]|<[^>]*>|\{[^}]*\})'
|
||||
|
||||
|
||||
def get_i18n_value(i18n_dict, fallback_language, fallback_any, fallback_value):
|
||||
lang = get_language()
|
||||
if i18n_dict:
|
||||
if lang in i18n_dict:
|
||||
return i18n_dict[lang]
|
||||
if lang == "en-uw" and "en" in i18n_dict:
|
||||
owiginal = i18n_dict["en"]
|
||||
stripped_owiginal = re.sub(special_pattern, '{}', owiginal)
|
||||
specials = [item[0] for item in re.findall(special_pattern, owiginal)]
|
||||
num_wowds = len(stripped_owiginal.split("(")[0].split())
|
||||
if num_wowds >= 8:
|
||||
twanslated = uwu_most.uwuify(stripped_owiginal)
|
||||
elif num_wowds >= 3:
|
||||
twanslated = uwu_more.uwuify(stripped_owiginal)
|
||||
else:
|
||||
twanslated = uwu.uwuify(stripped_owiginal)
|
||||
twanslated = twanslated.replace('***', '*').replace(r'\<', '<').replace(r'\>', '>')
|
||||
if specials:
|
||||
twanslated = ''.join(chain(*zip(twanslated.split('{}'), specials + [""])))
|
||||
return twanslated
|
||||
if fallback_language in i18n_dict:
|
||||
return i18n_dict[fallback_language]
|
||||
if fallback_any:
|
||||
|
|
|
@ -444,10 +444,27 @@ LOCALE_PATHS = (
|
|||
PROJECT_DIR / 'locale',
|
||||
)
|
||||
|
||||
LANGUAGES = [
|
||||
EXTRA_LANG_INFO = {
|
||||
'en-UW': {
|
||||
'bidi': False,
|
||||
'code': 'en-UW',
|
||||
'name': 'Engwish UwU',
|
||||
'name_local': u'Engwish UwU', #unicode codepoints here
|
||||
},
|
||||
}
|
||||
|
||||
# Add custom languages not provided by Django
|
||||
import django.conf.locale
|
||||
LANG_INFO = dict(django.conf.locale.LANG_INFO, **EXTRA_LANG_INFO)
|
||||
django.conf.locale.LANG_INFO = LANG_INFO
|
||||
|
||||
SELECTED_LANGUAGES = frozenset(config.get('c3nav', 'languages', fallback='en,de').split(','))
|
||||
LANGUAGES = [(code, name) for code, name in [
|
||||
('en', _('English')),
|
||||
('en-UW', _('Engwish UwU')),
|
||||
('de', _('German')),
|
||||
]
|
||||
] if code in SELECTED_LANGUAGES]
|
||||
TILE_CACHE_SERVER = config.get('c3nav', 'languagestile_cache_server', fallback=None)
|
||||
|
||||
template_loaders = (
|
||||
'django.template.loaders.filesystem.Loader',
|
||||
|
|
69
src/genuwu.py
Normal file
69
src/genuwu.py
Normal file
|
@ -0,0 +1,69 @@
|
|||
import re
|
||||
import sys
|
||||
from itertools import chain, zip_longest
|
||||
from pathlib import Path
|
||||
|
||||
import polib
|
||||
|
||||
file = Path(__file__).resolve().parent / "c3nav" / "locale" / "en_UW" / "LC_MESSAGES" / "django.po"
|
||||
if not file.exists():
|
||||
print('Run makemessages -l en_UW first!')
|
||||
sys.exit(1)
|
||||
|
||||
po = polib.pofile(file)
|
||||
|
||||
from uwuipy import Uwuipy
|
||||
uwu = Uwuipy(
|
||||
seed=1337,
|
||||
stutter_chance=0,
|
||||
face_chance=0,
|
||||
action_chance=0,
|
||||
exclamation_chance=0,
|
||||
nsfw_actions=False,
|
||||
power=4,
|
||||
)
|
||||
uwu_more = Uwuipy(
|
||||
seed=1337,
|
||||
stutter_chance=0,
|
||||
action_chance=0,
|
||||
exclamation_chance=0,
|
||||
power=4,
|
||||
)
|
||||
uwu_most = Uwuipy(
|
||||
seed=1337,
|
||||
stutter_chance=0,
|
||||
action_chance=0.05,
|
||||
face_chance=0.1,
|
||||
nsfw_actions=False,
|
||||
power=4,
|
||||
)
|
||||
|
||||
special_pattern = r'(%%|%(\([^)]*\))?[^a-z]*[a-z]|<[^>]*>|\{[^}]*\})'
|
||||
|
||||
|
||||
def uwuify(owiginal):
|
||||
stripped_owiginal = re.sub(special_pattern, '{}', owiginal)
|
||||
specials = [item[0] for item in re.findall(special_pattern, owiginal)]
|
||||
num_wowds = len(stripped_owiginal.split("(")[0].split())
|
||||
if num_wowds >= 8:
|
||||
twanslated = uwu_most.uwuify(stripped_owiginal)
|
||||
elif num_wowds >= 3:
|
||||
twanslated = uwu_more.uwuify(stripped_owiginal)
|
||||
else:
|
||||
twanslated = uwu.uwuify(stripped_owiginal)
|
||||
twanslated = twanslated.replace('***', '*').replace(r'\<', '<').replace(r'\>', '>')
|
||||
if specials:
|
||||
twanslated = ''.join(chain(*zip(twanslated.split('{}'), specials+[""])))
|
||||
return twanslated
|
||||
|
||||
|
||||
po.metadata["Plural-Forms"] = "nplurals=2; plural=(n != 1);"
|
||||
for entry in po:
|
||||
if entry.msgid_plural:
|
||||
entry.msgstr_plural[0] = uwuify(entry.msgid)
|
||||
entry.msgstr_plural[1] = uwuify(entry.msgid_plural)
|
||||
else:
|
||||
entry.msgstr = uwuify(entry.msgid)
|
||||
|
||||
po.save(file)
|
||||
|
2
src/requirements/uwu.txt
Normal file
2
src/requirements/uwu.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
uwuify==1.3.1
|
||||
polib==1.2.0
|
Loading…
Add table
Add a link
Reference in a new issue