Skip to content

Commit

Permalink
Merge pull request #29 from dhoko/ag_#28_babelfish_solo
Browse files Browse the repository at this point in the history
Ag #28 babelfish solo
  • Loading branch information
dhoko committed Jul 29, 2014
2 parents fd2f66f + a2ceb05 commit 9b36dea
Show file tree
Hide file tree
Showing 51 changed files with 1,676 additions and 26,952 deletions.
62 changes: 57 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ So when the file is created, it binds the data from the default state (*home*) t
### Configuration

```JavaScript
angular.module('myApp')
angular.module('myApp',['ui.router','ngBabelfish'])
.config(function(babelfishProvider) {

// Configure the i18n for this app
babelfishProvider.languages({
babelfishProvider.init({
state: "home", // Default state to load
lang: "en-EN", // Default language
url: "/i18n/languages.json", // Default url
Expand Down Expand Up @@ -219,11 +219,11 @@ You can build a file per lang, so you can load only the current lang, and load a
Configure the service from `babelfishProvider` in your app module

```JavaScript
angular.module('myApp')
angular.module('myApp',['ui.router','ngBabelfish'])
.config(function(babelfishProvider) {

// Configure the i18n for this app
babelfishProvider.languages({
babelfishProvider.init({
namespace: "", // Namespace to store your translations in the $scope
state: "home", // Default state of your app
lang: "fr-FR", // Default lang for the app
Expand All @@ -239,7 +239,33 @@ angular.module('myApp')
]
});

})
});

// Other way to do it

angular.module('myApp',['ui.router','ngBabelfish'])
.config(function(babelfishProvider) {

// Configure the i18n for this app
babelfishProvider.init({
namespace: "", // Namespace to store your translations in the $scope
state: "home", // Default state of your app
lang: "fr-FR" // Default lang for the app
});

// no need to activate lazy mode, it's already activated throw lang()
babelfishProvider
.lang({
lang: "fr-FR", // Name of your translation
url: "/i18n/fr-FR.json" // Path to the translation
})
.lang({
lang: "en-EN",
url: "/i18n/en-EN.json"
});


});
```

It's ready.
Expand Down Expand Up @@ -272,6 +298,28 @@ It's ready.
}
```

## Solo Mode (translate only a small portion of an application, such as a directive)

You can update a small portion of an application, without using ngBabelfish for the whole application. So it can be used with another translate service if you want.

```JavaScript
angular.module('myApp',['ui.router','ngBabelfish.solo'])
.controller('testController', function(translator) {
translator.initSolo({
namespace: 'i18n'
});
translator.load();
});
```

> To use the solo mode you must inject `ngBabelfish.solo` module (ngBabelfish already inject ngBabelfish.solo). You need to load the service `translator`.
Then it's ready, your translations are available in `$scope.i18n`;

*You cannot load the service babelfish with the solo mode cf [changelog Solo Mode](https://github.com/dhoko/ngBabelfish/pull/29)*



## API

### In a template
Expand All @@ -295,6 +343,10 @@ API:
- `babelfish.updateLang(lang)` : Load new translation for a lang in your app
- `babelfish.updateState(state)` : Bind current translation for a state
- `babelfish.isLoaded()` : Detect if your i18n is loaded
- `babelfish.loadTranslation(lang,url)` : Load a new translation at runtime
- `babelfish.isLangLoaded(lang)` : Check if a language is loaded
- `babelfish.getNamespace()`: Get the namespace
- `babelfish.translations()`: Get all the transltions for the application

### Filter translate

Expand Down
5 changes: 3 additions & 2 deletions demo/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ angular.module('ngBabelfishDemo', ['ui.router','ngBabelfish'])
$stateProvider
.state('home', {
url: '/',
templateUrl: 'partials/home.html'
templateUrl: 'partials/home.html',
controller: function() {}
})

.state('config', {
Expand All @@ -22,7 +23,7 @@ angular.module('ngBabelfishDemo', ['ui.router','ngBabelfish'])

$urlRouterProvider.otherwise('/');

babelfishProvider.languages({
babelfishProvider.init({
namespace: 'i18n',
url: 'i18n/i18n.json'
})
Expand Down
2 changes: 1 addition & 1 deletion demo/appLazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ angular.module('ngBabelfishDemoLazy', ['ui.router','ngBabelfish'])

$urlRouterProvider.otherwise('/');

babelfishProvider.languages({
babelfishProvider.init({
namespace: 'i18n',
lazy: true,
urls: [
Expand Down
35 changes: 35 additions & 0 deletions demo/appSolo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* ngBabelfishDemo Module
*
* Description
*/
angular.module('ngBabelfishDemoSolo', ['ui.router','ngBabelfish.solo'])
.config(function ($stateProvider, $urlRouterProvider){

$stateProvider
.state('home', {
url: '/',
templateUrl: 'partials/home.html',
controller: function(translator) {
console.log(translator.get())
}
})

.state('config', {
url: '/config',
templateUrl: 'partials/config.html',
controller: function() {}
// controller: 'configCtrl'

})

$urlRouterProvider.otherwise('/');
})
.run(function (translator) {
translator.initSolo({
lang: 'en-EN',
url: 'i18n/translations.json',
namespace: 'i18n'
});
translator.load();
});
12 changes: 0 additions & 12 deletions demo/bower_components/angular-ui-router/.npmignore

This file was deleted.

13 changes: 0 additions & 13 deletions demo/bower_components/angular-ui-router/.travis.yml

This file was deleted.

23 changes: 0 additions & 23 deletions demo/bower_components/angular-ui-router/CHANGELOG.md

This file was deleted.

Loading

0 comments on commit 9b36dea

Please sign in to comment.