Skip to content

Commit 3ebea3e

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/feature/language-support'
2 parents 8ccc494 + 8bec896 commit 3ebea3e

16 files changed

+305
-34
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ git clone https://github.com/angular-dashboard-framework/angular-dashboard-frame
3030
cd angular-dashboard-framework
3131
```
3232

33-
Install npm and bower dependencies:
33+
Install dependencies:
3434

3535
```bash
3636
npm install
@@ -59,6 +59,7 @@ gulp all
5959
```
6060
The sample and the final build of angular-dashboard-framework are now in the dist directory.
6161

62+
6263
## Contributing
6364

6465
Please do not commit changes to the dist folder. The dist folder is only generated for releases.

src/scripts/adf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
'use strict';
2626

27-
angular.module('adf', ['adf.provider', 'ui.bootstrap'])
27+
angular.module('adf', ['adf.provider', 'adf.locale', 'ui.bootstrap'])
2828
.value('adfTemplatePath', '../src/templates/')
2929
.value('rowTemplate', '<adf-dashboard-row row="row" adf-model="adfModel" options="options" edit-mode="editMode" ng-repeat="row in column.rows" />')
3030
.value('columnTemplate', '<adf-dashboard-column column="column" adf-model="adfModel" options="options" edit-mode="editMode" ng-repeat="column in row.columns" />')

src/scripts/adf.locale.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2015, Sebastian Sdorra
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
'use strict';
26+
27+
angular.module('adf.locale', [])

src/scripts/dashboard.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,16 @@ angular.module('adf')
330330
$scope.editMode = false;
331331
$scope.editClass = '';
332332

333+
//passs translate function from dashboard so we can translate labels inside html templates
334+
$scope.translate = dashboard.translate;
335+
336+
function getNewModalScope() {
337+
var scope = $scope.$new();
338+
//pass translate function to the new scope so we can translate the labels inside the modal dialog
339+
scope.translate = dashboard.translate;
340+
return scope;
341+
}
342+
333343
$scope.toggleEditMode = function(){
334344
$scope.editMode = ! $scope.editMode;
335345
if ($scope.editMode){
@@ -362,7 +372,7 @@ angular.module('adf')
362372

363373
// edit dashboard settings
364374
$scope.editDashboardDialog = function(){
365-
var editDashboardScope = $scope.$new();
375+
var editDashboardScope = getNewModalScope();
366376
// create a copy of the title, to avoid changing the title to
367377
// "dashboard" if the field is empty
368378
editDashboardScope.copy = {
@@ -403,7 +413,7 @@ angular.module('adf')
403413

404414
// add widget dialog
405415
$scope.addWidgetDialog = function(){
406-
var addScope = $scope.$new();
416+
var addScope = getNewModalScope();
407417
var model = $scope.model;
408418
var widgets;
409419
if (angular.isFunction(widgetFilter)){
@@ -418,6 +428,9 @@ angular.module('adf')
418428
}
419429
addScope.widgets = widgets;
420430

431+
//pass translate function to the new scope so we can translate the labels inside the modal dialog
432+
addScope.translate = $scope.translate;
433+
421434
// pass createCategories function to scope, if categories option is enabled
422435
if ($scope.options.categories){
423436
$scope.createCategories = createCategories;

src/scripts/locale-constant.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2015, Sebastian Sdorra
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
'use strict';
26+
27+
/**
28+
* @ngdoc object
29+
* @name adf.locale#adfLocale
30+
* @description
31+
*
32+
* Holds settings and values for framework supported locales
33+
*/
34+
angular.module('adf.locale')
35+
.constant('adfLocale',
36+
{
37+
defaultLocale: 'en-GB',
38+
frameworkLocales: {
39+
'en-GB': {
40+
ADF_COMMON_CLOSE: 'Close',
41+
ADF_COMMON_DELETE: 'Delete',
42+
ADF_COMMON_TITLE: 'Title',
43+
ADF_COMMON_CANCEL: 'Cancel',
44+
ADF_COMMON_APPLY: 'Apply',
45+
ADF_COMMON_EDIT_DASHBOARD: 'Edit dashboard',
46+
ADF_EDIT_DASHBOARD_STRUCTURE_LABEL: 'Structure',
47+
ADF_DASHBOARD_TITLE_TOOLTIP_ADD: 'Add new widget',
48+
ADF_DASHBOARD_TITLE_TOOLTIP_SAVE: 'Save changes',
49+
ADF_DASHBOARD_TITLE_TOOLTIP_EDIT_MODE: 'Enable edit mode',
50+
ADF_DASHBOARD_TITLE_TOOLTIP_UNDO: 'Undo changes',
51+
ADF_WIDGET_ADD_HEADER: 'Add new widget',
52+
ADF_WIDGET_DELETE_CONFIRM_MESSAGE: 'Are you sure you want to delete this widget ?',
53+
ADF_WIDGET_TOOLTIP_REFRESH: 'Reload widget Content',
54+
ADF_WIDGET_TOOLTIP_MOVE: 'Change widget location',
55+
ADF_WIDGET_TOOLTIP_COLLAPSE: 'Collapse widget',
56+
ADF_WIDGET_TOOLTIP_EXPAND: 'Expand widget',
57+
ADF_WIDGET_TOOLTIP_EDIT: 'Edit widget configuration',
58+
ADF_WIDGET_TOOLTIP_FULLSCREEN: 'Fullscreen widget',
59+
ADF_WIDGET_TOOLTIP_REMOVE: 'Remove widget'
60+
},
61+
'sv-SE': {
62+
ADF_COMMON_CLOSE: 'Stäng',
63+
ADF_COMMON_DELETE: 'Ta bort',
64+
ADF_COMMON_TITLE: 'Titel',
65+
ADF_COMMON_CANCEL: 'Avbryt',
66+
ADF_COMMON_APPLY: 'Använd',
67+
ADF_COMMON_EDIT_DASHBOARD: 'Redigera dashboard',
68+
ADF_EDIT_DASHBOARD_STRUCTURE_LABEL: 'Struktur',
69+
ADF_DASHBOARD_TITLE_TOOLTIP_ADD: 'Lägg till ny widget',
70+
ADF_DASHBOARD_TITLE_TOOLTIP_SAVE: 'Spara förändringar',
71+
ADF_DASHBOARD_TITLE_TOOLTIP_EDIT_MODE: 'Slå på redigeringsläge',
72+
ADF_DASHBOARD_TITLE_TOOLTIP_UNDO: 'Ångra förändringar',
73+
ADF_WIDGET_ADD_HEADER: 'Lägg till ny widget',
74+
ADF_WIDGET_DELETE_CONFIRM_MESSAGE: 'Är du säker på att du vill ta bort denna widget ?',
75+
ADF_WIDGET_TOOLTIP_REFRESH: 'Ladda om widget',
76+
ADF_WIDGET_TOOLTIP_MOVE: 'Ändra widgets position',
77+
ADF_WIDGET_TOOLTIP_COLLAPSE: 'Stäng widget',
78+
ADF_WIDGET_TOOLTIP_EXPAND: 'Öppna widget',
79+
ADF_WIDGET_TOOLTIP_EDIT: 'Ändra widget konfigurering',
80+
ADF_WIDGET_TOOLTIP_FULLSCREEN: 'Visa widget i fullskärm',
81+
ADF_WIDGET_TOOLTIP_REMOVE: 'Ta bort widget'
82+
}
83+
}
84+
}
85+
);

src/scripts/provider.js

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The MIT License
33
*
44
* Copyright (c) 2015, Sebastian Sdorra
@@ -31,8 +31,8 @@
3131
*
3232
* The dashboardProvider can be used to register structures and widgets.
3333
*/
34-
angular.module('adf.provider', [])
35-
.provider('dashboard', function(){
34+
angular.module('adf.provider', ['adf.locale'])
35+
.provider('dashboard', function(adfLocale){
3636

3737
var widgets = {};
3838
var widgetsPath = '';
@@ -51,6 +51,22 @@ angular.module('adf.provider', [])
5151
return true;
5252
};
5353

54+
var activeLocale = adfLocale.defaultLocale;
55+
var locales = adfLocale.frameworkLocales;
56+
57+
function getLocales() {
58+
return locales;
59+
}
60+
61+
function getActiveLocale() {
62+
return activeLocale;
63+
}
64+
65+
function translate(label) {
66+
var translation = locales[activeLocale][label];
67+
return translation ? translation : label;
68+
}
69+
5470
/**
5571
* @ngdoc method
5672
* @name adf.dashboardProvider#widget
@@ -227,6 +243,53 @@ angular.module('adf.provider', [])
227243
return this;
228244
};
229245

246+
/**
247+
* @ngdoc method
248+
* @name adf.dashboardProvider#setLocale
249+
* @methodOf adf.dashboardProvider
250+
* @description
251+
*
252+
* Changes the locale setting of adf
253+
*
254+
* @param {string} ISO Language Code
255+
*
256+
* @returns {Object} self
257+
*/
258+
this.setLocale = function(locale){
259+
if(locales[locale]) {
260+
activeLocale = locale;
261+
} else {
262+
throw new Error('Cannot set locale: ' + locale + '. Locale is not defined.');
263+
}
264+
return this;
265+
};
266+
267+
/**
268+
* @ngdoc method
269+
* @name adf.dashboardProvider#addLocale
270+
* @methodOf adf.dashboardProvider
271+
* @description
272+
*
273+
* Adds a new locale to adf
274+
*
275+
* @param {string} ISO Language Code for the new locale
276+
* @param {object} translations for the locale.
277+
*
278+
* @returns {Object} self
279+
*/
280+
this.addLocale = function(locale, translations){
281+
if(!angular.isString(locale)) {
282+
throw new Error('locale must be an string');
283+
}
284+
285+
if(!angular.isObject(translations)) {
286+
throw new Error('translations must be an object');
287+
}
288+
289+
locales[locale] = translations;
290+
return this;
291+
};
292+
230293
/**
231294
* @ngdoc service
232295
* @name adf.dashboard
@@ -239,6 +302,10 @@ angular.module('adf.provider', [])
239302
* @property {Array.<Object>} structures Array of registered structures.
240303
* @property {string} messageTemplate Template for messages.
241304
* @property {string} loadingTemplate Template for widget loading.
305+
* @property {method} sets locale of adf.
306+
* @property {Array.<Object>} hold all of the locale translations.
307+
* @property {string} the active locale setting.
308+
* @property {method} translation function passed to templates.
242309
*
243310
* @returns {Object} self
244311
*/
@@ -252,6 +319,10 @@ angular.module('adf.provider', [])
252319
messageTemplate: messageTemplate,
253320
loadingTemplate: loadingTemplate,
254321
customWidgetTemplatePath: customWidgetTemplatePath,
322+
setLocale: this.setLocale,
323+
locales: getLocales,
324+
activeLocale: getActiveLocale,
325+
translate: translate,
255326

256327
/**
257328
* @ngdoc method

src/scripts/widget.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ angular.module('adf')
2929

3030
function preLink($scope) {
3131
var definition = $scope.definition;
32+
33+
//passs translate function from dashboard so we can translate labels inside html templates
34+
$scope.translate = dashboard.translate;
35+
3236
if (definition) {
3337
var w = dashboard.widgets[definition.type];
3438
if (w) {
@@ -114,6 +118,8 @@ angular.module('adf')
114118
$scope.remove = function() {
115119
if ($scope.options.enableConfirmDelete) {
116120
var deleteScope = $scope.$new();
121+
deleteScope.translate = dashboard.translate;
122+
117123
var deleteTemplateUrl = adfTemplatePath + 'widget-delete.html';
118124
if (definition.deleteTemplateUrl) {
119125
deleteTemplateUrl = definition.deleteTemplateUrl;
@@ -146,6 +152,7 @@ angular.module('adf')
146152
// bind edit function
147153
$scope.edit = function() {
148154
var editScope = $scope.$new();
155+
editScope.translate = dashboard.translate;
149156
editScope.definition = angular.copy(definition);
150157

151158
var adfEditTemplatePath = adfTemplatePath + 'widget-edit.html';

src/templates/dashboard-edit.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<div class="modal-header">
22
<button type="button" class="close" ng-click="closeDialog()" aria-hidden="true">&times;</button>
3-
<h4 class="modal-title">Edit Dashboard</h4>
3+
<h4 class="modal-title" ng-bind="translate('ADF_COMMON_EDIT_DASHBOARD')">Edit Dashboard</h4>
44
</div>
55
<div class="modal-body">
66
<form role="form">
77
<div class="form-group">
8-
<label for="dashboardTitle">Title</label>
8+
<label for="dashboardTitle" ng-bind="translate('ADF_COMMON_TITLE')">Title</label>
99
<input type="text" class="form-control" id="dashboardTitle" ng-model="copy.title" required="">
1010
</div>
1111
<div class="form-group">
12-
<label>Structure</label>
12+
<label ng-bind="translate('ADF_EDIT_DASHBOARD_STRUCTURE_LABEL')">Structure</label>
1313
<div class="row" ng-init="splitted = split(structures, 3)">
1414
<div class="col-lg-4" ng-repeat="structureColumn in splitted">
1515
<div class="radio" ng-repeat="(key, structure) in structureColumn">
@@ -34,5 +34,5 @@ <h4 class="modal-title">Edit Dashboard</h4>
3434
</form>
3535
</div>
3636
<div class="modal-footer">
37-
<button type="button" class="btn btn-primary" ng-click="closeDialog()">Close</button>
37+
<button type="button" class="btn btn-primary" ng-click="closeDialog()" ng-bind="translate('ADF_COMMON_CLOSE')">Close</button>
3838
</div>

src/templates/dashboard-title.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<h1>
22
{{model.title}}
33
<span style="font-size: 16px" class="pull-right">
4-
<a href="" ng-if="editMode" title="add new widget" ng-click="addWidgetDialog()">
4+
<a href="" ng-if="editMode" title="{{ translate('ADF_DASHBOARD_TITLE_TOOLTIP_ADD') }}" ng-click="addWidgetDialog()">
55
<i class="glyphicon glyphicon-plus-sign"></i>
66
</a>
7-
<a href="" ng-if="editMode" title="edit dashboard" ng-click="editDashboardDialog()">
7+
<a href="" ng-if="editMode" title="{{ translate('ADF_COMMON_EDIT_DASHBOARD') }}" ng-click="editDashboardDialog()">
88
<i class="glyphicon glyphicon-cog"></i>
99
</a>
10-
<a href="" ng-if="options.editable" title="{{editMode ? 'save changes' : 'enable edit mode'}}" ng-click="toggleEditMode()">
10+
<a href="" ng-if="options.editable" title="{{editMode ? translate('ADF_DASHBOARD_TITLE_TOOLTIP_SAVE') : translate('ADF_DASHBOARD_TITLE_TOOLTIP_EDIT_MODE') }}" ng-click="toggleEditMode()">
1111
<i class="glyphicon" x-ng-class="{'glyphicon-edit' : !editMode, 'glyphicon-save' : editMode}"></i>
1212
</a>
13-
<a href="" ng-if="editMode" title="undo changes" ng-click="cancelEditMode()">
13+
<a href="" ng-if="editMode" title="{{ translate('ADF_DASHBOARD_TITLE_TOOLTIP_UNDO') }}" ng-click="cancelEditMode()">
1414
<i class="glyphicon glyphicon-repeat adf-flip"></i>
1515
</a>
1616
</span>

src/templates/widget-add.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="modal-header">
22
<button type="button" class="close" ng-click="closeDialog()" aria-hidden="true">&times;</button>
3-
<h4 class="modal-title">Add new widget</h4>
3+
<h4 class="modal-title" ng-bind="translate('ADF_WIDGET_ADD_HEADER')">Add new widget</h4>
44
</div>
55
<div class="modal-body">
66
<!-- dashboard categories enabled -->
@@ -35,5 +35,5 @@ <h4 class="modal-title">Add new widget</h4>
3535
</div>
3636
</div>
3737
<div class="modal-footer">
38-
<button type="button" class="btn btn-primary" ng-click="closeDialog()">Close</button>
38+
<button type="button" class="btn btn-primary" ng-click="closeDialog()" ng-bind="translate('ADF_COMMON_CLOSE')">Close</button>
3939
</div>

0 commit comments

Comments
 (0)