Skip to content

Commit

Permalink
Merge pull request willdurand#173 from Karify/feature/npm
Browse files Browse the repository at this point in the history
Add npm configuration for publishing
  • Loading branch information
monteiro authored Jul 25, 2016
2 parents 1c9bc14 + 8850b5d commit 577484e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
31 changes: 29 additions & 2 deletions Resources/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ guide](https://github.com/willdurand/BazingaJsTranslationBundle/blob/master/UPGR
Installation
------------

### Require via Composer

Install the bundle:

composer require "willdurand/js-translation-bundle"
Expand Down Expand Up @@ -44,16 +46,41 @@ Publish assets:
php app/console assets:install --symlink web
### Require via NPM (optional)
Install the package:
npm install bazinga-translator --save
This step is optional because the files exposed by the npm package are also part of the composer bundle.
Normally you would do this if you prefer to keep all your front-end dependencies in one place, or if you wish to include the `Translator` object as a module dependency in your JS files.

**Important**: it is strongly recommended that you use the same version of the composer bundle and the npm package.


Usage
-----

First, add the following line to your template. It will load the JS `Translator`:
To use the `Translator` object in your JS files you can either load it globally or `require` / `import` it as a module.

* To load it globally add the following line to your template:

``` html
<script src="{{ asset('bundles/bazingajstranslation/js/translator.min.js') }}"></script>
```

* To load it as a module you must be using a module bundler, like `webpack` and it is recommended that you install the translator via `npm`. Then in your JS files you can do:

``` js
// ES2015
import Translator from 'bazinga-translator';
```

``` js
// ES5
var Translator = require('bazinga-translator');
```

Then add the current application's locale into your layout, by adding a `lang`
attribute to the `html` tag:

Expand Down Expand Up @@ -110,7 +137,7 @@ file of your project.
#### Loading via JSON

Alternatively, you can load your translated messages via JSON (e.g. using
jQuery's `ajax()` or RequireJS's text plugin). Just amend the above mentioned
the `fetch` API, jQuery's `ajax()` or RequireJS's text plugin). Just amend the above mentioned
URLs to also contain the `'_format': 'json'` parameter like so:
``` html
Expand Down
22 changes: 22 additions & 0 deletions Resources/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "bazinga-translator",
"version": "2.5.0",
"description": "A pretty nice way to use your translation messages generated by the BazingaJsTranslationBundle in your JavaScript.",
"keywords": [ "translation", "symfony" ],
"license": "MIT",
"author": {
"name": "William Durand",
"email": "[email protected]"
},
"contributors": [
{
"name": "Bruno Sampaio",
"email": "[email protected]"
}
],
"files": [
"js/translator.js",
"public/js/translator.min.js"
],
"main": "js/translator.js"
}

0 comments on commit 577484e

Please sign in to comment.