<commit_before>var Promise = require('promise');
var _ = require('lodash');

var hashSimple = '[(.|.)]';
var translateService;

function init(setting) {
	translateService = require('yandex-translate')(setting.yandexApiKey);
}

function translateString(language, key, destObj) {
  // Find the keys of the current object that has string value (str is translatable)
	var objKeys = _.pickBy(destObj[key], _.isString);
	var keysArray = _.keys(objKeys);
	var valuesArray = _.concat(_.values(objKeys));

	return new Promise(function (resolve, reject) {
		var valuesStr = valuesArray.join(hashSimple);
		if (valuesStr === ''){
			// there is nothing to translate, so don't ask Yandex (Yandex will respond with an error)
			resolve(destObj);
			return;
		}
		translateService.translate(valuesStr, {to: language}, function (err, res) {
			if (err || !res) {
				reject('Yandex translation service failed', err);
			} else {
        // yandex return an array string and so we need split back to the normal vlues
				var result = res.text[0].split(hashSimple);<commit_msg>fix(yandex): fix error with deeply nested objects<commit_after>var Promise = require('promise');
var _ = require('lodash');

var hashSimple = '[(.|.)]';
var translateService;

function init(setting) {
	translateService = require('yandex-translate')(setting.yandexApiKey);
}

function translateString(language, key, destObj) {
  // Find the keys of the current object that has string value (str is translatable)
	var objKeys = _.pickBy(destObj[key], _.isString);
	var keysArray = _.keys(objKeys);
	var valuesArray = _.concat(_.values(objKeys));

	return new Promise(function (resolve, reject) {
		var valuesStr = valuesArray.join(hashSimple);
		if (valuesStr === '') {
			// there is nothing to translate, so don't ask Yandex (Yandex will respond with an error)
			resolve(destObj);
			return;
		}
		translateService.translate(valuesStr, {to: language}, function (err, res) {
			if (err || !res) {
				reject('Yandex translation service failed', err);
			} else {
        // yandex return an array string and so we need split back to the normal vlues
				var result = res.text[0].split(hashSimple);
{'fraction_non_alphanumeric': 0.12749188687992583, 'fraction_numerical': 0.0009272137227630969, 'mean_word_length': 4.422110552763819, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '5152756', 'n_tokens_mistral': 694, 'n_tokens_neox': 647, 'n_words': 207}