A simple library that adds translation support for Astronomy powered Meteor models
meteor add katrotz:astronomy-babelfish
Babelfish, called after the little fish from The Hitchhiker's Guide to the Galaxy, is a library that adds a translation behaviour to the models powered by the Astronomy library.
Astro.setLocales(['ro', 'ru', 'en', 'de']);
Astro.useLocale('de');
Features = new Meteor.Collection('features');
Feature = Astro.Class({
name: 'Feature',
collection: Features,
fields: {
//Note that the fields that should be multilingual, must not be defined explicitly
},
behaviors: {
babelfish: {
//List of model fields with multilingual support. Supports dot notation for nested fields.
fields: ['title', 'types.title']
}
}
});
##Methods
Set the list of locales valid values to be used (ISO 639-1 language names)
Get the list of locales valid values
Set the current locale
Get the current locale
Shorthand for Astro.getLocales
Shorthand for Astro.currentLocale
Get the list of fields registered as babel fields
Set the translation of a field for a locale
Set the translations of a field. The fieldTranslations should be an object with locales as keys, and translations as values
{
ru: "Babilon",
en: "Babel",
de: "Babylon"
}
- Babelfish will consder the default locale the first locale in the list of locales defined using
Astro.setLocales
- Babelfish will create the
translations
field on the document that will hold the translations for all multilingual fields for each locale. This field can not be directly manipulated. The translations can be set using themodel.translate
method. - Babelfish will create a field on the document for each multilingual field, holding the translation for the default locale. This will allow using the field in other behaviours (eg. A multilingual field can be used to generate a slug using the astronomy slug behaviour)