-
Notifications
You must be signed in to change notification settings - Fork 20
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
@@ -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") |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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:- Create the column with
nullable=True
- Run an
UPDATE ...
command to set thelang="en"
(see also this more complex recipe, doing updates) - Add the
nullable=False
constraint to the field
- Create the column with
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)]]
Co-authored-by: Alex Ioannidis <[email protected]>
Co-authored-by: Alex Ioannidis <[email protected]>
❤️ 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: