Display an adapted SweetAlert for i18n translations.
meteor add smaltcreation:alert-i18n
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."
}
}
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.
try {
throw Meteor.Error('bad-request')
} catch (e) {
Alert.open(e);
}
The same alert than the previous example will be displayed.
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."
}
},
In this case, info
has been automatically detected.
You can also use this package for display untranslated messages.
Alert.open('Surprise!');
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
});
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.