<commit_before>
import { Color, FileLoader, EventDispatcher } from '../Three';
import { x18n } from '../3rdParty/x18n';
import { lang_en } from './default-lang';
import { defaultTheme } from './defaultTheme';

const environment = new Map();
const themeColors = new Map();

// setup default language

x18n.register( 'en', lang_en );
x18n.set( 'en' );

const Cfg = Object.create( EventDispatcher.prototype );

Cfg.i18n = x18n.t;

Cfg.set = function setConfig ( envs ) {

	if ( envs === undefined ) return;

	var pName;

	for ( pName in envs ) {

		environment.set ( pName , envs[ pName ] );

	}

	Cfg.setLanguage( Cfg.value( 'language', navigator.language.slice( 0, 2 ) ) );

};

Cfg.setLanguage = function ( lang ) {

	if ( lang === 'en' ) {

		x18n.set( 'en' );

	} else {

		// attempt to register non-default language

		console.log( 'loading language file for:', lang );
		const loader = new FileLoader().setPath( Cfg.value( 'home' ) + 'lib/' );

		loader.load( 'lang-' + lang + '.json', _languageLoaded, null, _languageError );

	}

	x18n.on( [ 'lang:change' ], function () { Cfg.dispatchEvent( { type: 'change', name: name } ); } );

	return;

	function _languageLoaded( response ) {

		console.log( 'loaded language [' + lang + ']' );

		x18n.register( lang, JSON.parse( response ) );
		x18n.set( lang );

	}

	function _languageError() {

		console.log( 'error loading language file', lang );

	}

};

Cfg.value = function getValue ( item, defaultValue ) {

	if ( environment.has( item ) ) {

		return environment.get( item );

	} else {

		return defaultValue;

	}

};

Cfg.themeValue = function getThemeValue ( name ) {

	const theme = environment.get( 'theme' );

	const parts = name.split( '.' );
	var value;

	if ( theme !== undefined ) {

		value = Cfg.treeValue( theme, parts );

	}

	if ( value === undefined ) {

		value = Cfg.treeValue( defaultTheme, parts);

	}

	return value;


};

Cfg.treeValue = function ( theme, parts ) {

	var i;
	var top = theme;
	var part;

	for ( i = 0; i < parts.length; i++ ) {

		part = parts[ i ];

		if ( top[ part ] === undefined ) return undefined;

		top = top[ part ];

	}

	return top;

};
<commit_msg>add API to get radian values from theme values sppecified in degrees<commit_after>
import { Color, FileLoader, EventDispatcher, Math as _Math } from '../Three';
import { x18n } from '../3rdParty/x18n';
import { lang_en } from './default-lang';
import { defaultTheme } from './defaultTheme';

const environment = new Map();
const themeColors = new Map();

// setup default language

x18n.register( 'en', lang_en );
x18n.set( 'en' );

const Cfg = Object.create( EventDispatcher.prototype );

Cfg.i18n = x18n.t;

Cfg.set = function setConfig ( envs ) {

	if ( envs === undefined ) return;

	var pName;

	for ( pName in envs ) {

		environment.set ( pName , envs[ pName ] );

	}

	Cfg.setLanguage( Cfg.value( 'language', navigator.language.slice( 0, 2 ) ) );

};

Cfg.setLanguage = function ( lang ) {

	if ( lang === 'en' ) {

		x18n.set( 'en' );

	} else {

		// attempt to register non-default language

		console.log( 'loading language file for:', lang );
		const loader = new FileLoader().setPath( Cfg.value( 'home' ) + 'lib/' );

		loader.load( 'lang-' + lang + '.json', _languageLoaded, null, _languageError );

	}

	x18n.on( [ 'lang:change' ], function () { Cfg.dispatchEvent( { type: 'change', name: name } ); } );

	return;

	function _languageLoaded( response ) {

		console.log( 'loaded language [' + lang + ']' );

		x18n.register( lang, JSON.parse( response ) );
		x18n.set( lang );

	}

	function _languageError() {

		console.log( 'error loading language file', lang );

	}

};

Cfg.value = function getValue ( item, defaultValue ) {

	if ( environment.has( item ) ) {

		return environment.get( item );

	} else {

		return defaultValue;

	}

};

Cfg.themeValue = function getThemeValue ( name ) {

	const theme = environment.get( 'theme' );

	const parts = name.split( '.' );
	var value;

	if ( theme !== undefined ) {

		value = Cfg.treeValue( theme, parts );

	}

	if ( value === undefined ) {

		value = Cfg.treeValue( defaultTheme, parts);

	}

	return value;


};

Cfg.themeAngle = function getThemeAngle ( name ) {

	return _Math.degToRad( Cfg.themeValue ( name ) );

};

Cfg.treeValue = function ( theme, parts ) {

	var i;
	var top = theme;
	var part;

	for ( i = 0; i < parts.length; i++ ) {

		part = parts[ i ];

		if ( top[ part ] === undefined ) return undefined;

		top = top[ part ];

	}

	return top;

};

{'fraction_non_alphanumeric': 0.16050756901157615, 'fraction_numerical': 0.01068566340160285, 'mean_word_length': 3.175650557620818, 'pattern_counts': {'":': 0, '<': 5, '<?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': '306919', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1514, 'n_words': 428}