setLocale() method

Set the locale and the localization data
setLocale(locale: String, localization: Object): Core
(* denotes a required parameter)
ParameterTypeDescription
locale*StringThe locale in the format of countrycode_LANGUAGECODE (en_US, de_DE, fr_FR, vi_VN, for example)
localization*ObjectAn object containing the translation of all validators
This method is useful when you want to switch to another locale. See the L10n plugin for an example.
You can access the translation directly from the packages located in the dist/js/locates folder:
<script src="/vendors/@form-validation/umd/bundle/popular.min.js"></script>
<!--
You can include many language packages as you want. Their order don't matter
as you ensure that they are loaded after FormValidation(.min).js
-->
<script src="/vendors/@form-validation/umd/locales/en_US.min.js"></script>
<script src="/vendors/@form-validation/umd/locales/fr_FR.min.js"></script>
<script src="/vendors/@form-validation/umd/locales/vi_VN.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function(e) {
const fv = FormValidation.formValidation(
document.getElementById('demoForm'),
{
...
}
);
// Access the English translation package
const englishTranslation = FormValidation.locales.en_US;
// Switch error messages to English
fv.setLocale('en_US', englishTranslation);
});
</script>

See also