Skip to content

FEATURE: Translate categories and tags #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

nattsw
Copy link
Contributor

@nattsw nattsw commented Apr 3, 2025

Adding categories and tags into the fray.

This PR only adds translations for the categories and tags, without displaying them yet. That will come in a separate PR as we figure out caching and appropriate APIs in core.

@nattsw nattsw force-pushed the category-translations branch from 422a3ed to 0e8c3e2 Compare April 8, 2025 02:29
@nattsw nattsw marked this pull request as ready for review April 8, 2025 02:32
@nattsw nattsw changed the title FEATURE: Translate categories and display them when inline translatio… FEATURE: Translate categories and tags Apr 8, 2025
AND m.user_id > 0
#{max_age_clause}
WHERE m.#{content_column} != ''
#{not_deleted_clause(model)}
Copy link
Contributor Author

@nattsw nattsw Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike posts and topics, categories and tags do not have a deleted_at nor can be created by a bot

[
[Topic, "title"],
[Post, "raw"],
[Category, "name"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is Category#description too. Is that something we want to consider in this PR too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet. Category descriptions are currently topics so we will ignore for now.

Comment on lines +28 to +30
#{not_deleted_clause(model)}
#{non_bot_clause(model)}
#{max_age_clause(model)}
Copy link
Contributor

@tgxworld tgxworld Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if it makes sense to just make this backfill_clause(model) or something instead of having the logic of model == Post || model == Topic present over 3 methods. This also makes the complete query much easier to read/understand IMO instead of having 3 parts to combine mentally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the current query looks very neat instead of having to repeat the clause for every model

            SELECT m.id
            FROM #{model.table_name} m
            #{limit_to_public_clause(model)}
            WHERE m.#{content_column} != ''
              #{not_deleted_clause(model)}
              #{non_bot_clause(model)}
              #{max_age_clause(model)}
            ORDER BY m.updated_at DESC

I will prefer optimizing next time if it gets more complex.

# frozen_string_literal: true

module DiscourseTranslator
class CategoryTranslation < ActiveRecord::Base
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to differentiate between Category#name and Category#description? It might be useful to think about how we can expand this table to store the translation for more than a single column since some models may have multiple columns that requires us to translate.

Copy link
Contributor Author

@nattsw nattsw Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.

This current implementation makes use of the translatable concern. Category descriptions point to a topic so it will use topic translations instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants