BoltTranslate / Translate

Provides translation for contenttypes.
Other
43 stars 38 forks source link

[RFC] Translate taxonomies #198

Closed COOLak closed 5 years ago

COOLak commented 5 years ago

There's no mentioning of any way to translate taxonomies in the documentation, so I suppose there's no way to do it. Basically the only way is to have English taxonomies for all languages or have them in all languages at the same time, which doesn't look right. For example, on my website, I have a taxonomy called Categories, which includes News and Articles. At the bottom of each record there's output of the respective taxonomy (Category: News / Category: Articles). Visitors of different language version will not understand what that is.

COOLak commented 5 years ago

For anyone else who's come to face the same issue, I managed to make a workaround. Basically, you create additional taxonomies that end with '_locale' (e. g. _es for Spanish). So you have both 'categories' and 'categories_es', both 'tags' and 'tags_es'. Then you modify your _sub_taxonomylinks.twig in the following way (I use subdomain approach, use your own conditions that suite you). This allows to only show language-specific taxonomies depending on the url of the website.

<div class="tags">
    {% for type, values in record|taxonomy %}
        {% set domain = app.request.getHttpHost() %}
        {% if ((domain == 'es.domain.com') and '_es' in type) or ((domain == 'en.domain.com') and '_es' not in type) %}
            <span class="label">
                {% if values|length < 2 %}
                    {{ config.get('taxonomy')[type].singular_name }}:
                {% else %}
                    {{ config.get('taxonomy')[type].name }}:
                {% endif %}
            </span>
            {% for link, value in values %}
                <a href="{{ link }}" class="tag is-dark">{{ value }}</a>
            {% else %}
                {{ __('general.phrase.none') }}
            {% endfor %}
        {% endif %}
    {% endfor %}
</div>
COOLak commented 5 years ago

Well, another option is to just use Labels. At the time of submitting this RFC I wasn't fully aware that it's capable of doing this on its own. But the above method could still be useful for those who want to have taxonomy links different for other languages.