diff --git a/boards/forms/__init__.py b/boards/forms/__init__.py
--- a/boards/forms/__init__.py
+++ b/boards/forms/__init__.py
@@ -464,13 +464,18 @@ class ThreadForm(PostForm):
required_tag_exists = False
tag_set = set()
for tag_string in tags.split():
- if tag_string.strip().lower() == default_tag_name:
+ tag_name = tag_string.strip().lower()
+ if tag_name == default_tag_name:
required_tag_exists = True
tag, created = Tag.objects.get_or_create(
- name=tag_string.strip().lower(), required=True)
+ name=tag_name, required=True)
else:
- tag, created = Tag.objects.get_or_create(
- name=tag_string.strip().lower())
+ tag = Tag.objects.get_by_alias(tag_name)
+ if tag:
+ created = False
+ else:
+ tag, created = Tag.objects.get_or_create(
+ name=tag_name)
tag_set.add(tag)
# If this is a new tag, don't check for its parents because nobody
diff --git a/boards/migrations/0057_tag_aliases.py b/boards/migrations/0057_tag_aliases.py
new file mode 100644
--- /dev/null
+++ b/boards/migrations/0057_tag_aliases.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-02-24 19:40
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('boards', '0056_auto_20170123_1620'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='tag',
+ name='aliases',
+ field=models.TextField(blank=True),
+ ),
+ ]
diff --git a/boards/models/tag.py b/boards/models/tag.py
--- a/boards/models/tag.py
+++ b/boards/models/tag.py
@@ -1,9 +1,12 @@
import hashlib
+import re
+
from boards.models.attachment import FILE_TYPES_IMAGE
from django.template.loader import render_to_string
from django.db import models
from django.db.models import Count
from django.core.urlresolvers import reverse
+from django.utils.translation import get_language
from boards.models import Attachment
from boards.models.base import Viewable
@@ -16,9 +19,10 @@ import boards
RELATED_TAGS_COUNT = 5
+REGEX_TAG_ALIAS = r'{}:(\w+),'
+
class TagManager(models.Manager):
-
def get_not_empty_tags(self):
"""
Gets tags that have non-archived threads.
@@ -34,6 +38,9 @@ class TagManager(models.Manager):
return ', '.join([tag.get_view() for tag in tags])
+ def get_by_alias(self, alias):
+ return self.filter(aliases__contains=":{},".format(alias)).first()
+
class Tag(models.Model, Viewable):
"""
@@ -53,6 +60,7 @@ class Tag(models.Model, Viewable):
parent = models.ForeignKey('Tag', null=True, blank=True,
related_name='children')
+ aliases = models.TextField(blank=True)
def __str__(self):
return self.name
@@ -89,8 +97,17 @@ class Tag(models.Model, Viewable):
return self.required
def get_view(self):
+ locale = get_language()
+
+ if self.aliases:
+ match = re.search(REGEX_TAG_ALIAS.format(locale), self.aliases)
+ if match:
+ localized_tag_name = match.group(1)
+ else:
+ localized_tag_name = self.name
+
link = '{}'.format(
- self.get_absolute_url(), self.name)
+ self.get_absolute_url(), localized_tag_name)
if self.is_required():
link = '{}'.format(link)
return link