Display an adapted SweetAlert for i18n translations.
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
demo/images
i18n
.gitignore
LICENSE
README.md
alert-i18n-tests.js
alert-i18n.js
package-tap.i18n
package.js

README.md

meteor-alert-i18n

Display an adapted SweetAlert for i18n translations.

meteor add smaltcreation:alert-i18n

Usage

Basic

The package will display client side a SweetAlert with translated messages according to your locale and type. Mine is fr_FR.

  Alert.open('error.bad-request')

In your i18n JSON file like i18n/fr.i18n.json:

  error": {
    "bad-request": {
      "title": "Requête invalide",
      "text": "Votre requête est invalide."
    }
  }

SweetAlert example 1

Some translations are already provided in the package, but you can make your own translations in your project. It will also override the provided translations if you set the same key.

Error object

  try {
    throw Meteor.Error('bad-request')
  } catch (e) {
    Alert.open(e);
  }

The same alert than the previous example will be displayed.

Types of translations

Package's translations are divided in 4 parts standing for a type of the SweetAlert. It's an optional normalization. But if you do, type will be automatically set to SweetAlert.

  Alert.open('info.not-connected');
"info": {
    "not-connected": {
      "title": "Vous n'êtes pas connecté",
      "text": "Identifiez-vous pour plus de possibilités."
    }
  },

SweetAlert example 2

In this case, info has been automatically detected.

No keys, just messages

You can also use this package for display untranslated messages.

  Alert.open('Surprise!');

Options

SweetAlert provide a bunch of options that you can use in the package. See their documentation.

  Alert.open('warning.delete-file', {
      showCancelButton: true,
      confirmButtonColor: "#DD6B55",
      confirmButtonText: "Yes, delete it!",
      closeOnConfirm: false
  });

SweetAlert example 4

Contributing

Contributions are highly encouraged for pushing this package to a next level of translations. Don't hesitate to pull-request your own language file or aditionnal keys for already existing translations.