Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
feat(service): introduce getter returning available languages
Browse files Browse the repository at this point in the history
The getter returns the registered available languages.

Closes #1304
  • Loading branch information
tspaeth authored and knalli committed Mar 5, 2016
1 parent a7029f5 commit 3988af0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/service/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2115,6 +2115,25 @@ function $translate($STORAGE_KEY, $windowProvider, $translateSanitizationProvide
return deferred.promise;
};

/**
* @ngdoc function
* @name pascalprecht.translate.$translate#getAvailableLanguageKeys
* @methodOf pascalprecht.translate.$translate
*
* @description
* This function simply returns the registered language keys being defined before in the config phase
* With this, an application can use the array to provide a language selection dropdown or similar
* without any additional effort
*
* @returns {object} returns the list of possibly registered language keys and mapping or null if not defined
*/
$translate.getAvailableLanguageKeys = function () {
if ($availableLanguageKeys.length > 0) {
return $availableLanguageKeys;
}
return null;
};

// Whenever $translateReady is being fired, this will ensure the state of $isReady
var globalOnReadyListener = $rootScope.$on('$translateReady', function () {
$onReadyDeferred.resolve();
Expand Down
24 changes: 24 additions & 0 deletions test/unit/service/translate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2644,4 +2644,28 @@ describe('pascalprecht.translate', function () {
}));
});

describe('$translate#getAvailableLanguageKeys()', function () {

var availKeys = [
{'de-de': 'DE'},
{'en-gb': 'EN'},
{'*': 'EN'}
];

beforeEach(module('pascalprecht.translate', function ($translateProvider) {
$translateProvider.registerAvailableLanguageKeys(availKeys);
}));

var $translate;

beforeEach(inject(function (_$translate_) {
$translate = _$translate_;
}));

it('should have the configured array as a return value', function () {
expect($translate.getAvailableLanguageKeys()).toEqual(availKeys);
});

});

});

3 comments on commit 3988af0

@julkue
Copy link

@julkue julkue commented on 3988af0 Apr 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@joni2back
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@joaocmfcm
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D

Please sign in to comment.