Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const fs = require('fs');
const path = require('path');
const glob = require('glob');
const i18n = require('../lib/i18n/i18n.js');
const lookupClosestLocale = require('lookup-closest-locale');
const cldrAliasData = require('cldr-core/supplemental/aliases.json');
const cldrAliases = cldrAliasData.supplemental.metadata.alias.languageAlias;
const cldrParentsData = require('cldr-core/supplemental/parentLocales.json');
const cldrParentLocales = cldrParentsData.supplemental.parentLocales.parentLocale;
// const
// Object.entries(cldrAliases).forEach(([alias, entry]) => { if (locales[entry._replacement]) console.log(alias, entry) })
const lhLocales = glob
.sync('./lighthouse-core/lib/i18n/locales/*.json')
.filter(f => !f.includes('.ctc.json'))
.map(filename => path.parse(filename).name);
//
// 1. Validate the locales we store are canonical and not an alias
//
const fs = require('fs');
const path = require('path');
const glob = require('glob');
const i18n = require('../lib/i18n/i18n.js');
const lookupClosestLocale = require('lookup-closest-locale');
const cldrAliasData = require('cldr-core/supplemental/aliases.json');
const cldrAliases = cldrAliasData.supplemental.metadata.alias.languageAlias;
const cldrParentsData = require('cldr-core/supplemental/parentLocales.json');
const cldrParentLocales = cldrParentsData.supplemental.parentLocales.parentLocale;
// const
// Object.entries(cldrAliases).forEach(([alias, entry]) => { if (locales[entry._replacement]) console.log(alias, entry) })
const lhLocales = glob
.sync('./lighthouse-core/lib/i18n/locales/*.json')
.filter(f => !f.includes('.ctc.json'))
.map(filename => path.parse(filename).name);
//
// 1. Validate the locales we store are canonical and not an alias
//
const aliasExceptions = ['zh-HK', 'zh-TW']; // TC pipeline still uses these codes rather than the CLDR's preferred `zh-Hant-HK`, `zh-Hant-TW`
for (const localeCode of lhLocales) {
import * as glob from "glob"
import * as path from "path"
let CLDR_DATES_DIR = path.dirname(require.resolve("cldr-dates-full/package.json"))
let CLDR_NUMBERS_DIR = path.dirname(require.resolve("cldr-numbers-full/package.json"))
// These are the exceptions to the default algorithm for determining a locale's
// parent locale.
let PARENT_LOCALES_HASH = require("cldr-core/supplemental/parentLocales.json")
.supplemental.parentLocales.parentLocale
let CALENDARS_LOCALES_HASH = glob.sync("*/ca-*.json", {
cwd: path.resolve(CLDR_DATES_DIR, "main")
}).reduce((hash, filename) => {
hash[path.dirname(filename)] = true
return hash
}, {})
let NUMBERS_LOCALES_HASH = glob.sync("*/numbers.json", {
cwd: path.resolve(CLDR_NUMBERS_DIR, "main")
}).reduce((hash, filename) => {
hash[path.dirname(filename)] = true
return hash
}, {})
new Promise((resolve, reject) => {
try {
const Cldr = require('cldrjs');
Cldr.load(require('cldr-core/supplemental/likelySubtags'));
// Load all bundles
for (locale of require('cldr-core/availableLocales').availableLocales.modern) {
Cldr.load(require(`cldr-localenames-modern/main/${locale}/languages`))
}
resolve(new CldrLanguages(Cldr))
} catch (err) {
reject(err)
}
});
let NUMBERS_LOCALES_HASH = glob.sync("*/numbers.json", {
cwd: path.resolve(CLDR_NUMBERS_DIR, "main")
}).reduce((hash, filename) => {
hash[path.dirname(filename)] = true
return hash
}, {})
let CURRENCIES_LOCALES_HASH = glob.sync("*/currencies.json", {
cwd: path.resolve(CLDR_NUMBERS_DIR, "main")
}).reduce((hash, filename) => {
hash[path.dirname(filename)] = true
return hash
}, {})
let DEFAULT_CONTENT_ARRAY = require("cldr-core/defaultContent.json")
.defaultContent.map((value) => value.replace(/_/g, "-"))
// Some locales that have a `pluralRuleFunction` don't have a `dateFields.json`
// file, and visa versa, so this creates a unique collection of all locales in
// the CLDR for which we need data from.
let ALL_LOCALES_HASH =
Object.keys(PARENT_LOCALES_HASH)
.concat(Object.keys(CALENDARS_LOCALES_HASH))
.concat(Object.keys(NUMBERS_LOCALES_HASH))
.concat(Object.keys(CURRENCIES_LOCALES_HASH))
.concat(DEFAULT_CONTENT_ARRAY)
.sort()
.reduce((hash, locale) => {
hash[locale.toLowerCase()] = locale
return hash
}, {})
langs[lang] = `${langs[lang] || ""}${data}
`;
});
}
return Promise.resolve();
}
const availableLanguages = document.querySelector(
"meta[name=availableLanguages]").content.split(",");
const negotiated = negotiateLanguages(
navigator.languages,
availableLanguages,
{
defaultLocale: "en-US",
likelySubtags: likelySubtagsData.supplemental.likelySubtags
}
);
this.props.setNegotiatedLanguages(negotiated);
const promises = negotiated.map(language =>
Promise.all(
[
fetch(`/static/locales/${language}/app.ftl`).then(response => addLang(language, response)),
fetch(`/static/locales/${language}/experiments.ftl`).then(response => addLang(language, response))
]
)
);
Promise.all(promises).then(() => {
this.props.setLocalizations(langs);
describe('Ordinal rules', () => {
for (var lc in ordinalData.supplemental['plurals-type-ordinal']) {
describe(lc, () => testPluralData('ordinal', lc, getPlural))
}
})
})
describe('Cardinal rules', () => {
for (var lc in cardinalData.supplemental['plurals-type-cardinal']) {
describe(lc, () => testPluralData('cardinal', lc, getPlural))
}
})
return next();
}
const langs = header.replace(/\s/g, '').match(acceptLanguages) || ['en-US'];
const preferred = langs
.map(l => {
const parts = l.split(';');
return {
locale: parts[0],
q: parts[1] ? parseFloat(parts[1].split('=')[1]) : 1
};
})
.sort((a, b) => b.q - a.q)
.map(x => x.locale);
req.language = negotiateLanguages(preferred, languages, {
strategy: 'lookup',
likelySubtags: langData.supplemental.likelySubtags,
defaultLocale: 'en-US'
})[0];
next();
};