Meteor Autoform i18n
Internationalization for aldeed:autoform powered by tap:i18n.
This package automatically attaches reactive labels, input placeholders and select options to your forms created through Autoform.
UPDATE: To get reactively translated error messages in Autoform, additionally use gwendall:simple-schema-i18n.
Installation
meteor add gwendall:autoform-i18n
How-to
1. Create an i18n file with your translations
*.i18n.json files contain the values that the package will apply to your schema. For each schema field, you can pass the following values:
label [String]
: Will be set as a label in your autoformplaceholder [String]
: Will be set as a text input / textarea placeholder or select first option, depending on your input typeoptions [Object]
: Will be the options available in your selects, radioboxes or checkboxes for the given field.
If you explicitely define label
, placeholder
or options
for some your schema fields, the package will not overwrite them with translations. Don't declare them for the package to perform the translation.
2. Define a simple-schema for your collection and call Schema.i18n(json_path)
json_path
is the path allowing the package to find your translations for this schema in your i18n files.
NOTE: Call Schema.i18n(json_path) in a Meteor.startup hook to make sure your translation files are available to the package.
Example
/i18n/en.i18n.json
1{ 2 "schemas": { 3 "posts": { 4 "title": { 5 "label": "Title", 6 "placeholder": "Enter a title for your post" 7 }, 8 "category": { 9 "label": "Category", 10 "placeholder": "Select a category", 11 "options": { 12 "announcements": "Announcements", 13 "packages": "Packages", 14 "ama": "AMA", 15 "news": "News" 16 } 17 } 18 } 19 } 20}
/i18n/fr.i18n.json
1{ 2 "schemas": { 3 "posts": { 4 "title": { 5 "label": "Titre", 6 "placeholder": "Veuillez saisir le titre de votre publication" 7 }, 8 "category": { 9 "label": "Categorie", 10 "placeholder": "Choisissez une categorie", 11 "options": { 12 "announcements": "Annonces", 13 "packages": "Paquets", 14 "ama": "AMA", 15 "news": "Nouvelles" 16 } 17 } 18 } 19 } 20} 21
/lib/collections/.js
1Posts = new Mongo.Collection("posts"); 2Schema = new SimpleSchema({ 3 "title": { 4 type: String 5 }, 6 "category": { 7 type: String 8 } 9}); 10Meteor.startup(function() { 11 Schema.i18n("schemas.posts"); 12 Posts.attachSchema(Schema); 13});
/client/tpl.html
1<template name="postForm"> 2 {{> quickForm collection="Posts" id="insertPostForm" type="insert"}} 3</template>