Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"test-accessibility-cli-vocab-search": "npx cypress run --env cli=true --spec 'tests/cypress/accessibility/axe-vocab-search.cy.js'"
},
"dependencies": {
"@formatjs/intl-collator": "^0.2.2",
"@fortawesome/fontawesome-free": "^7.2.0",
"bootstrap": "^5.3.*",
"vue": "^3.5.25"
Expand Down
50 changes: 38 additions & 12 deletions resource/js/tab-hierarchy.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,19 +327,12 @@
strA = strA || a.label || a.prefLabel || a.title || ''
strB = strB || b.label || b.prefLabel || b.title || ''

// Set language and options
const lang = window.SKOSMOS.content_lang || window.SKOSMOS.lang
const options = {
numeric: window.SKOSMOS.sortByNotation === 'natural', // Set numeric to true if sort should be natural
sensitivity: 'variant' // Strings that differ in base letters, diacritic marks, or case compare as unequal
}

const result = strA.localeCompare(strB, lang, options)
const result = this.$collator.compare(strA, strB)
if (result !== 0) {
return result
} else {
// fall back to non-numeric sort to ensure a consistent order
return strA.localeCompare(strB, lang, { sensitivity: 'variant' })
return this.$fallbackCollator.compare(strA, strB)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Function with many returns (count = 4): compareConcepts [qlty:return-statements]

}
},
Expand Down Expand Up @@ -519,9 +512,42 @@
`
})

if (document.getElementById('tab-hierarchy')) {
tabHierApp.mount('#tab-hierarchy')
// initialize the collators needed by the app
tabHierApp.config.globalProperties.$collator = new Intl.Collator(
window.SKOSMOS.content_lang || window.SKOSMOS.lang,

Check warning on line 517 in resource/js/tab-hierarchy.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=NatLibFi_Skosmos&issues=AZ5uo1Hu7oL6maeBETl7&open=AZ5uo1Hu7oL6maeBETl7&pullRequest=2025

Check warning on line 517 in resource/js/tab-hierarchy.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=NatLibFi_Skosmos&issues=AZ5uo1Hu7oL6maeBETl6&open=AZ5uo1Hu7oL6maeBETl6&pullRequest=2025
{
sensitivity: 'variant',
numeric: window.SKOSMOS.sortByNotation === 'natural'

Check warning on line 520 in resource/js/tab-hierarchy.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=NatLibFi_Skosmos&issues=AZ5uo1Hu7oL6maeBETl5&open=AZ5uo1Hu7oL6maeBETl5&pullRequest=2025
}
)
tabHierApp.config.globalProperties.$fallbackCollator = new Intl.Collator(
window.SKOSMOS.content_lang || window.SKOSMOS.lang,

Check warning on line 524 in resource/js/tab-hierarchy.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=NatLibFi_Skosmos&issues=AZ5uo1Hu7oL6maeBETl4&open=AZ5uo1Hu7oL6maeBETl4&pullRequest=2025

Check warning on line 524 in resource/js/tab-hierarchy.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=NatLibFi_Skosmos&issues=AZ5uo1Hu7oL6maeBETl3&open=AZ5uo1Hu7oL6maeBETl3&pullRequest=2025
{
sensitivity: 'variant',
numeric: false
}
)

tabHierApp.mount('#tab-hierarchy')
}

async function initializeHierarchyApp () {
try {
await window.getIntlCollatorReady()

Check warning on line 536 in resource/js/tab-hierarchy.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=NatLibFi_Skosmos&issues=AZ6IprKn-tP9bpQEjQZc&open=AZ6IprKn-tP9bpQEjQZc&pullRequest=2025
} catch (e) {
console.error('Intl.Collator polyfill failed to load, continuing with native collator:', e)
}
Comment thread
qltysh[bot] marked this conversation as resolved.

startHierarchyApp()
}

onTranslationReady(startHierarchyApp)
onTranslationReady(function () {
if (document.getElementById('tab-hierarchy')) {
if (typeof window.getIntlCollatorReady !== 'function') {

Check warning on line 546 in resource/js/tab-hierarchy.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=NatLibFi_Skosmos&issues=AZ6Mp61LIaTFPUKdCpyv&open=AZ6Mp61LIaTFPUKdCpyv&pullRequest=2025

Check warning on line 546 in resource/js/tab-hierarchy.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected negated condition.

See more on https://sonarcloud.io/project/issues?id=NatLibFi_Skosmos&issues=AZ6Mp61LIaTFPUKdCpyu&open=AZ6Mp61LIaTFPUKdCpyu&pullRequest=2025
// wait for the polyfill promise to be initialized
document.addEventListener('intlCollatorPromiseReady', initializeHierarchyApp)
} else {
initializeHierarchyApp()
}
}
})
42 changes: 42 additions & 0 deletions src/view/scripts.inc.twig
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,48 @@ window.SKOSMOS = {
<!-- Bootstrap -->
<script src="node_modules/bootstrap/dist/js/bootstrap.bundle.js"></script>

<!-- FormatJS Intl.Collator polyfill for expanded locale support -->
<script type="importmap">
{
"imports": {
"@formatjs/intl-localematcher": "./node_modules/@formatjs/intl-localematcher/index.js",
"@formatjs/fast-memoize": "./node_modules/@formatjs/fast-memoize/index.js"
Comment thread
osma marked this conversation as resolved.
}
}
</script>
<script type="module">
function needsCollatorPolyfill(locale) {
try {
const supported = Intl.Collator.supportedLocalesOf([locale])
return supported.length === 0
} catch {
return true; // fallback for old browsers
}
}

async function ensureCollator(locale) {
if (needsCollatorPolyfill(locale)) {
await import('./node_modules/@formatjs/intl-collator/polyfill-force.js')
}
}

// global Promise for loading the polyfill on-demand
let collatorPromise = null

window.getIntlCollatorReady = function () {
if (!collatorPromise) {
const locale = window.SKOSMOS.content_lang || window.SKOSMOS.lang
collatorPromise = ensureCollator(locale)
}
return collatorPromise
}

// custom event to signal that the collator promise has been initialized
const event = new Event('intlCollatorPromiseReady')
document.dispatchEvent(event)

</script>
Comment thread
osma marked this conversation as resolved.

<!-- Vue.js -->
{% if GlobalConfig.uiDevMode %}
<script src="node_modules/vue/dist/vue.global.js"></script>
Expand Down
Loading