angular.module('gettext').directive('translate', function (gettextCatalog, $interpolate, $parse, $compile) {
    /**
     * Trim fallback for old browsers(instead of jQuery)
     * Based on AngularJS-v1.2.2 (angular.js#620)
     */
    var trim = (function () {
        if (!String.prototype.trim) {
            return function (value) {
                return (typeof value === 'string') ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value;
            };
        }
        return function (value) {
            return (typeof value === 'string') ? value.trim() : value;
        };
    })();

    return {
        transclude: 'element',
        priority: 499,
        compile: function (element, attrs, transclude) {
            return function ($scope, $element) {
                // Validate attributes
                var assert = function (condition, missing, found) {
                    if (!condition) {
                        throw new Error("You should add a " + missing + " attribute whenever you add a " + found + " attribute.");
                    }
                };

                assert(!attrs.translatePlural || attrs.translateN, 'translate-n', 'translate-plural');
                assert(!attrs.translateN || attrs.translatePlural, 'translate-plural', 'translate-n');
                assert(!attrs.ngIf, 'ng-if', 'translate');
                assert(!attrs.ngSwitchWhen, 'ng-switch-when', 'translate');

                var countFn = $parse(attrs.translateN);

                transclude($scope, function (clone) {
                    var input = trim(clone.html());
                    clone.removeAttr('translate');
                    $element.replaceWith(clone);

                    return $scope.$watch(function () {
                        var prev = clone.html();

                        // Fetch correct translated string.
                        var translated;
                        if (attrs.translatePlural) {
                            translated = gettextCatalog.getPlural(countFn($scope), input, attrs.translatePlural);
                        } else {
                            translated = gettextCatalog.getString(input);
                        }

                        // Interpolate with scope.
                        var interpolated = $interpolate(translated)($scope);
                        if (prev === interpolated) {
                            return; // Skip DOM change.
                        }
                        clone.html(interpolated);
                        if (attrs.translateCompile !== undefined) {
                            $compile(clone.contents())($scope);
                        }
                        return clone;

                    });
                });
            };
        }
    };
});

@@ -1284,24 +1284,25 @@
 nslate-n');%0A
+%0A
             
@@ -1301,32 +1301,28 @@
             
-assert(!
+if (
 attrs.ngIf, 
@@ -1323,78 +1323,260 @@
 ngIf
-, '
+) %7B%0A                    throw new Error(%22You should not combine translate with 
 ng-if
-'
 , 
-'translate');%0A                assert(!attrs.ngSwitchWhen, '
+this will lead to problems.%22);%0A                %7D%0A                if (attrs.ngSwitchWhen) %7B%0A                    throw new Error(%22You should not combine translate with 
 ng-s
@@ -1589,24 +1589,58 @@
 when
-'
 , 
-'translate');
+this will lead to problems.%22);%0A                %7D
 %0A%0A  

Clarify error messages.