Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/katrotz/meteor-astronomy-babelfish
Translation module for meteor astronomy
https://github.com/katrotz/meteor-astronomy-babelfish
astronomy meteor model translation
Last synced: 10 days ago
JSON representation
Translation module for meteor astronomy
- Host: GitHub
- URL: https://github.com/katrotz/meteor-astronomy-babelfish
- Owner: katrotz
- License: mit
- Created: 2016-01-02T12:18:12.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-17T14:09:08.000Z (about 9 years ago)
- Last Synced: 2024-11-14T08:08:14.384Z (2 months ago)
- Topics: astronomy, meteor, model, translation
- Language: JavaScript
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Meteor Astronomy Babelfish
> A simple library that adds translation support for [Astronomy](https://github.com/jagi/meteor-astronomy) powered Meteor models
## Installation
```meteor add katrotz:astronomy-babelfish```
## Introduction
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.
###### Configure the locales
```
Astro.setLocales(['ro', 'ru', 'en', 'de']);```
###### Set the current locale
```
Astro.useLocale('de');```
###### Define the model
```
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
### Global methods##### Astro.setLocales(localesList)
Set the list of locales valid values to be used (ISO 639-1 language names)##### Astro.getLocales()
Get the list of locales valid values##### Astro.useLocale(locale)
Set the current locale##### Astro.currentLocale()
Get the current locale### Model methods
##### model.babelLocales()
Shorthand for Astro.getLocales##### model.currentLocale()
Shorthand for Astro.currentLocale##### model.babelFields()
Get the list of fields registered as babel fields##### model.translate(fieldName, fieldTranslation, locale)
Set the translation of a field for a locale##### model.translate(fieldName, fieldTranslations)
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"
}
```## Notes
1. Babelfish will consder the default locale the first locale in the list of locales defined using `Astro.setLocales`
2. 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 the `model.translate` method.
3. 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)## Licence
[MIT Licence](http://opensource.org/licenses/MIT)