Set language attribute on resource title and descriptions #2346
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 hasresource.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:
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.