-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add rtl/ltr direction support for adding instrument name #448
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
base: develop
Are you sure you want to change the base?
Conversation
PouyaMohseni
commented
Dec 3, 2025
e1f6578 to
0ffed3b
Compare
| { | ||
| "wikidata_code": "{{ language.wikidata_code }}", | ||
| "autonym": "{{ language.autonym }}", | ||
| "en_label": "{{ language.en_label }}" |
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 just noticed that this template file has a inline script. This is quite messy and not ideal. Can we get rid of it in this PR? Thanks.
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.
Yeah, I just took a closer look at this...
If we want to keep this rendered server-side, then probably the cleanest thing to do is pass a JSON string to the context and then load it here.
Just make the languages context object into a python object (list of dictionaries), stringify it, and then assign it directly to a variable.
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.
It's also the "Django" way: see the json_script template filter: https://docs.djangoproject.com/en/5.2/ref/templates/builtins/#json-script
| { | ||
| "wikidata_code": "{{ language.wikidata_code }}", | ||
| "autonym": "{{ language.autonym }}", | ||
| "en_label": "{{ language.en_label }}" |
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.
Yeah, I just took a closer look at this...
If we want to keep this rendered server-side, then probably the cleanest thing to do is pass a JSON string to the context and then load it here.
Just make the languages context object into a python object (list of dictionaries), stringify it, and then assign it directly to a variable.
|
|
||
| const languages = readLanguagesFromPage(); | ||
|
|
||
| export { languages }; |
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.
Is this intended to be used elsewhere? Especially since the export having any useful data depends on the languages being templated into the html...if we were populating this with an api call, I would understand exporting just because, but as it stands now, I think it's clearer to not export (if someone wants this language object later somewhere else, the fact that it isn't exported will be a good hint that it's not self-contained)
|
I've done the same thing here for
UMIL/web-app/django/VIM/apps/main/views.py Lines 34 to 51 in cea2f93
|
|
Forgot to include, you can then parse data to frontend like this: UMIL/web-app/frontend/src/stats/BarCharts.ts Lines 29 to 39 in cea2f93
|
627b8fc to
6395f39
Compare
|
|
||
| declare const languages: WikidataLanguage[]; | ||
| // Helper to read JSON from the template-inserted script tag | ||
| function readLanguagesFromPage() { |
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.
This function is only called once? Does it need to be a function?
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 thought it would be easier to reuse it in the future, as we want to have a page to add new instruments, which would need such functionality.
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, I would suggest to put it into a file named utils.ts and name the function getLanguages.
| ); | ||
|
|
||
| if (lang) { | ||
| nameInput.setAttribute('dir', lang.html_direction); |
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.
You are setting the text alignment below. Is this needed?
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.
On my device, text alignment was sufficient, but I wasn’t aware of the other behaviors, so I added it just to be safe. If you recommend otherwise, I remove it.
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.
To make it more clear, I suggest you use css class instead.
| nameInput.setAttribute('dir', lang.html_direction); | |
| nameInput.classList.add(lang.html_direction === 'rtl' ? 'force-rtl' : 'force-ltr'); |
dchiller
left a comment
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 good once @yinanazhou is...
| lang.html_direction === 'rtl' ? 'force-rtl' : 'force-ltr', | ||
| ); | ||
| nameInput.style.textAlign = | ||
| lang.html_direction === 'rtl' ? 'right' : 'left'; |
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.
Is this still needed?
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.
Yes, it doesn't work on my side without the second part.
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 think it's better to make .force-rtl and .force-ltr work than doing this. Just had a closer look at them, you can try move them out of the nest they are in right now.
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.
@yinanazhou, Do you approve the changes?
3acc61e to
598d2b9
Compare
| ); | ||
|
|
||
| if (lang) { | ||
| nameInput.classList.remove('force-rtl', 'force-ltr'); |
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.
This is a weird place to clean up the class. You should always clean up when the language changes. Move this outside of if and up to make it the first thing to do when the change happens. Also remember to trigger event in restoreFormData() after L307 to make sure the change event gets fired.
598d2b9 to
9ae269e
Compare