-
Notifications
You must be signed in to change notification settings - Fork 379
Localization
If your application needs to display the validation messages in multiple languages, you can take advantage of the localization files available in the Localization
directory. If you can't find the one you need feel free to submit a PR for it.
Since some applications may be using an AMD loader like RequireJS
, others just script
tags, or maybe Browserify
with npm modules, the content of this page is split in sections for each usage.
Add a reference to the localization files, after Knockout-Validation plugin, and dynamically change the language when needed. In previous versions of the library, loading a localization file would immediately update the validation messages. Starting with version 2.0.0
this must be explicitly made by calling ko.validation.locale
and prodide a locale ID.
<script type="text/javascript" src="knockout.validation.js"></script>
<script type="text/javascript" src="el-GR.js"></script>
<script type="text/javascript" src="fr-FR.js"></script>
<script>
// Change validation messages to be in French
ko.validation.locale('fr-FR');
</script>
A working example can be found here.
Although you may be using a different AMD loader you should still be able to use the localization files. The required steps to make this work is not different than what you would do for other libraries, except that you need to ensure you load Knockout-Validation first.
Since RequireJS configurations can be very different, instead of dumping something here, I created an example for it, available here.
This section will be updated when the npm package is published.