Skip to content

Set language attribute on resource title and descriptions #2346

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

Merged
merged 4 commits into from
Jul 11, 2025

Conversation

jonkafton
Copy link
Contributor

@jonkafton jonkafton commented Jul 10, 2025

What are the relevant tickets?

Closes https://github.com/mitodl/hq/issues/6831

Description (What does it do?)

Sets a lang attribute on the learning drawer title and description and resource card titles for where available to improve machine readability.

This will provide occasional benefit, though we currently have limited data on the API:

  • We have a resource.language attribute, though I haven't come across any resources where this is not null. This course has resource.language null and a title and description in Turkish: https://api.learn.mit.edu/api/v1/learning_resources/3048/.

  • I'm using the value on resource.runs[0].languages.[0], the first language on the fist run. This is also what we're using for the languages in the drawer info section (though listing all languages for all runs). If a course has runs in several languages, this may not be the language of the parent title and description and in any case there's not guarantee the course title and description are in the same language as the first run.

  • Some of our data is missing or incorrect. This course offered in Spanish does not have languages set on its run: https://api.learn.mit.edu/api/v1/learning_resources/16541/. This course offered in Mandarin has "en-us" set on its run languages: https://api.learn.mit.edu/api/v1/learning_resources/2911/

The fix needed, if available on the source data, is to ensure that the language of the course title and description is always set on the on the resource so we're not selecting from the runs in hope of a match. An example of a good resource where the title matches the run language: https://api.learn.mit.edu/api/v1/learning_resources/2908/. Side note: It would be really useful to provide a language filter on the search for foreign language learners.

How can this be tested?

  • Search for some foreign language courses. Some searches:

    • "Kullanıcıdan" (Turkish / tr)
    • "스타트업 기업가정신" (Korean / ko)
  • Confirm that the resource list card titles have a lang attribute set to the first run language.

  • Open the resource drawer and confirm that both the title and description have a lang attribute set.

  • You should see similar learning resources in the same language in the drawer. Check that the resource card title links have a lang attribute set.

  • The lang attribute should be absent if null on the first learning resource run.

  • Screen readers should announce the text in the relevant language voice when the element is active, though not necessarily decisive as e.g. VoiceOver on mac does auto-detects the language.

@jonkafton jonkafton added the Needs Review An open Pull Request that is ready for review label Jul 10, 2025
@jonkafton jonkafton changed the title Set first run language on drawer and card titles and description Set language attribute on resource title and descriptions Jul 10, 2025
@abeglova abeglova self-assigned this Jul 11, 2025
Copy link
Contributor

@abeglova abeglova left a comment

Choose a reason for hiding this comment

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

This works for now although i agree that we need to fix the etl to propagate run language data to the learning resource and also more consistently populate language data on runs. In particular i noticed MIT Professional Education has lots of foreign language courses and none of them have the language correctly set in the api on either the resource or the runs

@@ -83,6 +83,7 @@ const ResourceDescription = ({ resource }: { resource?: LearningResource }) => {
* backend during ETL. This is safe to render.
*/
dangerouslySetInnerHTML={{ __html: resource.description || "" }}
lang={resource.runs?.[0]?.languages?.[0]}
Copy link
Contributor

Choose a reason for hiding this comment

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

This works. I think since generally runs are returned in a roughly chronological order getting the last run would be better since it's more likely to be a newer run so, resource.runs?.[resource.runs.length -1 ]?.languages?.[0]

Copy link

github-actions bot commented Jul 11, 2025

OpenAPI Changes

Show/hide No detectable change.

Unexpected changes? Ensure your branch is up-to-date with main (consider rebasing).

@jonkafton jonkafton removed the Needs Review An open Pull Request that is ready for review label Jul 11, 2025
@jonkafton jonkafton merged commit c3206f6 into main Jul 11, 2025
13 checks passed
@jonkafton jonkafton deleted the jk/6831-lang-attribute branch July 11, 2025 21:52
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