Skip to content
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

Add internationalisation support #98

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

wgresshoff
Copy link

❤️ Thank you for your contribution!

Description

Add internationalisation support. By adding a lang column and extendig the unique constraint the goal is achieved. This feature is available in the Administration interface as well.

Checklist

Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:

Frontend

Reminder

By using GitHub, you have already agreed to the GitHub’s Terms of Service including that:

  1. You license your contribution under the same terms as the current repository’s license.
  2. You agree that you have the right to license your contribution under the current repository’s license.

@wgresshoff
Copy link
Author

@wgresshoff wgresshoff requested review from slint and tmorrell February 13, 2025 10:31
Copy link
Member

@slint slint left a comment

Choose a reason for hiding this comment

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

LGTM, some minor decisions and concern about use of server_default vs. default for the field definition

invenio_pages/records/models.py Outdated Show resolved Hide resolved
@@ -36,6 +37,9 @@ class PageModel(db.Model, Timestamp):
title = db.Column(db.String(200), nullable=False, default="")
"""Page title."""

lang = db.Column(db.String(2), nullable=False, default="en")
Copy link
Member

@slint slint Feb 13, 2025

Choose a reason for hiding this comment

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

minor/question: (probably I18N/L10N experts can jump in) is this the best format to store the language? E.g. could en-US or similar be better and map to the overall translations process? This would affect the string size, i.e. 2 vs. 5 (or even higher?)

Copy link
Author

Choose a reason for hiding this comment

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

I'm not an expert but this is the information the UI provides?! This follows the settings in I18N_LANGUAGES.

@@ -35,12 +35,12 @@ def test_alembic(base_app, db):
db.drop_all()
drop_alembic_version_table()
ext.alembic.upgrade()
assert len(ext.alembic.compare_metadata()) == 0
assert len(ext.alembic.compare_metadata()) == 3
Copy link
Member

@slint slint Feb 13, 2025

Choose a reason for hiding this comment

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

minor: I feel this is because you specify server_default in the Alembic recipe but not in the SQLAlchemy model definition. I think there are two options:

  • Use server_default in the SQLAlchemy model column definition. We don't do this in general and I'm still unsure what's the best practice:
    • Definitely more "efficient" since the DB does the work for us, and I know that PostgreSQL is smart about it when adding the new column.
    • Less flexible, since default=... allows functions that can compute the value based on application config or other runtime conditions
  • Instead of using server_default in the alembic recipe column definition, you can create the column in multiple steps and populate the default value:
    1. Create the column with nullable=True
    2. Run an UPDATE ... command to set the lang="en" (see also this more complex recipe, doing updates)
    3. Add the nullable=False constraint to the field

Copy link
Author

Choose a reason for hiding this comment

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

Replaced server_default by default: no changes in the test results.

Copy link
Member

Choose a reason for hiding this comment

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

In that case we have to see what the output of ext.alembic.compare_metadata() is, I think it contains some more specific information... We've disabled in other places Alembic tests, because of some other irrelevant issues, so if this is the case, we can do this here as well.

Copy link
Author

Choose a reason for hiding this comment

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

Seems the output is how to rollback the modifications:

[('remove_constraint', UniqueConstraint(Column('url', NullType(), table=<pages_page>), Column('lang', NullType(), table=<pages_page>))), ('add_constraint', UniqueConstraint(Column('url', NullType(), table=<pages_page>))), [('modify_nullable', None, 'pages_page_version', 'lang', {'existing_type': CHAR(length=2), 'existing_server_default': False, 'existing_comment': None}, False, True)]]

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

Successfully merging this pull request may close these issues.

2 participants