Closed schniper closed 9 years ago
What version are you using, master or latest tagged (1.3.2)? How are you adding the lang exactly?
Hey, I've been using master. Added a new lanhg file in src/lang, but the issue happens with English as well.The reason seems to be that the require mapping is available in the main js file, but not from the _lang.js one.
Costin
Unless otherwise stated, this e-mail message, its attachments and all future replies and attachments related to it are to be considered confidential and exclusive property of their senders/authors. Copying and/or distributing any of them in their entirety or in part for a purpose outside their scope (as considered/defined by the sender) is forbidden in the absence of a prior consent from the sender. If you have received this message by mistake, please be so kind to delete it and notify the sender.
Preserve the environment - do you really need to print a copy of this e-mail?
On Sat, Aug 29, 2015 at 6:23 AM -0700, "Gary Green" notifications@github.com wrote:
What version are you using, master or latest tagged (1.3.2)? How are you adding the lang exactly?
— Reply to this email directly or view it on GitHub.
Hmm to be honest I didn't consider adding a language file thru browserify in the actual build. Idea was to use Validator.setMessages
and Validator.useLang
to add a new language. It would be cool to have the ability to add a custom language file into the browserify build though.
I had a bit of a headache trying to get browserify to see the language files at all, and exclude the russian language by default. Had to pretty much hack it in .
I'm not sure it's even possible, as browserify needs a concrete path supplied to require
in order to add it to the build ? Any idea?
Actually thinking about it you could do this by passing custom browserify parameters to --require
your language file and also alias it so it appears as ./lang/<code>
-- does that work?
Thanks, I’ll give it a shot asap!
From: Gary Green Reply-To: skaterdav85/validatorjs Date: Tuesday 1 September 2015 at 11:40 To: skaterdav85/validatorjs Cc: Costin Bereveanu Subject: Re: [validatorjs] Language loading clarification (#58)
Actually thinking about it you could do this by passing custom browserify parameters to --require your language file and also alias it so it appears as ./lang/ -- does that work?
— Reply to this email directly or view it on GitHub.
This may help
https://gist.github.com/defunctzombie/4339901#replace-specific-files---advanced
Just add a browser
field to your package.json which browserify will read.
On 1 September 2015 at 09:44, Costin Bereveanu notifications@github.com wrote:
Thanks, I’ll give it a shot asap!
From: Gary Green Reply-To: skaterdav85/validatorjs Date: Tuesday 1 September 2015 at 11:40 To: skaterdav85/validatorjs Cc: Costin Bereveanu Subject: Re: [validatorjs] Language loading clarification (#58)
Actually thinking about it you could do this by passing custom browserify parameters to --require your language file and also alias it so it appears as ./lang/
-- does that work?
— Reply to this email directly or view it on GitHub.
— Reply to this email directly or view it on GitHub https://github.com/skaterdav85/validatorjs/issues/58#issuecomment-136637829 .
Hopefully latest commit fixes this. Can you try for me please? https://github.com/skaterdav85/validatorjs/commit/e5af583288cd1d18912a8564a0aa2bb34236a2c6
It seems to be fine, thanks. For a second language (Romanian), I have added a new lang/ro.js file in my browserify enabled folder and the following in my main app file: Validator.setMessages('ro', require('./vendor/validatorjs/lang/ro')); Validator.useLang('ro'); This approach works quite well and leaves the default library code untouched.
Thanks!
From: Gary Green Reply-To: skaterdav85/validatorjs Date: Friday 4 September 2015 at 15:26 To: skaterdav85/validatorjs Cc: Costin Bereveanu Subject: Re: [validatorjs] Language loading clarification (#58)
Hopefully latest commit fixes this. Can you try for me please? e5af583
— Reply to this email directly or view it on GitHub.
Hey, Maybe I'm looking at this the wrong way, but in order to get a browserify setup to load a language file, I had to move the langs function from validator.js to _lang.js. Otherwise a module not found would be reported for ./lang/code. Any thoughts on this? Thanks!