Skip to content

Translation with "optimistdigital/nova-translatable" #30

@julianlaibach

Description

@julianlaibach

Hey there,
thank you for your great Package!

Recently i needed to get it working with the Package: "optimistdigital/nova-translatable" and found a pretty easy way to get it working.

In "resources/js/components/SluggableText/FormField.vue" in Line 27 (handleChange()) i edited the Function like this:

handleChange(event) {            
    let lang = this.field.attribute.split('.').length() > 1
        ? this.field.attribute.split('.').pop()
        : null
    let name = this.slugField

    if(lang) {
        name += '-' + lang
    }

    Nova.$emit('field-update-' + event.type + '-' + name, {
        value: event.target.value
    })
},

In "resources/js/components/Slug/FormField.vue" in Line 39 (mounted()) i edited the Function like this:

mounted() {
    const eventType = this.field.options.event || 'keyup';
    let lang = this.field.attribute.split('.').length() > 1
        ? this.field.attribute.split('.').pop()
        : null
    let name = this.field.name
    
    if(lang) {
        name += '-' + lang
    }

    Nova.$on('field-update-' + eventType + '-' + name, ({value}) => {
        this.generateSlug(value)
    })
},

This also works without translatable. Maybe you can integrate this to the existing Package.

Best
Julian

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions