Skip to content
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

Feat Nav buttons text configurable + add tests #476

Merged
merged 21 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
99d2b44
feat: make the header nav buttons text configurable
Sep 19, 2024
996003e
fix: resolve errors in app.cy tests regarding the title bar
Sep 19, 2024
a0d9e93
fix: resolve errors regarding the content tests
Sep 19, 2024
46f977f
fix: rewrite the old tests content as it was and add a arabic karshun…
Sep 19, 2024
0bb79e4
refactor: add ahiqar and gfl selektors in globals file
Sep 19, 2024
383c931
test: add tests for the feat header nav buttons text configurable
Sep 19, 2024
8ccdfc8
chore: restore the previous content in index.html
Sep 20, 2024
ee74427
fix: add combined translation keys for the header nav buttons
Sep 20, 2024
bc803d9
test: adapt the header nav buttons text according to the new translat…
Sep 20, 2024
fddb30c
chore: remove the 'labels' object from the gfl local example file
Sep 20, 2024
044f32e
chore: restore the labels object in config of local files (arabic kar…
Sep 20, 2024
93b1840
fix: show specific header nav button labels for the ahiqar editions
Sep 20, 2024
7988fcb
feat: make header navigation buttons text configurable for each project
Sep 20, 2024
fc824c8
test: remove the tests for arabic karshuni 'de'
Sep 20, 2024
935c7a5
chore: add in the translations key of config the (key,value) of nav b…
Sep 20, 2024
5bb41a1
chore: remove the translations key values from i18n en for the ahiqa…
Sep 20, 2024
625f681
chore: set the 'item' label temporarily in Title bar
Sep 20, 2024
b6b196f
chore: use the general keys (item and manifest) in config for the loc…
Sep 23, 2024
c754f39
feat: add nav buttons text configurable
Sep 23, 2024
415b03f
fix: show the item name in the title of header based on nav buttons text
Sep 23, 2024
931b282
chore: remove ahiqar arabic karshuni local
Sep 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions examples/ahiqar-arabic-karshuni-local.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,13 @@
],
"translations": {
"en": {
"contents_and_metadata": "Contents & Metadata"
}
"contents_and_metadata": "Contents & Metadata",
"next_item": "Next Sheet",
"previous_item": "Previous Sheet",
"next_manifest": "Next Manuscript",
"previous_manifest": "Previous Manuscript"
},

}
});
});
Expand Down
9 changes: 8 additions & 1 deletion examples/gfl-local.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,14 @@
}
],
translations: {
Edition_license: 'Editionslizenz'
de: {
Edition_license: 'Editionslizenz',
next_item : "Nächste Seite",
previous_item: "Vorherige Seite",
next_manifest: "Nächstes Dokument",
previous_manifest: "Vorheriges Dokument"
}

}
});
});
Expand Down
26 changes: 16 additions & 10 deletions src/components/header/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ import { useI18n } from 'vue-i18n';
import { useConfigStore } from '@/stores/config';
import { useContentsStore } from '@/stores/contents';
import BaseButton from '@/components/base/BaseButton.vue';
import { getNavButtonsLabels } from '@/utils/translations'

const configStore = useConfigStore();
const contentStore = useContentsStore();
const { t } = useI18n();


const manifest = computed<Manifest>(() => contentStore.manifest);
const manifests = computed<Manifest[]>(() => contentStore.manifests);
Expand All @@ -48,6 +49,8 @@ const hasPrev = computed<boolean>(() => {

return true;
});


const hasNext = computed<boolean>(() => {
const nextIndex = itemIndex.value + 1;
if (nextIndex > manifest.value.sequence.length - 1) {
Expand All @@ -57,16 +60,19 @@ const hasNext = computed<boolean>(() => {
}
return true;
});
const labels = computed<Labels>(() => configStore.config.labels || {
manifest: 'manifest',
item: 'item',
});
const nextButtonLabel = computed<string>(() => (itemIndex.value === manifest.value.sequence.length - 1
? `${t('next')} ${t(labels.value.manifest ? labels.value.manifest : 'Manuscript')}`
: `${t('next')} ${t(labels.value.item)}`));


const [nextPageLabel, previousPageLabel, nextDocumentLabel, previousDocumentLabel]: string[] = getNavButtonsLabels(configStore.config)

const nextButtonLabel = computed<string>(() => (
itemIndex.value === manifest.value.sequence.length - 1
? `${nextDocumentLabel}`
: `${nextPageLabel}`));


const prevButtonLabel = computed<string>(() => (itemIndex.value === 0
? `${t('prev')} ${t(labels.value.manifest ? labels.value.manifest : 'Manuscript')}`
: `${t('prev')} ${t(labels.value.item)}`));
? `${previousDocumentLabel}`
: `${previousPageLabel}`));

function prev() {
const prevIndex = itemIndex.value - 1;
Expand Down
17 changes: 10 additions & 7 deletions src/components/header/TitleBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class="t-px-2 text-gray-500 dark:text-gray-300"
name="chevronRight"
/>
<span v-if="item">{{ labels.item }} {{ item.n }}</span>
<span v-if="item">{{ getItemLabel() }} {{ item.n }}</span>
</h2>
</template>
<template v-else>
Expand All @@ -32,7 +32,7 @@
<span
v-if="item"
class="t-align-middle"
>{{ labels.item }} {{ item.n }}</span>
>{{ getItemLabel() }} {{ item.n }}</span>
</h1>
</template>
</template>
Expand All @@ -50,7 +50,7 @@ import { computed } from 'vue';
import { useConfigStore } from '@/stores/config';
import { useContentsStore } from '@/stores/contents'
import BaseIcon from '@/components/base/BaseIcon.vue';

import { getNavButtonsLabels } from '@/utils/translations';

export interface Props {
item: Item
Expand All @@ -63,10 +63,13 @@ withDefaults(defineProps<Props>(), {
const configStore = useConfigStore()
const contentStore = useContentsStore()


const collectionTitle = computed<string | null>(() => contentStore.collectionTitle);
const manifestTitle = computed<string | undefined>(() => contentStore.manifest?.label );
const labels = computed<Labels>(() => configStore.config.labels || {
manifest: 'manifest',
item: 'item',
});


function getItemLabel() {
const navButtonsLabels = getNavButtonsLabels(configStore.config)
return navButtonsLabels[0].split(' ')[1]
}
</script>
10 changes: 5 additions & 5 deletions src/i18n/de/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@ export default {
Letter: 'Brief',
License: 'Lizenz',
Location: 'Aktueller Aufbewahrungsort',
Manuscript: 'Manuskript',
metadata: 'Metadaten',
Motif: 'Motive',
search_hit_list: 'Trefferanzeige',
next: 'Nächste',
no_annotations_in_view: 'Die aktuelle Ansicht enthält keine Annotationen.',
no_comments_in_view: 'Die aktuelle Ansicht enthält keine Kommentare',
no_entrypoint_available: 'Keine URL zum Einstieg gefunden. Bitte überprüfen Sie Ihre Konfiguration.',
Expand All @@ -74,11 +72,14 @@ export default {
zoom_in: 'Vergrössern',
zoom_out: 'Verkleinern',
'Place of origin': 'Herkunftsort',
prev: 'Vorherige',
project_info: 'Projekt Informationen',
reset: 'Zurücksetzen',
search: 'Suche',
Sheet: 'Seite',
item: 'Seite',
next_item: 'Nächste Seite',
previous_item: 'Vorherige Seite',
next_manifest: 'Nächstes Dokument',
previous_manifest: 'Vorheriges Dokument',
show: 'Zeige',
show_hide_panels: 'Panels ein-/ausblenden',
tabs: 'Reiter',
Expand All @@ -104,7 +105,6 @@ export default {
server_error: 'Server Fehler',
other: 'Sonstiges',
subtitle: 'Untertitel',
manifest: 'Manifest',
more_annotations: 'Weitere',
undefined_role: 'Undefinierte Rolle',
not_found: 'Nicht gefunden',
Expand Down
10 changes: 6 additions & 4 deletions src/i18n/en/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ export default {
metadata: 'Metadata',
Motif: 'Motifs',
search_hit_list: 'Search hit list',
next: 'Next',
next_item: 'Next Item',
previous_item: 'Previous Item',
next_manifest: 'Next Manifest',
previous_manifest: 'Previous Manifest',
no_annotations_in_view: 'The current view has no annotations to display.',
no_comments_in_view:
'The current view does not contain any comments to display',
Expand All @@ -78,11 +81,11 @@ export default {
zoom_in: 'Zoom in',
zoom_out: 'Zoom out',
'Place of origin': 'Place of origin',
prev: 'Previous',
project_info: 'Project Info',
reset: 'Reset',
search: 'Search',
Sheet: 'Sheet',
item: 'Item',
sheet: 'Sheet',
show: 'Show',
show_hide_panels: 'Show/Hide Panels',
tabs: 'Tabs',
Expand All @@ -108,7 +111,6 @@ export default {
server_error: 'Server error',
other: 'Other',
subtitle: 'Subtitle',
manifest: 'Manifest',
also_selected: 'Also selected',
undefined_role: 'Undefined role',
not_found: 'Not found',
Expand Down
31 changes: 31 additions & 0 deletions src/utils/translations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

import i18n from '@/i18n'

// variables are named according to the general concept of ie (item = sheet, item); (manifest = document, manuscript)
const navButtonsDefaultTextArray = ['next_item', 'previous_item', 'next_manifest', 'previous_manifest']

export function areNavButtonsLabelsInConfig(config) {
paulpestov marked this conversation as resolved.
Show resolved Hide resolved
const lang = config['lang']
const translations = config.translations[lang]

for (let i = 0; i < navButtonsDefaultTextArray.length; i++) {
if(!(navButtonsDefaultTextArray[i] in translations)) return false
}

return true
}


export function getNavButtonsLabels(config, navButtonsDefaultTextArray) {
const lang = config['lang']

if (areNavButtonsLabelsInConfig(config)) {
const translations = config.translations[lang]
return [translations['next_item'], translations['previous_item'], translations['next_manifest'], translations['previous_manifest']]
}
else {
// the following way of accessing translations (i.e next_item) is on square brackets, because we use 18n on a js file and not a vue component
const t = i18n[lang]
return [t['next_item'], t['previous_item'], t['next_manifest'], t['previous_manifest']]
}
}
6 changes: 3 additions & 3 deletions tests/cypress/e2e/content.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('Content - Multiple Tabs', () => {
// Decreasing font size
cy
.get(selectors.panel3)
.get('.actions>div:first-child button[title="Decrease"]')
.find('.actions>div:first-child button[title="Decrease"]')
.click();

cy.get('#text-content div')
Expand All @@ -142,7 +142,7 @@ describe('Content - Multiple Tabs', () => {
// Increasing font size
cy
.get(selectors.panel3)
.get('.actions>div:first-child button[title="Increase"]')
.find('.actions>div:first-child button[title="Increase"]')
.click() // 18px
.click() // 20px
.click() // 22px
Expand All @@ -160,7 +160,7 @@ describe('Content - Multiple Tabs', () => {
// Increasing font size
cy
.get(selectors.panel3)
.get('.actions>div:first-child button[title="Decrease"]')
.find('.actions>div:first-child button[title="Decrease"]')
.click() // 14px
.should('be.disabled');

Expand Down
1 change: 1 addition & 0 deletions tests/cypress/e2e/header.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,4 @@ describe('Header - Item and Manifest changing', () => {
.should('include', 'tido=m7_i1');
});
});

38 changes: 38 additions & 0 deletions tests/cypress/e2e/translations.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

import { commonSelectors, ahiqarSelectors, gflSelectors } from '../support/globals';

const selectors = {
...commonSelectors,
...ahiqarSelectors,
}

describe('Translations', () => {
describe('Header Nav buttons text configurable', () => {

it('should show the nav buttons text in german', () => {
/// GFL Projekt

cy.visit('/gfl-local.html?tido=i0')
.get(selectors.nextButton)
.contains('Nächste Seite')

.get(selectors.prevButton)
.contains('Vorheriges Dokument')

cy.visit('/gfl-local.html?tido=i1')
.get(selectors.nextButton)
.contains('Nächstes Dokument')

.get(selectors.prevButton)
.contains('Vorherige Seite')
})
})

it('should show the nav buttons text in english', () => {
cy.visit('/ahiqar-arabic-karshuni-local.html?tido=m0_i0')
.get(selectors.nextButton)
.contains('Next Sheet')
.get(selectors.prevButton)
.contains('Previous Manuscript')
})
})
11 changes: 11 additions & 0 deletions tests/cypress/support/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,15 @@ export default {
},
ahiqarApiBaseUrl: 'http://localhost:8181/ahiqar',
gflApiBaseUrl: 'http://localhost:8181/gfl',
ahiqarSelectors: {
list: '.panels-wrapper > .panel:nth-child(4) div[role="tablist"] .annotations-list',
listItem: '.panels-wrapper > .panel:nth-child(4) [role="tablist"] .annotations-list .item',
listOfSecondTab: '.panels-wrapper > .panel:nth-child(4) [role="tabpanel"]:nth-child(2) .annotations-list',
tab: '.panels-wrapper > .panel:nth-child(4) [role="tablist"] [data-pc-section="nav"] [data-pc-name="tabpanel"]',
text: '.panels-wrapper > .panel:nth-child(3) #text-content',
annotationPanelActionCheckbox: '.panel-header .actions > div:first-child #panel-check-action',
},
gflSelectors: {
listItem: '.panels-wrapper > .panel:nth-child(3) [role="tablist"] .annotations-list .item',
}
};