Skip to content
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

[TAS-2030] 💄 Add inLanguage field for book #471

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
79 changes: 59 additions & 20 deletions components/IscnRegisterForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,25 @@
</div>
</div>
<!-- type -->
<FormField :label="$t('IscnRegisterForm.label.type')" class="mb-[12px]">
<Selector
class="h-[40px] w-[160px]"
:options="typeOptions"
:placeholder="defaultType"
@input="setType"
/>
</FormField>
<div class="flex justify-between mb-[12px]">
<FormField :label="$t('IscnRegisterForm.label.type')">
<Selector
class="h-[40px] w-[160px]"
:options="typeOptions"
:placeholder="defaultType"
@input="setType"
/>
</FormField>
<FormField v-if="isBookType" :label="$t('IscnRegisterForm.label.language')">
<Selector
class="h-[40px] w-[160px]"
:options="languageOptions"
:placeholder="defaultLanguage"
@input="setLanguage"
/>
</FormField>
</div>

<Divider class="my-[12px]" />
<!-- form fieldset -->
<div>
Expand Down Expand Up @@ -691,19 +702,24 @@ export default class IscnRegisterForm extends Vue {
@walletModule.Action('initIfNecessary') initIfNecessary!: () => Promise<any>

typeOptions = [
'Book',
'Photo',
'Image',
'CreativeWork',
]
'Book',
'Photo',
'Image',
'CreativeWork',
]

fileTypeOptions = [
'epub',
'pdf',
'audio',
'jpg',
'png',
]
'epub',
'pdf',
'audio',
'jpg',
'png',
]

languageOptions = [
'zh',
'en',
]

licenseMap: { [key: string]: string | null } = {
'Copyright. All rights reserved.': 'All Rights Reserved',
Expand Down Expand Up @@ -850,6 +866,17 @@ export default class IscnRegisterForm extends Vue {
return 'CreativeWork'
}

get defaultLanguage() {
const containsOnlyASCII = (str: string) => /^[ -~]*$/.test(str);

const isEpubInChinese = this.epubMetadata?.language === 'zh';
Copy link
Member

Choose a reason for hiding this comment

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

Should we respect if epub metadata language is explicitly set to en?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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


const titleContainsNonASCII = this.name && !containsOnlyASCII(this.name)
const descriptionContainsNonASCII = this.description && !containsOnlyASCII(this.description)

return (isEpubInChinese || titleContainsNonASCII || descriptionContainsNonASCII) ? 'zh' : 'en';
}

get authorDialogTitle() {
return this.currentAuthorDialogType === AuthorDialogType.author
? this.$t('IscnRegisterForm.title.editAuthor')
Expand Down Expand Up @@ -1053,6 +1080,10 @@ export default class IscnRegisterForm extends Vue {
return arweaveIdList
}

get isBookType() {
return this.type === 'Book'
}

@Watch('payload', { immediate: true, deep: true })
change() {
this.debouncedCalculateISCNFee()
Expand All @@ -1063,6 +1094,11 @@ export default class IscnRegisterForm extends Vue {
if (errormsg) this.isOpenWarningSnackbar = true
}

@Watch('defaultLanguage', { immediate: true })
setLanguageValue(value: any) {
this.language = value
}

async mounted() {
this.uploadStatus = 'loading'

Expand All @@ -1071,7 +1107,6 @@ export default class IscnRegisterForm extends Vue {
this.description = this.extractText(this.epubMetadata.description)
this.author.name = this.epubMetadata.author || ''
this.author.authorDescription = 'Author'
this.language = this.epubMetadata.language || ''
this.tags = this.epubMetadata.tags || []
this.thumbnailUrl = this.formatArweave(
this.epubMetadata.thumbnailArweaveId,
Expand Down Expand Up @@ -1237,6 +1272,10 @@ export default class IscnRegisterForm extends Vue {
this.type = value
}

setLanguage(value: string) {
this.language = value
}

setLicense(value: string) {
this.license = value
}
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
"IscnRegisterForm.label.registrant": "Registrant",
"IscnRegisterForm.label.tags": "Tags",
"IscnRegisterForm.label.type": "Type",
"IscnRegisterForm.label.language": "Language",
"IscnRegisterForm.label.content": "Content Info",
"IscnRegisterForm.label.uploading": "Loading files...",
"IscnRegisterForm.label.url": "URL",
Expand Down
Loading