Example #1
0
locales.forEach((locale) => {
  // Locale specific data
  Cldr.load(data("main/" + locale + "/languages"));

  // Bind to locale
  var cldr = new Cldr(locale);

  // Grab language code (minimal)
  var lang = cldr.attributes.bundle;
  if (resultNames[lang] == null) {
    resultNames[lang] = cldr.main("localeDisplayNames/languages/" + lang);
  }
});
	if (locale === 'root') {
		continue
	}

	// If this locale has no relative time labels
	// in CLDR data then skip it.
	if (CLDR_LOCALES.indexOf(locale) < 0) {
		continue
	}

	// `make-plural` library converts
	// CLDR pluralization rules
	// into a javascript function.
	// https://github.com/eemeli/make-plural.js
	const MakePlurals = MakePlural.load(
		CLDR('supplemental/plurals'),
		// Ordinals aren't needed for relative date/time formatting
		// CLDR('supplemental/ordinals')
	)

	// Pluralization function code
	const functionCode = new MakePlurals(locale).toString('classify')

	// Minify pluralization function code
	let { error, code } = UglifyJS.minify(functionCode)

	if (error) {
		throw error
	}

	// Strip function name.
Example #3
0
var Cldr = require("cldrjs");
var data = require("cldr-data");
var glob = require("glob");
var path = require("path");
var fs = require("fs");

// Find all supported languages
var filenames = glob.sync(path.join(path.dirname(require.resolve("cldr-data")), "main/*"));
var locales = filenames.map((filename) => path.basename(filename))

// Load suppl. data (required)
Cldr.load(data("supplemental/likelySubtags"));

// Language Data
// =============

var resultNames = {};
locales.forEach((locale) => {
  // Locale specific data
  Cldr.load(data("main/" + locale + "/languages"));

  // Bind to locale
  var cldr = new Cldr(locale);

  // Grab language code (minimal)
  var lang = cldr.attributes.bundle;
  if (resultNames[lang] == null) {
    resultNames[lang] = cldr.main("localeDisplayNames/languages/" + lang);
  }
});