-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy path104_i18n.ngdoc
104 lines (84 loc) · 3.35 KB
/
104_i18n.ngdoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
@ngdoc overview
@name Tutorial: 104 i18n
@description
UI-Grid provides an i18nService that you can use to change the default language, add translations,
or change existing translations.
The easiest way to set language is to use the ui-i18n directive in a div that contains the grid.
<pre>
<div ui-i18n="{{lang}}">
</pre>
Only one ui-i18n directive is allowed. The current language setting is stored in the i18n service (singleton)
so there is currently no way to have more than one language per app.
Another option is to use the i18nService and use the setCurrentLang method
<pre>
i18nService.setCurrentLang('fr');
</pre>
For an example using angular-translate to translate your headers, refer to http://plnkr.co/edit/KnrKTst5dWXvlZNeIy9c?p=preview
If you would like to get better performance out of your application, it is recommended that you take advantage of UI-Grid's multi-file
support. By default ui-grid.core.js will contain just the english language, in order to load the other language follow the example bellow:
<pre>
<script src="/release/ui-grid.core.js"></script>
<script src="/release/i18n/ui-grid.language.[YOUR_LANGUAGE_HERE].js"></script>
<!-- Alternatively you can load all languages provided with you grid by loading the following -->
<script src="/release/i18n/ui-grid.language.all.js"></script>
</pre>
@example
<example module="app">
<file name="app.js">
angular.module('app', ['ngTouch', 'ui.grid'])
.controller('MainCtrl', MainCtrl);
MainCtrl.$inject = ['i18nService', '$http'];
function MainCtrl(i18nService, $http) {
var vm = this;
vm.langs = i18nService.getAllLangs();
vm.lang = 'nl';
vm.gridOptions = {
columnDefs: [
{ field: 'name' },
{ field: 'gender' },
{ field: 'company', enableFiltering: false }
]
};
$http.get('/data/100.json')
.then(function(response) {
vm.gridOptions.data = response.data;
});
}
</file>
<file name="index.html">
<div ng-controller="MainCtrl as $ctrl">
<select id="langDropdown" ng-model="$ctrl.lang" ng-options="l for l in $ctrl.langs"></select>
<br />
<div ui-i18n="{{$ctrl.lang}}">
<h2>Using attribute:</h2>
<p ui-t="groupPanel.description"></p>
<h2>Using attribute 2:</h2>
<p ui-translate>groupPanel.description</p>
<h2>Using Filter that updates with language:</h2>
<p>{{"groupPanel.description" | t:$ctrl.lang}}</p>
<h2>Using Filter that does not update after load:</h2>
<p>{{"groupPanel.description" | t}}</p>
<p>Click the header menu to see language.</p>
<div id="i18nGrid" ui-grid="$ctrl.gridOptions" class="grid"></div>
</div>
</div>
</file>
<file name="main.css">
.grid {
width: 500px;
height: 250px;
}
</file>
<file name="scenario.js">
var gridTestUtils = require('../../test/e2e/gridTestUtils.spec.js');
describe('104 i18n', function() {
gridTestUtils.firefoxReload();
it('should default to nl for the language', function() {
expect(element(by.id('langDropdown')).element(by.css('option:checked')).getText()).toEqual('nl');
});
it('should have three visible columns', function() {
gridTestUtils.expectHeaderColumnCount( 'i18nGrid', 3 );
});
});
</file>
</example>