3.0.1 • Published 3 months ago

ms-mailer-templates v3.0.1

Weekly downloads
209
License
MIT
Repository
github
Last release
3 months ago

Templates for Mailer Microservice

Build Status

Uses foundation ink by zurb for creating basic responsive styles. By default includes the most simple templates for account activation and password reset.

Installation

npm i ms-mailer-templates -S

Usage

const render = require('ms-mailer-templates');

const ctx = { link: 'http://localhost', qs: '?token=xxxxx', username: 'Indiana Johns' };
render('activate', ctx,  optionalHandlebarsOpts )
  .then(template => {
    // get rendered template
  });

It checks for incorrect context, missing template and so on

i18n

The package uses i18next library to provide translations.

Usage

Provide lng option among other context options to specify destination language when rendering templates. The following code will return html for activate email template translated into german.

const render = require('ms-mailer-templates');

render('activate', { lng: 'de' })
  .then(translatedTemplate => {
    ...
  });

Translation helper

Package exports a simple translation helper as a property of the default export.

render.translate(key, { lng, ...rest });

Where key is the key of the string to be translated, lng - target language, rest - other translation context options

Usage example:

const render = require('ms-mailer-templates');

// returns translated string when translation is available 
// for 'de' language and 'custom' namespace
const txt = render.translate('custom:|Count {{count}}', { lng: 'de', count: 10 });

Guides

To add i18n support for existing or new templates one must wrap strings to be translated into t handlebars helper.

<div>
  {{t "String to translate"}}
</div>

Namespaces

Default package's i18n namespace is emails. All strings fall into this namespace unless specifically stated otherwise. When one has separate translation project they can put their own strings into separate namespace. :| works as the namespace separator.

<span>{{t "my-own-ns:|something to be translated"}}</span>

Then add your newly created namespace to the list of supported namespaces in src/i18n.js file:

const SUPPORTED_NAMESPACES = [
  'emails',
  'your-new-namespace',
  ...
]

The package uses en locale as a reference and fallbacks to the key contents when no translation is provided.

Parsing

All strings wrapped with t helper will be parsed into en locale.

Command

yarn i18n:parse

will parse all src/templates/**/*.html files and store all collected strings under i18n-parsed directory with structure as follows:

...
└──i18n-parsed
   └──en
      ├── emails.json
      └── custom-namespace.json

Translations

All translated resources must be provided as flat json files under i18n directory following the i18n/{{language}}{{namespace}}.json filename template.

...
└──i18n
   ├──en
   │   ├── emails.json
   │   └── custom-namespace.json
   ├──de
   │   ├── emails.json
   │   └── custom-namespace.json
   │   ...

Existing templates

General

  1. password
  2. reset

Radio FX

  1. activate
  2. invite
  3. report-problem
  4. request-invite
  5. support-contact

StreamLayer

  1. accept-invite
  2. add-member-notify
  3. feedback
  4. registration-notify
  5. password-reset

Roadmap

  1. Add more templates
3.0.1

3 months ago

2.4.1

2 years ago

2.4.0

3 years ago

2.3.0

3 years ago

2.2.6

3 years ago

2.2.5

3 years ago

2.2.4

3 years ago

2.2.3

3 years ago

2.2.2

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.1.3

3 years ago

2.1.2

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

2.0.0-rc.1

3 years ago

1.21.0-rc.6

3 years ago

1.21.0-rc.5

3 years ago

1.21.0-rc.3

3 years ago

1.21.0-rc.4

3 years ago

1.21.0-rc.1

3 years ago

1.21.0-rc.2

3 years ago

1.20.5

3 years ago

1.20.6

3 years ago

1.20.4

3 years ago

1.20.2

3 years ago

1.20.3

3 years ago

1.20.1

3 years ago

1.20.0

3 years ago

1.19.2

3 years ago

1.19.1

3 years ago

1.19.0

3 years ago

1.18.0

3 years ago

1.17.0

4 years ago

1.16.0

4 years ago

1.15.0

4 years ago

1.14.1

5 years ago

1.14.0

5 years ago

1.13.1

5 years ago

1.13.0

5 years ago

1.12.0

5 years ago

1.11.1

5 years ago

1.11.0

5 years ago

1.10.0

6 years ago

1.9.6

6 years ago

1.9.5

6 years ago

1.9.4

6 years ago

1.9.3

6 years ago

1.9.2

6 years ago

1.9.1

6 years ago

1.9.0

6 years ago

1.8.0

6 years ago

1.7.4

6 years ago

1.7.3

6 years ago

1.7.2

6 years ago

1.7.1

6 years ago

1.7.0

6 years ago

1.6.1

6 years ago

1.6.0

6 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.4

7 years ago

1.4.3

7 years ago

1.4.2

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.16.0

7 years ago

0.15.0

8 years ago

0.14.1

8 years ago

0.14.0

8 years ago

0.13.1

8 years ago

0.13.0

8 years ago

0.12.0

8 years ago

0.11.0

8 years ago

0.10.1

8 years ago

0.10.0

8 years ago

0.9.0

8 years ago

0.8.0

8 years ago

0.7.1

8 years ago

0.7.0

8 years ago

0.6.1

8 years ago

0.6.0

8 years ago

0.5.0

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.0.1

8 years ago