Skip to content

Commit 86a2a64

Browse files
committed
fix(i18nDirective): does not throw error on non-token(s)
Closes doshprompt#4
1 parent 1da60de commit 86a2a64

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-localization",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"homepage": "https://github.com/doshprompt/angular-localization",
55
"description": "angularjs localization done right",
66
"main": "angular-localization.js",

src/localization.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,20 @@ angular.module('ngLocalize', ['ngCookies', 'ngLocalize.Config', 'ngLocalize.Even
270270
function (locale, localeEvents, localeConf) {
271271
'use strict';
272272

273-
function update(elm, string, optArgs) {
274-
var tag = '';
273+
function setText(elm, tag) {
274+
if (tag !== elm.text()) {
275+
elm.text(tag);
276+
}
277+
}
275278

276-
locale.ready(locale.getPath(string)).then(function () {
277-
tag = locale.getString(string, optArgs);
278-
if (tag !== elm.text()) {
279-
elm.text(tag);
280-
}
281-
});
279+
function update(elm, string, optArgs) {
280+
if (locale.isToken(string)) {
281+
locale.ready(locale.getPath(string)).then(function () {
282+
setText(elm, locale.getString(string, optArgs));
283+
});
284+
} else {
285+
setText(elm, string);
286+
}
282287
}
283288

284289
return function (scope, elm, attrs) {

tests/unit/directiveSpec.js

+9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ describe('directives', function () {
4141
$rootScope.$digest();
4242
expect(element.text()).toEqual('My name is Rahul Doshi');
4343
}));
44+
45+
it('should allow non-tokens to passthrough untouched and without errors', inject(function ($compile, $rootScope) {
46+
var element = angular.element(
47+
'<p data-i18n="notAToken"></p>'
48+
);
49+
$compile(element)($rootScope);
50+
$rootScope.$digest();
51+
expect(element.text()).toEqual('notAToken');
52+
}));
4453
});
4554

4655
describe('i18nAttr', function () {

0 commit comments

Comments
 (0)