Creates a single JSON object from all the languages in locales

@param {*} localesPath Absolute path to the locales folder /sections/section-name/locales/
@returns
14450
async function combineLocales(localesPath) {
  const localesFiles = await fs.readdir(localesPath);
  const jsonFiles = localesFiles.filter((fileName) =>
    fileName.endsWith('.json'),
  );

  return jsonFiles.reduce(async (promise, file) => {
    const accumulator = await promise;
    const localeCode = path
      .basename(file)
      .split('.')
      .shift();
    const fileContents = JSON.parse(
      await fs.readFile(path.resolve(localesPath, file), 'utf-8'),
    );
    accumulator[localeCode] = fileContents;
    return accumulator;
  }, Promise.resolve({}));
}
955646
private static function pluginFolderPaths($plugins, $folder_path)
    {
        $paths = [];

        foreach ($plugins as $path) {
            $iterator = new \DirectoryIterator($path);

            /** @var \DirectoryIterator $directory */
            foreach ($iterator as $directory) {
                if (!$directory->isDir() || $directory->isDot()) {
                    continue;
                }

                // Path to the languages folder
                $lang_path = $directory->getPathName() . '/' . $folder_path;

                // If this folder exists, add it to the list of paths
                if (file_exists($lang_path)) {
                    $paths []= $lang_path;
                }
            }
        }
        return $paths;
    }
39991
function findString(msgPath, opts) {
        const options = merge({log: true}, opts || {});
        let candidateString, matchingString, path;

        // no path? no string
        if (msgPath.length === 0 || !isString(msgPath)) {
            chalk.yellow('i18n.t() - received an empty path.');
            return '';
        }

        // If not in memory, load translations for core
        if (coreStrings === undefined) {
            I18n.init();
        }

        if (options.isThemeString) {
            // If not in memory, load translations for theme
            if (themeStrings === undefined) {
                I18n.loadThemeTranslations();
            }
            // Both jsonpath's dot-notation and bracket-notation start with '$'
            // E.g.: $.store.book.title or $['store']['book']['title']
            // The {{t}} translation helper passes the default English text
            // The full Unicode jsonpath with '$' is built here
            // jp.stringify and jp.value are jsonpath methods
            // Info: https://www.npmjs.com/package/jsonpath
            path = jp.stringify(['$', msgPath]);
            candidateString = jp.value(themeStrings, path) || msgPath;
        } else {
            // Backend messages use dot-notation, and the '$.' prefix is added here
            // While bracket-notation allows any Unicode characters in keys for themes,
            // dot-notation allows only word characters in keys for backend messages
            // (that is \w or [A-Za-z0-9_] in RegExp)
            path = `$.${msgPath}`;
            candidateString = jp.value(coreStrings, path);
        }

        matchingString = candidateString || {};

        if (isObject(matchingString) || isEqual(matchingString, {})) {
            if (options.log) {
                logging.error(new errors.IncorrectUsageError({
                    message: `i18n error: path "${msgPath}" was not found`
                }));
            }

            matchingString = coreStrings.errors.errors.anErrorOccurred;
        }

        return matchingString;
    }
225607
public function getImplementedLocales($path = '/../Resources/translations/')
    {
        $locales = [];
        $finder = $this->finder->files()->in(__DIR__.$path)->name('/platform\.[^.]*\.json/');

        foreach ($finder as $file) {
            $locale = str_replace(['platform.', '.json'], '', $file->getRelativePathname());
            $locales[$locale] = $locale;
        }

        return $locales;
    }
957706
function findI18nKeysAndStrings(filePath) {
    const textContentRegEx = /data-i18n="(.*?)".*?>\s*(.*?)\s*</gs;
    const placeholderRegEx = /data-i18n-placeholder="(.*?)"(?:.*?placeholder="(.*?)")?/g;
    const phraseRegEx = /translatePhrase\('(.*?)'\)/g;

    // Get global variable
    const contents = fs.readFileSync(filePath).toString();

    /** @type {object} */
    const dict = {};

    let textMatch;
    while ((textMatch = textContentRegEx.exec(contents)) !== null) { // eslint-disable-line no-cond-assign
        const key = textMatch[1];
        const phrase = textMatch[2];
        dict[key] = phrase;
    }

    let placeholderMatch;
    while ((placeholderMatch = placeholderRegEx.exec(contents)) !== null) { // eslint-disable-line no-cond-assign
        const key = placeholderMatch[1];
        const phrase = placeholderMatch[2] || '- not found -';
        dict[key] = phrase;
    }

    let phraseMatch;
    while ((phraseMatch = phraseRegEx.exec(contents)) !== null) { // eslint-disable-line no-cond-assign
        const key = phraseMatch[1];
        const phrase = false;
        dict[key] = phrase;
    }

    return dict;
}
42125
function registerLocales (headers) {
  var localesList = {
    indexes: {}
  };
  var i = headers.length - 1;
  var localeName;

  while (i >= 2) {
    localeName = headers[i].trim().split(/[\s\(]/)[0];
    localesList[localeName] = {
      localeName: localeName,
      messages: {}
    };
    localesList.indexes[i] = localeName;
    i--;
  }
  return localesList;
}
439099
function(path) {
            if (path === undefined) {
                path = document.location.pathname;
            }
            var locale = this.getConfigValue('LOCALE').toString();

            // if there is no way to figure out the locale, just return pathname
            if (!this.getConfigValue('LOCALE') || path.indexOf(locale) == -1) {
                return path;
            }
            var start = locale.length + path.indexOf(locale);
            return path.slice(start);
        }
275488
protected function loadJsonPaths($locale)
    {
        $jsonPaths = array_merge($this->jsonPaths, array($this->path));

        $reducer = function ($items, $callback, $initial = null) {
            return array_reduce($items, $callback, $initial);
        };

        $decoder = function ($output, $path) use ($locale) {
            if (file_exists($full = "{$path}/{$locale}.json")) {
                $decoded = json_decode(file_get_contents($full), true);

                if (is_null($decoded) || json_last_error() !== JSON_ERROR_NONE) {
                    throw new RuntimeException("Translation file [{$full}] contains an invalid JSON structure.");
                }

                $output = array_merge($output, $decoded);
            }

            return $output;
        };

        return $reducer($jsonPaths, function ($output, $path) use ($decoder) {
            return $decoder($output, $path);
        }, array());
    }
1147822
function getTypingNamesFromJson(jsonPath, filesToWatch) {
                if (host.fileExists(jsonPath)) {
                    filesToWatch.push(jsonPath);
                }
                var result = ts.readConfigFile(jsonPath, function (path) { return host.readFile(path); });
                if (result.config) {
                    var jsonConfig = result.config;
                    if (jsonConfig.dependencies) {
                        mergeTypings(ts.getOwnKeys(jsonConfig.dependencies));
                    }
                    if (jsonConfig.devDependencies) {
                        mergeTypings(ts.getOwnKeys(jsonConfig.devDependencies));
                    }
                    if (jsonConfig.optionalDependencies) {
                        mergeTypings(ts.getOwnKeys(jsonConfig.optionalDependencies));
                    }
                    if (jsonConfig.peerDependencies) {
                        mergeTypings(ts.getOwnKeys(jsonConfig.peerDependencies));
                    }
                }
            }
3144
function fromJson(collection, collectionPath, next) {

  var docsBulk = [];
  var docs = fs.readdirSync(collectionPath);
  var last = ~~docs.length, counter = 0;
  if (last === 0) {
    return next(null);
  }

  docs.forEach(function(docName) {

    var doc, data;
    try {
      data = fs.readFileSync(collectionPath + docName);
    } catch (err) {
      return last === ++counter ? next(null) : null;
    }
    try {
      doc = JSON.parse(data);
    } catch (err) {
      return last === ++counter ? next(err) : error(err);
    }

    docsBulk.push({
      insertOne: {
        document: doc
      }
    });

    return last === ++counter ? collection.bulkWrite(docsBulk, next) : null;
  });
}
893782
function readJSON (filePath) {
  let json = fs.readFileSync(filePath, "utf8");

  try {
    return JSON.parse(json);
  }
  catch (e) {
    throw ono(e, `Error parsing ${filePath}`);
  }
}
1106017
@Route(method = HttpMethod.GET, uri = "i18n/bundles/{file<.+>}.json")
    public Result getBundleResourceForI18Next(@QueryParameter("locales") String listOfLocales,
                                              @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch) {
        // Parse the list of locale
        List<Locale> locales = new ArrayList<>();
        if (!Strings.isNullOrEmpty(listOfLocales)) {
            String[] items = listOfLocales.split(" ");
            for (String item : items) {
                // Manage the 'dev' value (it's the default locale used by i18next
                if ("dev".equalsIgnoreCase(item)) {
                    locales.add(InternationalizationService.DEFAULT_LOCALE);
                } else {
                    locales.add(Locale.forLanguageTag(item));
                }
            }
        }

        String etag;
        StringBuilder builder = new StringBuilder();
        for (Locale locale : locales) {
            builder.append(service.etag(locale));
        }
        etag = builder.toString();

        if (ifNoneMatch != null && ifNoneMatch.equals(etag)) {
            return new Result(Status.NOT_MODIFIED);
        }

        // i18next use a specific Json Format
        ObjectNode result = json.newObject();
        for (Locale locale : locales) {
            ObjectNode lang = json.newObject();
            ObjectNode translation = json.newObject();
            lang.set("translation", translation);
            Collection<ResourceBundle> bundles = service.bundles(locale);
            for (ResourceBundle bundle : bundles) {
                for (String key : bundle.keySet()) {
                    populateJsonResourceBundle(translation, key, bundle.getString(key));
                }
            }
            String langName = locale.toLanguageTag();
            if (locale.equals(InternationalizationService.DEFAULT_LOCALE)) {
                langName = "dev";
            }
            result.set(langName, lang);
        }
        return ok(result).with(HeaderNames.ETAG, etag);
    }
915317
function loadJson(filepath) {
	const json = fs.readFileSync(require.resolve(filepath), 'utf8');
	return JSON.parse(stripJsonComments(json));
}
737722
public static Map<String, LocalResource> createLocalResources(FileSystem fs, String classPathDir) {
		Map<String, LocalResource> localResources = provisionAndLocalizeCurrentClasspath(fs, classPathDir);
		return localResources;
	}
162037
function generateAllLocalesFile(LOCALES, ALIASES) {
  const existingLocalesAliases = {};
  const existingLocalesData = {};

  // for each locale, get the data and the list of equivalent locales
  LOCALES.forEach(locale => {
    const eqLocales = new Set();
    eqLocales.add(locale);
    if (locale.match(/-/)) {
      eqLocales.add(locale.replace(/-/g, '_'));
    }

    // check for aliases
    const alias = ALIASES[locale];
    if (alias) {
      eqLocales.add(alias);

      if (alias.match(/-/)) {
        eqLocales.add(alias.replace(/-/g, '_'));
      }

      // to avoid duplicated "case" we regroup all locales in the same "case"
      // the simplest way to do that is to have alias aliases
      // e.g. 'no' --> 'nb', 'nb' --> 'no-NO'
      // which means that we'll have 'no', 'nb' and 'no-NO' in the same "case"
      const aliasKeys = Object.keys(ALIASES);
      for (let i = 0; i < aliasKeys.length; i++) {
        const aliasValue = ALIASES[alias];
        if (aliasKeys.indexOf(alias) !== -1 && !eqLocales.has(aliasValue)) {
          eqLocales.add(aliasValue);

          if (aliasValue.match(/-/)) {
            eqLocales.add(aliasValue.replace(/-/g, '_'));
          }
        }
      }
    }

    for (let l of eqLocales) {
      // find the existing content file
      const path = `${RELATIVE_I18N_DATA_FOLDER}/${l}.ts`;
      if (fs.existsSync(`${RELATIVE_I18N_DATA_FOLDER}/${l}.ts`)) {
        const localeName = formatLocale(locale);
        existingLocalesData[locale] =
            fs.readFileSync(path, 'utf8')
                .replace(`${HEADER}\n`, '')
                .replace('export default ', `export const locale_${localeName} = `)
                .replace('function plural', `function plural_${localeName}`)
                .replace(/,(\n  | )plural/, `, plural_${localeName}`)
                .replace('const u = undefined;\n\n', '');
      }
    }

    existingLocalesAliases[locale] = eqLocales;
  });

  function generateCases(locale) {
    let str = '';
    let locales = [];
    const eqLocales = existingLocalesAliases[locale];
    for (let l of eqLocales) {
      str += `case '${l}':\n`;
      locales.push(`'${l}'`);
    }
    let localesStr = '[' + locales.join(',') + ']';

    str += `  l = locale_${formatLocale(locale)};
    locales = ${localesStr};
    break;\n`;
    return str;
  }

  function formatLocale(locale) { return locale.replace(/-/g, '_'); }
  // clang-format off
  return `${HEADER}
import {registerLocaleData} from '../src/i18n/locale_data';

const u = undefined;

${LOCALES.map(locale => `${existingLocalesData[locale]}`).join('\n')}

let l: any;
let locales: string[] = [];

switch (goog.LOCALE) {
${LOCALES.map(locale => generateCases(locale)).join('')}}

if(l) {
  locales.forEach(locale => registerLocaleData(l, locale));
}
`;
  // clang-format on
}
475468
function localizePaths(pathList) {
  // resolve paths so that './foo/bar.js' and 'foo/bar.js' resolve to the same localized path
  pathList = pathList.map(function (p) {
    var resolvedPath = path.resolve(p);
    if (resolvedPath.substr(resolvedPath.length - 3) === '.js') {
      resolvedPath = resolvedPath.substr(0, resolvedPath.length - 3);
    }
    return resolvedPath;
  });

  var localizedPathList = [];
  if (pathList.length > 0) {
    var commonPath = null;
    pathList.forEach(function (fullPath, i) {
      var parts;
      if (commonPath === null) {
        parts = fullPath.split('/');
        if (parts.length > 1) {
          commonPath = parts.slice(0, parts.length - 1).join('/') + '/';
        } else {
          commonPath = '';
        }
      } else if (commonPath.length > 0) {
        parts = commonPath.split('/');
        parts.pop();
        commonPath = '';
        for (var partIndex = 0; partIndex < parts.length; partIndex++) {
          var testPath = commonPath + parts[partIndex] + '/';
          if (fullPath.substring(0, testPath.length) === testPath) {
            commonPath = testPath;
          } else {
            break;
          }
        }
      }
    });
    pathList.forEach(function (fullPath, i) {
      localizedPathList.push(fullPath.substr(commonPath.length));
    });
  }
  return localizedPathList;
}
696041
function getPluralCategory(value, cases, ngLocalization, locale) {
    var /** @type {?} */ key = "=" + value;
    if (cases.indexOf(key) > -1) {
        return key;
    }
    key = ngLocalization.getPluralCategory(value, locale);
    if (cases.indexOf(key) > -1) {
        return key;
    }
    if (cases.indexOf('other') > -1) {
        return 'other';
    }
    throw new Error("No plural message found for value \"" + value + "\"");
}