-
Notifications
You must be signed in to change notification settings - Fork 25
fix: Metadata.serialize() sortAs and undefined language tag #178
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
base: develop
Are you sure you want to change the base?
Conversation
|
So funny story, I will have to check if there is any side-effect re. const test = { undefined: "unknown", en: "english", fr: "french" }
test["en"] // Returns "english"
test[undefined] // Note the lack of quotes. Returns "unknown"So I’ll have to check pretty much all packages for this, to see whether things accidentally worked because |
JayPanoz
left a comment
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.
Thanks. This helped us spot an inconsistency in RWPM schemas.
So it is expected sortAs should be treated as a LocalizedString, like title and subtitle, and that they should then all use the same method for serialisation – otherwise data is lost.
As for und thanks for switching to this. I will update tests following the merge so that you don’t have to as I already did it when reviewing this PR.
| if (this.altIdentifier) json.altIdentifier = this.altIdentifier.serialize(); | ||
| if (this.subtitle) json.subtitle = this.subtitle.serialize(); | ||
| if (this.sortAs) json.sortAs = this.sortAs.serialize(); | ||
| if (this.sortAs) json.sortAs = this.sortAs.getTranslation(); |
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 allowed us to spot an inconsistency in the RWPM schema, where sortAs in Metadata was effectively correct, but sortAs in Contributor and Subject were not.
In any case, its serialization has to be consistent with title and subtitle as they are using the same type, LocalizedString.
Note I’ve merged a fix in #183, and updated the schema in readium/webpub-manifest#128 (comment)
Maintainers of the other toolkits have been informed of this change.
| if (this.altIdentifier) json.altIdentifier = this.altIdentifier.serialize(); | ||
| if (this.subtitle) json.subtitle = this.subtitle.serialize(); | ||
| if (this.sortAs) json.sortAs = this.sortAs.serialize(); | ||
| if (this.sortAs) json.sortAs = this.sortAs.getTranslation(); |
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.
| if (this.sortAs) json.sortAs = this.sortAs.getTranslation(); | |
| if (this.sortAs) json.sortAs = this.sortAs.serialize(); |
| public readonly translations: { [key: string]: string }; | ||
|
|
||
| public static readonly UNDEFINED_LANGUAGE = 'undefined'; | ||
| public static readonly UNDEFINED_LANGUAGE = 'und'; |
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.
Note I will have to update tests directly after this is merged, as they currently fail due to undefined being used for LocalizedString
I discovered that when calling Manifest.serialize() it did not return correctly for sortAs in metadata and that undefined language did not use a correct BCP-47 tag. This PR should fix it.