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

Override extension language #1753

Closed
sm2017 opened this issue Mar 17, 2019 · 10 comments
Closed

Override extension language #1753

sm2017 opened this issue Mar 17, 2019 · 10 comments
Assignees
Labels
breaking changes Change that can breaking existing code bug Bug or defect
Milestone

Comments

@sm2017
Copy link

sm2017 commented Mar 17, 2019

According to https://github.com/hapijs/joi/blob/master/API.md#validatevalue-schema-options-callback we can pass options.language to validate to override languages

I have a multi-language application , I successfully override Joi core languages such as object.max

But I cannot override extension languages

const BaseJoi = require('joi');
const JoiPhoneNumberExtensions = require('joi-phone-number-extensions');
const Joi = BaseJoi.extend(JoiPhoneNumberExtensions);

const schema = Joi.phoneNumber().defaultRegion('US').type('MOBILE').format('E164');
BaseJoi.validate(
    'invalid phone',
    schema,
    {
        language:{
             phoneNumber : {
                base: 'base overrided',
                region: 'region overrided',
                emptyFieldRef: 'emptyFieldRef overrided',
                illegalRefRegion: 'illegalRefRegion overrided',
                type: 'type overrided',
                format: 'format overrided',
            }
        },
    },
    (err, value) => {
        console.log(err)
    }
);
@sm2017
Copy link
Author

sm2017 commented Mar 24, 2019

@Marsup can you please reply?

@Marsup Marsup added the bug Bug or defect label Mar 24, 2019
@Marsup
Copy link
Collaborator

Marsup commented Mar 24, 2019

I recognize this is a bug, extensions are considering language as local options (which always override global options) which prevents language overriding. I'm not sure I'll be able to fix it quickly so unless you can maybe you'll have better luck post-processing the errors from the details array which is I think a better way of doing i18n, there are npm modules doing it for you I think.

@sm2017
Copy link
Author

sm2017 commented Mar 31, 2019

@Marsup can you tell me , when you can fix it?

@sm2017
Copy link
Author

sm2017 commented Apr 2, 2019

@Marsup reply please

@WesTyler
Copy link
Contributor

WesTyler commented Apr 2, 2019

Not the best way to get a response, honestly. I can assure you he has not forgotten this, and does keep up with issues and bugs; so if you haven't gotten a response in 2 days it's probably because he is busy with his full-time job (which is not Joi maintenance).

@sm2017
Copy link
Author

sm2017 commented Apr 3, 2019

@WesTyler OK , sorry

@Marsup Marsup self-assigned this Apr 6, 2019
@Marsup Marsup added this to the 15.0.1 milestone Apr 6, 2019
@Marsup Marsup added the breaking changes Change that can breaking existing code label Apr 6, 2019
@Marsup Marsup closed this as completed in b8109b9 Apr 6, 2019
@Marsup
Copy link
Collaborator

Marsup commented Apr 6, 2019

Even though this is technically a breaking change, I'm going to put it out there as a patch because it was a misguided implementation.

@sm2017
Copy link
Author

sm2017 commented Apr 28, 2019

@Marsup When you release 15.0.1?

@Marsup
Copy link
Collaborator

Marsup commented Apr 30, 2019

It is now.

@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking changes Change that can breaking existing code bug Bug or defect
Projects
None yet
Development

No branches or pull requests

3 participants