npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ms-mailer-templates

v3.0.1

Published

Templates for mailer microservice

Downloads

258

Readme

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