Skip to content

KAPOW - Localization support

Latest
Compare
Choose a tag to compare
@grofit grofit released this 30 Nov 21:15
· 40 commits to master since this release

Localization

So out the box Treacherous now has support for different locales and has separated the validation messages from the actual validation rules. As with everything else the rule name/code is used as the contract between the messages. By default en-us will be loaded (its bundled with the project), but you can easily add your own custom messages to this as well as adding your own languages to it.

The current implementation will work fine for most simple examples, but it has been built with extensibility in mind, so for those of you who use i18n based frameworks you can make your own custom ILocaleHandler implementations which can take the locale codes (i.e en-us and the tags then do the relevant transforming on them.

There is a page in the docs about this subject, containing an example async loader that could go to back ends/apis etc, so this should hopefully get people up and running in the multilingual world.

This is a first pass, so the implementation may mature a bit once there is more feedback but for now should hopefully make things a little easier for everyone.

(You can still override the message per property rule via the builder, but it is rare you would need to)

Minor linting tweaks

This update has a few minor changes around the codebase, mainly to bring things in line with the linter so the code is no longer using var and instead using more concise const or let as well as upping the TS version used.

Dropping AMD support

The AMD modules were rarely used, and most module packaging systems these days can cope with commonJS and es2015 modules, so this version bundles those 2 versions, the main pointing to a commonjs implementation, and the module definition for webpack and other tools pointing to the es2015 implementation to allow for tree shaking.