UwU suppowt
This commit is contained in:
parent
bece878aa2
commit
43f7414573
6 changed files with 139 additions and 3 deletions
|
@ -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',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue