Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/boxuk/angular-symfony-translation
Integrates BazingaJS Translation bundle with AngularJS.
https://github.com/boxuk/angular-symfony-translation
Last synced: about 1 month ago
JSON representation
Integrates BazingaJS Translation bundle with AngularJS.
- Host: GitHub
- URL: https://github.com/boxuk/angular-symfony-translation
- Owner: boxuk
- License: mit
- Created: 2014-09-24T12:27:43.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-06-15T12:15:13.000Z (over 8 years ago)
- Last Synced: 2024-04-15T07:38:58.283Z (7 months ago)
- Language: JavaScript
- Size: 85.9 KB
- Stars: 13
- Watchers: 45
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
AngularJS Translations, powered by Symfony2
===========================================
[![NPM version](https://badge.fury.io/js/angular-symfony-translation.png)](https://www.npmjs.org/package/angular-symfony-translation) [![Build Status](https://travis-ci.org/boxuk/angular-symfony-translation.svg)](https://travis-ci.org/boxuk/angular-symfony-translation) [![Code Climate](https://codeclimate.com/github/boxuk/angular-symfony-translation/badges/gpa.svg)](https://codeclimate.com/github/boxuk/angular-symfony-translation) [![Coverage Status](https://img.shields.io/coveralls/boxuk/angular-symfony-translation.svg)](https://coveralls.io/r/boxuk/angular-symfony-translation)> Integrates BazingaJS Translation bundle with AngularJS.
When integrating an Angular application with Symfony2, you can quickly find
yourself in an awkward situation when it comes to dealing with translations.You have all of your translations server-side and exposed to your JS using
the excellent [Bazinga JS Translations Bundle](https://github.com/willdurand/BazingaJsTranslationBundle),
but how do you access those translations from your Angular app (including your view
partials)?This Angular module provides functionality to access translations exposed
by the above mentioned Symfony2 bundle from within your Angular app.## Key points:
* Works with both `1.x` and `2.x` versions of the Bazinga JS Translation bundle.
* Provides `trans` and `transChoice` filters with the same method signatures as
the methods provided by the BazingaJS bundle.
* Uses an adapter so you can use `2.x` syntax regardless of whether you're using
`1.x` or `2.x`.## Installation
* `bower install --save angular-symfony-translation`
or
* `npm install --save angular-symfony-translation`Include `dist/angular-symfony-translation.js` before your Angular app
(either as a `` tag or as part of your build script).List the module as a dependency of your app:
```javascript
angular.module('myApplication', ['boxuk.translation']);
```## Usage
The following assumes you already have [Bazinga JS Translations Bundle](https://github.com/willdurand/BazingaJsTranslationBundle)
setup and working.This module exposes an API that matches what is provided by version
**2.x** of the BazingaJS bundle. If you're using a **1.x** release, you can
still use this module with no further modifications as the module will handle
transforming method calls for the older API.### General documentation:
The filters provided by this module match the BazingaJS bundle as closely as
possible. As such, the documentation provided by that bundle should be consulted
for more detail on usage, e.g. parameters, pluralization, etc.This documentation will cover the **differences in usage** and nothing else.
### In a view partial:
#### `trans` filter:
```html
<!-- Basic usage -->
<p>{{ 'key' | trans }}</p><!-- With custom params and domain -->
<p>{{ 'key' | trans: { 'foo': 'bar' }: 'my_domain' }}</p>
```#### `transChoice` filter:
```yaml
# app/Resources/messages.en.yml
salmon: "{0} No salmon today, sorry.|{1} We have a single salmon!|[1,Inf] Woah, there's %count% salmon. That's a lot of salmon."
``````html
<!-- Basic usage -->
<p>{{ 'salmon' | transChoice: 5: {'count': 5} }}</p><!-- With custom domain -->
<p>{{ 'salmon' | transChoice: 5: {'count': 5}: 'my_domain' }}</p>
```#### `TranslationService`:
Both of the above filters make use of the translation service, which either directly exposes the `Translator`
object from the *BazingaJS Translation bundle* (for version 2.x of the bundle) or exposes a 2.x to 1.x adapter.Exposes the same interface as the 2.x version of the bundle: [see the bundle documentation for more details](https://github.com/willdurand/BazingaJsTranslationBundle/blob/v2.2.0/Resources/doc/index.md#the-js-translator).
##### `trans`
###### Parameters
| Name | Type | Description |
|--------|---------|-----------------------------------------|
| key | String | The translation key to lookup |
| params | Object= | Translation parameters |
| domain | String= | The domain to use (default: `messages`) |##### `transChoice`
###### Parameters
| Name | Type | Description |
|--------|---------|-----------------------------------------|
| key | String | The translation key to lookup |
| count | Number | The number to use for pluralization |
| params | Object= | Translation parameters |
| domain | String= | The domain to use (default: `messages`) |##### Service usage
```javascript
function DogsController(TranslationService, DogsService) {
/**
* @type {Array.<Dog>}
*/
var dogs = DogsService.getDogs();
/**
* Getting a simple translation
*
* @type {String}
*/
var title = TranslationService.trans('some_title');
/**
* Using pluralization
*
* @type {String}
*/
var message = TranslationService.transChoice('number_of_dogs', dogs.length);
}
```## System overview
Probably only relevant if you're planning on developing this further:
![System diagram](/docs/system-overview.png)