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

RequireJS and Knockout-Validation Localization #492

Closed
hgenru opened this issue Dec 24, 2014 · 4 comments · Fixed by #503 or #506
Closed

RequireJS and Knockout-Validation Localization #492

hgenru opened this issue Dec 24, 2014 · 4 comments · Fixed by #503 or #506
Assignees
Milestone

Comments

@hgenru
Copy link

hgenru commented Dec 24, 2014

How to use the localization files with RequireJS? Now I have to make my desired localization files into custom files.

@crissdev crissdev changed the title ReuiqreJS and Knockout-Validation Localization RequireJS and Knockout-Validation Localization Dec 24, 2014
@crissdev
Copy link
Member

It dependes on your build environment. On way to do it is to preprocess the localization files and wrap them with define so you can require them.

define(['knockout', 'knockout-validation'], function(ko) {

    //...localization file contents
});

If you're using gulp you can do this easily with gulp-wrap-amd plugin.

I can see that it's not possible to use the localization files with RequireJS without wrapping them. I think the best way to fix this issue is to wrap the localization files similar to the way the library is.

@hgenru
Copy link
Author

hgenru commented Dec 24, 2014

And do. Hoping that we can somehow connect a file with requirejs shim. To avoid code duplication.

@crissdev
Copy link
Member

AMD usage example http://embed.plnkr.co/qCu23Cid0D4jlkndPvYy/preview

Node.js

npm install knockout
npm install git://github.com/Knockout-Contrib/Knockout-Validation#master
var kv = require('knockout.validation');

// Helper method to dump each rule's message
function dumpMessages() {
    Object.keys(kv.rules).forEach(function(ruleName) {
        console.log(kv.rules[ruleName].message);
    });
}

// Show the default messages
dumpMessages();

// Localize rules
require('knockout.validation/Localization/ro-RO.js');
dumpMessages();

// Localize rules again
require('knockout.validation/Localization/fr-FR.js');
dumpMessages();

// Reset to previous values
require('knockout.validation/Localization/en-US.js');
dumpMessages();

@crissdev
Copy link
Member

@davhdavh Don't forget to close this issue in your commit. Thanks.

crissdev added a commit that referenced this issue Jan 18, 2015
…een them

The default localization is en-US and it's already included in the library. There's no need
to load it explicitly from en-US.js.

The following localization files have been renamed because their name was invalid:
* no-NB.js → nb-NO.js
* ca-CA.js → ca-ES.js

Closes #492
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment