Dust.js (Linkedin) helpers that works with Sails JS default i18n hook
- Make sure your Sails app. use Dust.js as template engine
- Install this hook by
npm install sails-hook-dust-i18n
i18n
(can also called by__
)exec
see reference here
requires at least sails >= 0.11
-
There are 2 option that describe main text:
-
Put text in body block, example:
{@i18n}Welcome{/i18n}
or{@__}Welcome{/__}
(bothi18n
and__
has same functionality) -
Put in
t
parameter, example:{@i18n t="Welcome" /}
or{@__ t="Welcome" /}
-
Put arguments in
args
parameter if needed, example:{@i18n args="['guys']" }Welcome %s{/i18n}
will rendered toWelcomen guys
if locales catalog is like{"Welcome %s": "Welcomen %s"}
-
Make sure to define translation in
/config/locales/[locale].js
like/config/locales/en.js
-
That file contains translation in JSON format like
{ "Welcome": "Welcome to Sails!" }
- Sails i18n documentation
- Node-i18n (dependency that sails-hook-i18n rely on)
- Make body block rendering synchronously (look at index.js)
- Add test case, it always thrown an error
Error: Cannot find module '../../../../sails-hooks'
- You suggest ...
MIT