<commit_before>/*jslint node: true, forin: true, jslint white: true, newcap: true*/
/*global console*/
/*
 * parse
 * author : <NAME>
 * https://github.com/iwatakeshi
 * license : MIT
 * Code heavily borrowed from <NAME>
 * https://github.com/adamwdraper
 */
(function() {
    'use strict';

    var parse,
        hasModule = (typeof module !== 'undefined' && module.exports),
        _ = require('underscore'),
        loader = require('./loader.js'),
        config = require('./config.js'),
        utils = require('./utils.js'),
        isDefined = utils.isDefined,
        router = require('./router.js'),
        localemap = require('../maps/locales.js'),
        regex = utils.regex,
        debug = utils.debug;

    //normal parser for phrases
    parse = function(phrase, locale, plural) {
        var result, routeResult, universeResult;
        //check if we have to override
        if (isOverride(locale)) {
            //the load a new instance of loader with the json loaded
            //to the overrided locale
            result = new loader(locale.locale).json();
        } else {
            result = loader(locale).json();
        }
        var _result;
        if (config().router()) {
            if (router().route().length() === 0) {

                _result = result[router().route().dot()][phrase];
                if (_result) {
                    routeResult = resultParser(result[router().route().dot()][phrase], locale, plural);
                } else if (result[config().keywords().universe][phrase]) {
                    universeResult = resultParser(result[config().keywords().universe][phrase], locale, plural);
                } else {
                    return phrase;
                }
            } else {
                //check if the definition contains the route
                _result = dotParser(router().route().dot(), result);
                //if it does
                if (_result) {
                    // do something
                    routeResult = resultParser(dotParser(router().route().dot(), result)[phrase], locale, plural);
                    //else lets try universe
                } else {
                    _result = dotParser(router().route().dot(), result);
                    //if universe exists
                    if (_result) {
                        universeResult = resultParser(result[config().keywords().universe][phrase], locale, plural);
                    } else {
                        return phrase;
                    }
                }
            }
            //if result still has trouble
            if (!routeResult) {
                //try universe
                if (universeResult) {
                    routeResult = universeResult;
                }
            }
            if (isDefault(locale) && !plural) {
                return phrase;
            } else {
                return routeResult || phrase;
            }
        } else {
            return resultParser(result[phrase], locale, plural) || phrase;
        }
    };

    /*
    @param {RegEx Array} input
    @param {String} locale
    @param {Boolean} plural
    */
    //bracket handler
    parse.bracket = function(input, locale, plural) {
        var search, dot, result, routeResult, universeResult, results;
        try {
            if (input[1]) {
                search = input[1];
                debug(search).debug("module parse, fn: bracket, Parse Bracket search");
            }
            if (input[2]) {
                dot = input[2];
                debug(dot).debug("module parse, fn: bracket, Parse Bracket dot");
                if (dot.indexOf('plural') > -1) {
                    //prevents the word plural to clash with an existing 'plural' ie plural.plural
                    plural = false;
                }<commit_msg>Fixed isssue if result in phrase parser is undefined to just return the phrase.<commit_after>/*jslint node: true, forin: true, jslint white: true, newcap: true*/
/*global console*/
/*
 * parse
 * author : <NAME>
 * https://github.com/iwatakeshi
 * license : MIT
 * Code heavily borrowed from <NAME>
 * https://github.com/adamwdraper
 */
(function() {
    'use strict';

    var parse,
        hasModule = (typeof module !== 'undefined' && module.exports),
        _ = require('underscore'),
        loader = require('./loader.js'),
        config = require('./config.js'),
        utils = require('./utils.js'),
        isDefined = utils.isDefined,
        router = require('./router.js'),
        localemap = require('../maps/locales.js'),
        regex = utils.regex,
        debug = utils.debug;

    //normal parser for phrases
    parse = function(phrase, locale, plural) {
        var result, routeResult, universeResult;
        //check if we have to override
        if (isOverride(locale)) {
            //the load a new instance of loader with the json loaded
            //to the overrided locale
            result = new loader(locale.locale).json();
        } else {
            result = loader(locale).json();
        }
        var _result;
        if (config().router()) {
            if (router().route().length() === 0) {

                _result = result[router().route().dot()][phrase];
                if (_result) {
                    routeResult = resultParser(result[router().route().dot()][phrase], locale, plural);
                } else if (result[config().keywords().universe][phrase]) {
                    universeResult = resultParser(result[config().keywords().universe][phrase], locale, plural);
                } else {
                    return phrase;
                }
            } else {
                //check if the definition contains the route
                _result = dotParser(router().route().dot(), result);
                //if it does
                if (_result) {
                    // do something
                    routeResult = resultParser(dotParser(router().route().dot(), result)[phrase], locale, plural);
                    //else lets try universe
                } else {
                    _result = dotParser(router().route().dot(), result);
                    //if universe exists
                    if (_result) {
                        universeResult = resultParser(result[config().keywords().universe][phrase], locale, plural);
                    } else {
                        return phrase;
                    }
                }
            }
            //if result still has trouble
            if (!routeResult) {
                //try universe
                if (universeResult) {
                    routeResult = universeResult;
                }
            }
            if (isDefault(locale) && !plural) {
                return phrase;
            } else {
                return routeResult || phrase;
            }
        } else {
            if (result) {
                return resultParser(result[phrase], locale, plural) || phrase;
            } else {
                return phrase;
            }
        }
    };

    /*
    @param {RegEx Array} input
    @param {String} locale
    @param {Boolean} plural
    */
    //bracket handler
    parse.bracket = function(input, locale, plural) {
        var search, dot, result, routeResult, universeResult, results;
        try {
            if (input[1]) {
                search = input[1];
                debug(search).debug("module parse, fn: bracket, Parse Bracket search");
            }
            if (input[2]) {
                dot = input[2];
                debug(dot).debug("module parse, fn: bracket, Parse Bracket dot");
                if (dot.indexOf('plural') > -1) {
                    //prevents the word plural to clash with an existing 'plural' ie plural.plural
                    plural = false;
                }
{'fraction_non_alphanumeric': 0.12311236242641413, 'fraction_numerical': 0.0015357051446122344, 'mean_word_length': 1.4699747155499368, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4071034', 'n_tokens_mistral': 1968, 'n_tokens_neox': 1866, 'n_words': 520}