11import { createSelector } from 'reselect' ;
2- import { createCachedSelector } from 're-reselect' ;
32import { PropertyValue , Utils , Resource } from 'manifesto.js' ;
43import getThumbnail from '../../lib/ThumbnailFactory' ;
54import asArray from '../../lib/asArray' ;
@@ -24,9 +23,10 @@ export const getLocale = createSelector(
2423 [
2524 getCompanionWindowLocale ,
2625 getConfig ,
26+ ( state , { locale } ) => locale ,
2727 ] ,
28- ( companionWindowLocale , config = { } ) => (
29- companionWindowLocale || config . language
28+ ( companionWindowLocale , config = { } , locale ) => (
29+ locale || companionWindowLocale || config . language || config . fallbackLanguages
3030 ) ,
3131) ;
3232
@@ -57,17 +57,9 @@ export const getManifestError = createSelector(
5757) ;
5858
5959/** Instantiate a manifesto instance */
60- const getContextualManifestoInstance = createCachedSelector (
60+ const getContextualManifestoInstance = createSelector (
6161 getManifest ,
62- getLocale ,
63- ( manifest , locale ) => manifest
64- && createManifestoInstance ( manifest . json , locale ) ,
65- ) (
66- ( state , { companionWindowId, manifestId, windowId } ) => [
67- manifestId ,
68- windowId ,
69- getLocale ( state , { companionWindowId } ) ,
70- ] . join ( ' - ' ) , // Cache key consisting of manifestId, windowId, and locale
62+ manifest => manifest && createManifestoInstance ( manifest . json ) ,
7163) ;
7264
7365/**
@@ -80,15 +72,14 @@ const getContextualManifestoInstance = createCachedSelector(
8072export const getManifestoInstance = createSelector (
8173 getContextualManifestoInstance ,
8274 ( state , { json } ) => json ,
83- getLocale ,
84- ( manifesto , manifestJson , locale ) => (
75+ ( manifesto , manifestJson ) => (
8576 manifestJson && createManifestoInstance ( manifestJson , locale )
8677 ) || manifesto ,
8778) ;
8879
8980export const getManifestLocale = createSelector (
90- [ getManifestoInstance ] ,
91- manifest => manifest && manifest . options && manifest . options . locale && manifest . options . locale . replace ( / - .* $ / , '' ) ,
81+ [ getManifestoInstance , getLocale ] ,
82+ ( manifest , locale ) => locale ?? ( manifest && manifest . options && manifest . options . locale && manifest . options . locale . replace ( / - .* $ / , '' ) ) ,
9283) ;
9384
9485/** */
@@ -128,7 +119,7 @@ export const getManifestProviderName = createSelector(
128119 ] ,
129120 ( provider , locale ) => provider
130121 && provider [ 0 ] . label
131- && PropertyValue . parse ( provider [ 0 ] . label , locale ) . getValue ( ) ,
122+ && PropertyValue . parse ( provider [ 0 ] . label ) . getValue ( locale ) ,
132123) ;
133124
134125/**
@@ -173,8 +164,8 @@ export const getManifestHomepage = createSelector(
173164 ( homepages , locale ) => homepages
174165 && asArray ( homepages ) . map ( homepage => (
175166 {
176- label : PropertyValue . parse ( homepage . label , locale )
177- . getValue ( ) ,
167+ label : PropertyValue . parse ( homepage . label )
168+ . getValue ( locale ) ,
178169 value : homepage . id || homepage [ '@id' ] ,
179170 }
180171 ) ) ,
@@ -189,11 +180,11 @@ export const getManifestHomepage = createSelector(
189180 * @returns {string|null }
190181 */
191182export const getManifestRenderings = createSelector (
192- [ getManifestoInstance ] ,
193- manifest => manifest
183+ [ getManifestoInstance , getManifestLocale ] ,
184+ ( manifest , locale ) => manifest
194185 && manifest . getRenderings ( ) . map ( rendering => (
195186 {
196- label : rendering . getLabel ( ) . getValue ( ) ,
187+ label : rendering . getLabel ( ) . getValue ( locale ) ,
197188 value : rendering . id ,
198189 }
199190 ) ) ,
@@ -216,8 +207,8 @@ export const getManifestSeeAlso = createSelector(
216207 && asArray ( seeAlso ) . map ( related => (
217208 {
218209 format : related . format ,
219- label : PropertyValue . parse ( related . label , locale )
220- . getValue ( ) ,
210+ label : PropertyValue . parse ( related . label )
211+ . getValue ( locale ) ,
221212 value : related . id || related [ '@id' ] ,
222213 }
223214 ) ) ,
@@ -257,8 +248,8 @@ export const getManifestRelated = createSelector(
257248 }
258249 : {
259250 format : related . format ,
260- label : PropertyValue . parse ( related . label , locale )
261- . getValue ( ) ,
251+ label : PropertyValue . parse ( related . label )
252+ . getValue ( locale ) ,
262253 value : related . id || related [ '@id' ] ,
263254 }
264255 ) ) ,
@@ -273,13 +264,13 @@ export const getManifestRelated = createSelector(
273264 * @returns {string|null }
274265 */
275266export const getRequiredStatement = createSelector (
276- [ getManifestoInstance ] ,
277- manifest => manifest
267+ [ getManifestoInstance , getManifestLocale ] ,
268+ ( manifest , locale ) => manifest
278269 && asArray ( manifest . getRequiredStatement ( ) )
279270 . filter ( l => l && l . getValues ( ) . some ( v => v ) )
280271 . map ( labelValuePair => ( {
281- label : ( labelValuePair . label && labelValuePair . label . getValue ( ) ) || null ,
282- values : labelValuePair . getValues ( ) ,
272+ label : ( labelValuePair . label && labelValuePair . label . getValue ( locale ) ) || null ,
273+ values : labelValuePair . getValues ( locale ) ,
283274 } ) ) ,
284275) ;
285276
@@ -299,7 +290,7 @@ export const getRights = createSelector(
299290 ] ,
300291 ( rights , license , locale ) => {
301292 const data = rights || license ;
302- return asArray ( PropertyValue . parse ( data , locale ) . getValues ( ) ) ;
293+ return asArray ( PropertyValue . parse ( data ) . getValues ( locale ) ) ;
303294 } ,
304295) ;
305296
@@ -333,9 +324,9 @@ export function getManifestThumbnail(state, props) {
333324 * @returns {string }
334325 */
335326export const getManifestTitle = createSelector (
336- [ getManifestoInstance ] ,
337- manifest => manifest
338- && manifest . getLabel ( ) . getValue ( ) ,
327+ [ getManifestoInstance , getManifestLocale ] ,
328+ ( manifest , locale ) => manifest
329+ && manifest . getLabel ( ) . getValue ( locale ) ,
339330) ;
340331
341332/**
@@ -366,7 +357,7 @@ export const getManifestSummary = createSelector(
366357 getManifestLocale ,
367358 ] ,
368359 ( summary , locale ) => summary
369- && PropertyValue . parse ( summary , locale ) . getValue ( locale ) ,
360+ && PropertyValue . parse ( summary ) . getValue ( locale ) ,
370361) ;
371362
372363/**
@@ -391,11 +382,11 @@ export const getManifestUrl = createSelector(
391382 * @param iiifResource
392383 * @returns {Array[Object] }
393384 */
394- export function getDestructuredMetadata ( iiifResource ) {
385+ export function getDestructuredMetadata ( iiifResource , locale = undefined ) {
395386 return ( iiifResource
396387 && iiifResource . getMetadata ( ) . map ( labelValuePair => ( {
397- label : labelValuePair . getLabel ( ) ,
398- values : labelValuePair . getValues ( ) ,
388+ label : labelValuePair . getLabel ( locale ) ,
389+ values : labelValuePair . getValues ( locale ) ,
399390 } ) )
400391 ) ;
401392}
@@ -409,8 +400,8 @@ export function getDestructuredMetadata(iiifResource) {
409400 * @returns {Array[Object] }
410401 */
411402export const getManifestMetadata = createSelector (
412- [ getManifestoInstance ] ,
413- manifest => manifest && getDestructuredMetadata ( manifest ) ,
403+ [ getManifestoInstance , getManifestLocale ] ,
404+ ( manifest , locale ) => manifest && getDestructuredMetadata ( manifest , locale ) ,
414405) ;
415406
416407/** */
0 commit comments