-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4054 from ProjectMirador/manifest-getValue-locale2
Refactor manifesto initialization to push property localization down
- Loading branch information
Showing
17 changed files
with
200 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useContext } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
getLocale, | ||
} from '../state/selectors'; | ||
import LocaleContext from '../contexts/LocaleContext'; | ||
|
||
/** | ||
* Render the contextually appropriate label for the resource | ||
*/ | ||
export function IIIFResourceLabel({ fallback, resource }) { | ||
const contextLocale = useContext(LocaleContext); | ||
const fallbackLocale = useSelector(state => getLocale(state, {})); | ||
|
||
if (!resource) return fallback; | ||
|
||
const label = resource.getLabel(); | ||
|
||
if (!label) return fallback; | ||
|
||
return label.getValue(contextLocale || fallbackLocale || '') ?? (fallback || resource.id); | ||
} | ||
|
||
IIIFResourceLabel.propTypes = { | ||
fallback: PropTypes.string, | ||
resource: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types | ||
}; |
Oops, something went wrong.