Skip to content

Commit

Permalink
Add dynamic translations for Aria tags
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelvaara committed Feb 4, 2025
1 parent a1ebb7b commit a009724
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 9 additions & 3 deletions resource/js/tab-hierarchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ function startHierarchyApp () {
computed: {
openAriaMessage () {
return $t('Open')
},
goToTheConceptPageAriaMessage () {
return $t('Go to the concept page')
}
},
provide () {
Expand Down Expand Up @@ -205,6 +208,7 @@ function startHierarchyApp () {
:selectedConcept="selectedConcept"
:loadingChildren="loadingChildren"
:openAriaMessage="openAriaMessage"
:goToTheConceptPageAriaMessage="goToTheConceptPageAriaMessage"
@load-children="loadChildren($event)"
@select-concept="selectedConcept = $event"
></tab-hier-wrapper>
Expand Down Expand Up @@ -244,7 +248,7 @@ function startHierarchyApp () {
})

tabHierApp.component('tab-hier-wrapper', {
props: ['hierarchy', 'selectedConcept', 'loadingChildren', 'openAriaMessage'],
props: ['hierarchy', 'selectedConcept', 'loadingChildren', 'openAriaMessage', 'goToTheConceptPageAriaMessage'],
emits: ['loadChildren', 'selectConcept'],
mounted () {
// scroll automatically to selected concept after the whole hierarchy tree has been mounted
Expand Down Expand Up @@ -284,6 +288,7 @@ function startHierarchyApp () {
:isLast="i == hierarchy.length - 1"
:loadingChildren="loadingChildren"
:openAriaMessage="openAriaMessage"
:goToTheConceptPageAriaMessage="goToTheConceptPageAriaMessage"
@load-children="loadChildren($event)"
@select-concept="selectConcept($event)"
></tab-hier>
Expand All @@ -292,7 +297,7 @@ function startHierarchyApp () {
})

tabHierApp.component('tab-hier', {
props: ['concept', 'selectedConcept', 'isTopConcept', 'isLast', 'loadingChildren', 'openAriaMessage'],
props: ['concept', 'selectedConcept', 'isTopConcept', 'isLast', 'loadingChildren', 'openAriaMessage', 'goToTheConceptPageAriaMessage'],
emits: ['loadChildren', 'selectConcept'],
inject: ['partialPageLoad', 'getConceptURL', 'showNotation'],
methods: {
Expand Down Expand Up @@ -332,7 +337,7 @@ function startHierarchyApp () {
<a :class="{ 'selected': selectedConcept === concept.uri }"
:href="getConceptURL(concept.uri)"
@click="handleClickConceptEvent($event, concept)"
aria-label="Go to the concept page"
:aria-label="goToTheConceptPageAriaMessage"
>
<span v-if="showNotation && concept.notation" class="concept-notation">{{ concept.notation }} </span>
{{ concept.label }}
Expand All @@ -344,6 +349,7 @@ function startHierarchyApp () {
:concept="c"
:selectedConcept="selectedConcept"
:openAriaMessage="openAriaMessage"
:goToTheConceptPageAriaMessage="goToTheConceptPageAriaMessage"
:isTopConcept="false"
:isLast="i == concept.children.length - 1"
:loadingChildren="loadingChildren"
Expand Down
4 changes: 3 additions & 1 deletion tests/cypress/template/sidebar-hierarchy.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,14 @@ describe('Hierarchy', () => {
cy.visit('/test-hierarchy/fi/')
cy.get('#hierarchy').should('not.have.class', 'disabled').click()
cy.get('#hierarchy-list').find('ul.list-group button').should('have.attr', 'aria-label', 'avaa');
cy.get('.concept-label a').first().should('have.attr', 'aria-label', 'Mene käsitesivulle')
cy.visit('/test-hierarchy/en/')
cy.get('#hierarchy').should('not.have.class', 'disabled').click()
cy.get('#hierarchy-list').find('ul.list-group button').should('have.attr', 'aria-label', 'Open');
cy.get('.concept-label a').first().should('have.attr', 'aria-label', 'Go to the concept page')
cy.visit('/test-hierarchy/sv/')
cy.get('#hierarchy').should('not.have.class', 'disabled').click()
cy.get('#hierarchy-list').find('ul.list-group button').should('have.attr', 'aria-label', 'öppna');
cy.get('.concept-label a').first().should('have.attr', 'aria-label', 'Gå till begreppssidan')
})

})

0 comments on commit a009724

Please sign in to comment.