<commit_before>(function () {
    'use strict';

    const directive = function (Base, i18n, decorators) {
        return {
            scope: true,
            restrict: 'AE',
            link($scope, $element, $attrs) {

                class I18n extends Base {

                    constructor() {
                        super($scope);

                        this.watchers = Object.create(null);
                        this.forStop = [];
                        const handler = this._getHandler();
                        this.forStop.push(() => i18next.off('languageChanged', handler));

                        i18next.on('languageChanged', handler);
                        if ($attrs.params) {
                            const stop = $scope.$watch($attrs.params, handler);
                            this.forStop.push(stop);
                        }

                        handler();
                    }

                    $onDestroy() {
                        super.$onDestroy();
                        this.forStop.forEach((cb) => cb());
                    }

                    /**
                     * @return {Function}
                     * @private
                     */
                    _getHandler() {
                        const literal = this._compile(I18n._getLiteral());
                        const ns = i18n.getNs($element);
                        return function () {
                            const skipErros = 'skipErrors' in $attrs;
                            const params = $attrs.params && $scope.$eval($attrs.params) || undefined;
                            $element.html(i18n.translate(literal, ns, params, skipErros));
                        };
                    }

                    /**
                     * @param literal
                     * @return {string}
                     * @private
                     */
                    _compile(literal) {
                        const parts = literal.match(/{{.*?(}})/g);
                        let addWatcher = false;
                        if (!parts) {
                            return literal.trim();
                        } else {
                            parts.forEach((part) => {
                                if (part.indexOf('::') === -1) {
                                    addWatcher = true;
                                }
                                const forEval = part
                                    .replace('{{', '')
                                    .replace('}}', '')
                                    .replace('::', '');
                                literal = literal.replace(part, $scope.$eval(forEval)).trim();
                                if (!this.watchers[literal]) {
                                    this.forStop.push($scope.$watch(forEval, () => this._getHandler()()));
                                    this.watchers[literal] = true;
                                }
                            });
                        }

                        return literal;
                    }

                    /**
                     * @return {*}
                     * @private
                     */
                    @decorators.cachable()
                    static _getLiteral() {
                        return String(I18n._isAttribute() ? $attrs.wI18n : $element.text()).trim();
                    }

                    /**
                     * @return {boolean}
                     * @private
                     */
                    static _isAttribute() {
                        return !!$attrs.wI18n;
                    }

                }

                return new I18n();
            },
            transclude: true,
            template: function ($element) {
                if ($element.get(0).tagName === 'W-I18N') {
                    return '<span ng-transclude></span>';
                }
            }
        };
    };

    directive.$inject = ['Base', 'i18n', 'decorators'];

    angular.module('app')
        .directive('wI18n', directive);
})();<commit_msg>CLIENT-438: fix localize system<commit_after>(function () {
    'use strict';

    const directive = function (Base, i18n) {
        return {
            scope: true,
            restrict: 'AE',
            link($scope, $element, $attrs) {

                class I18n extends Base {

                    constructor() {
                        super($scope);

                        this._forStop = [];
                        this._watchers = Object.create(null);
                        this._literalTemplate = I18n._getLiteralTemplate();
                        this._parts = this._literalTemplate.match(/{{.*?(}})/g);
                        this._handler = this._getHandler();

                        this._addWatchers();

                        this.listenEventEmitter(i18next, 'languageChanged', this._handler);
                        if ($attrs.params) {
                            const stop = $scope.$watch($attrs.params, this._handler);
                            this._forStop.push(stop);
                        }

                        this._handler();
                    }

                    $onDestroy() {
                        super.$onDestroy();
                        this._forStop.forEach((cb) => cb());
                        this._forStop = [];
                    }

                    /**
                     * @return {Function}
                     * @private
                     */
                    _getHandler() {
                        const ns = i18n.getNs($element);
                        return () => {
                            const skipErrors = 'skipErrors' in $attrs;
                            const params = $attrs.params && $scope.$eval($attrs.params) || undefined;
                            $element.html(i18n.translate(this._compile(this._literalTemplate), ns, params, skipErrors));
                        };
                    }

                    /**
                     * @param {string} literal
                     * @return {string}
                     * @private
                     */
                    _compile(literal) {
                        if (this._parts) {
                            this._parts.forEach((part) => {
                                const forEval = part
                                    .replace('{{', '')
                                    .replace('}}', '')
                                    .replace('::', '');

                                literal = literal.replace(part, $scope.$eval(forEval));
                            });
                        }
                        return literal;
                    }

                    /**
                     * @private
                     */
                    _addWatchers() {
                        if (!this._parts) {
                            return null;
                        }

                        this._parts.forEach((part) => {
                            const needWatcher = part.indexOf('::') === -1;

                            if (needWatcher && !this._watchers[part]) {
                                const forEval = part
                                    .replace('{{', '')
                                    .replace('}}', '')
                                    .replace('::', '');

                                this._forStop.push($scope.$watch(forEval, this._handler));
                                this._watchers[part] = true;
                            }
                        });
                    }

                    /**
                     * @return {*}
                     * @private
                     */
                    static _getLiteralTemplate() {
                        return String(I18n._isAttribute() ? $element.attr('w-i18n') : $element.text()).trim();
                    }

                    /**
                     * @return {boolean}
                     * @private
                     */
                    static _isAttribute() {
                        return !!$attrs.wI18n;
                    }

                }

                return new I18n();
            },
            transclude: true,
            template: function ($element) {
                if ($element.get(0).tagName === 'W-I18N') {
                    return '<span ng-transclude></span>';
                }
            }
        };
    };

    directive.$inject = ['Base', 'i18n'];

    angular.module('app')
        .directive('wI18n', directive);
})();
{'fraction_non_alphanumeric': 0.1152143522833178, 'fraction_numerical': 0.0071062441752096925, 'mean_word_length': 0.7399675719497365, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5886619', 'n_tokens_mistral': 1955, 'n_tokens_neox': 1742, 'n_words': 302}