-
Notifications
You must be signed in to change notification settings - Fork 255
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
Refactor property value internationalization (fixes #3470) #3482
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<meta name="theme-color" content="#000000"> | ||
<title>Mirador</title> | ||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500"> | ||
</head> | ||
<body> | ||
<div id="mirador" style="position: absolute; top: 0; bottom: 0; left: 0; right: 0;"></div> | ||
<script>document.write("<script type='text/javascript' src='../../../dist/mirador.min.js?v=" + Date.now() + "'><\/script>");</script> | ||
<script type="text/javascript"> | ||
var baseUrl = window.location.href.substring( | ||
0, window.location.href.indexOf(window.location.pathname)); | ||
var miradorInstance = Mirador.viewer({ | ||
id: 'mirador', | ||
language: 'de', | ||
theme: { | ||
transitions: window.location.port === '4488' ? { create: () => 'none' } : {}, | ||
}, | ||
windows: [{ | ||
manifestId: window. window.location.port | ||
? `${baseUrl}/version-2/i18n.json` | ||
: `${baseUrl}/__tests__/fixtures/version-2/i18n.json`, | ||
thumbnailNavigationPosition: 'far-bottom', | ||
showLocalePicker: true, | ||
}], | ||
catalog: [ | ||
{ manifestId: 'https://iiif.bodleian.ox.ac.uk/iiif/manifest/e32a277e-91e2-4a6d-8ba6-cc4bad230410.json' }, | ||
{ manifestId: 'https://iiif.harvardartmuseums.org/manifests/object/299843' }, | ||
{ manifestId: "https://media.nga.gov/public/manifests/nga_highlights.json", provider: "National Gallery of Art"}, | ||
{ manifestId: "https://data.ucd.ie/api/img/manifests/ucdlib:33064", provider: "Irish Architectural Archive"}, | ||
{ manifestId: "https://wellcomelibrary.org/iiif/b18035723/manifest", provider: "Wellcome Library"}, | ||
{ manifestId: "https://demos.biblissima.fr/iiif/metadata/florus-dispersus/manifest.json", provider: "Biblissima"}, | ||
{ manifestId: "https://www.e-codices.unifr.ch/metadata/iiif/gau-Fragment/manifest.json", provider: "e-codices - Virtual Manuscript Library of Switzerland"}, | ||
{ manifestId: "https://wellcomelibrary.org/iiif/collection/b18031511", provider: "Wellcome Library"}, | ||
{ manifestId: "https://gallica.bnf.fr/iiif/ark:/12148/btv1b10022508f/manifest.json", provider: "Bibliothèque nationale de France"}, | ||
{ manifestId: "https://manifests.britishart.yale.edu/Osbornfa1", provider: "Beinecke Rare Book and Manuscript Library, Yale University"}, | ||
{ manifestId: "https://iiif.biblissima.fr/chateauroux/B360446201_MS0005/manifest.json", provider: "Biblissima"}, | ||
{ manifestId: "https://iiif.durham.ac.uk/manifests/trifle/32150/t1/m4/q7/t1m4q77fr328/manifest", provider: "Durham University Library"}, | ||
//{ manifestId: "https://iiif.vam.ac.uk/collections/O1023003/manifest.json", provider: "Ocean liners"}, | ||
{ manifestId: "https://zavicajna.digitalna.rs/iiif/iiif/api/presentation/2/4aa44ad1-0b74-4590-ab09-534a38cb7c53%252F00000001%252Fostalo01%252F00000012/manifest", provider: "Библиотека 'Милутин Бојић'"}, | ||
] | ||
}); | ||
</script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,11 +30,11 @@ const reorder = (list, startIndex, endIndex) => { | |
/** */ | ||
export class CanvasLayers extends Component { | ||
/** */ | ||
static getUseableLabel(resource, index) { | ||
static getUseableLabel(resource, index, langs) { | ||
return (resource | ||
&& resource.getLabel | ||
&& resource.getLabel().length > 0) | ||
? resource.getLabel().getValue() | ||
? resource.getLabel().getValue(langs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remind me of the manifesto behavior if there's no label in a given language? Is there a fallback or something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently the behavior is to simply pick the first value, with no regard for the (legacy) |
||
: String(index + 1); | ||
} | ||
|
||
|
@@ -117,6 +117,7 @@ export class CanvasLayers extends Component { | |
renderLayer(resource, index) { | ||
const { | ||
classes, | ||
languages, | ||
layerMetadata, | ||
t, | ||
} = this.props; | ||
|
@@ -143,7 +144,7 @@ export class CanvasLayers extends Component { | |
component="div" | ||
variant="body1" | ||
> | ||
{CanvasLayers.getUseableLabel(resource, index)} | ||
{CanvasLayers.getUseableLabel(resource, index, languages)} | ||
<div> | ||
<MiradorMenuButton aria-label={t(layer.visibility ? 'layer_hide' : 'layer_show')} edge="start" size="small" onClick={() => { this.setLayerVisibility(resource.id, !layer.visibility); }}> | ||
{ layer.visibility ? <VisibilityIcon /> : <VisibilityOffIcon /> } | ||
|
@@ -265,6 +266,7 @@ CanvasLayers.propTypes = { | |
classes: PropTypes.objectOf(PropTypes.string), | ||
index: PropTypes.number.isRequired, | ||
label: PropTypes.string.isRequired, | ||
languages: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
layerMetadata: PropTypes.objectOf(PropTypes.shape({ | ||
opacity: PropTypes.number, | ||
})), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,12 @@ import getThumbnail from '../lib/ThumbnailFactory'; | |
*/ | ||
export class IIIFThumbnail extends Component { | ||
/** */ | ||
static getUseableLabel(resource, index) { | ||
static getUseableLabel(resource, langs) { | ||
return (resource | ||
&& resource.getLabel | ||
&& resource.getLabel().length > 0) | ||
? resource.getLabel().getValue() | ||
: String(index + 1); | ||
? resource.getLabel().getValue(langs) | ||
: resource.id; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Just checked, |
||
} | ||
|
||
/** | ||
|
@@ -129,9 +129,9 @@ export class IIIFThumbnail extends Component { | |
|
||
/** */ | ||
label() { | ||
const { label, resource } = this.props; | ||
const { label, resource, languages } = this.props; | ||
|
||
return label || IIIFThumbnail.getUseableLabel(resource); | ||
return label || IIIFThumbnail.getUseableLabel(resource, languages); | ||
} | ||
|
||
/** | ||
|
@@ -180,6 +180,7 @@ IIIFThumbnail.propTypes = { | |
imagePlaceholder: PropTypes.string, | ||
label: PropTypes.string, | ||
labelled: PropTypes.bool, | ||
languages: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
maxHeight: PropTypes.number, | ||
maxWidth: PropTypes.number, | ||
resource: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,11 +17,17 @@ export class LocalePicker extends Component { | |
const { | ||
availableLocales, | ||
classes, | ||
locale, | ||
setLocale, | ||
userLanguages, | ||
} = this.props; | ||
let { locale } = this.props; | ||
|
||
if (!setLocale || availableLocales.length < 2) return <></>; | ||
// If `locale` is not among the available locales, it should be the first available | ||
// locale that matches the language preferences from the `userLanguages` store value | ||
if (availableLocales.indexOf(locale) < 0) { | ||
locale = userLanguages.find(l => availableLocales.indexOf(l) >= 0) ?? availableLocales[0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we push a default fallback locale into settings? It probably shouldn't happen, but 🤷 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, there's already the |
||
} | ||
return ( | ||
<FormControl> | ||
<Select | ||
|
@@ -55,11 +61,13 @@ LocalePicker.propTypes = { | |
classes: PropTypes.objectOf(PropTypes.string), | ||
locale: PropTypes.string, | ||
setLocale: PropTypes.func, | ||
userLanguages: PropTypes.arrayOf(PropTypes.string), | ||
}; | ||
|
||
LocalePicker.defaultProps = { | ||
availableLocales: [], | ||
classes: {}, | ||
locale: '', | ||
setLocale: undefined, | ||
userLanguages: [], | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably goes for all these label helpers... I wonder if we should refactor these back into the instance, now that they depend on some state data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a good idea, yes! Or maybe refactor it into a utility function? I've seen this exact static method (and minor variations of it) in more than a handful components.