/*
 * Developed for the CRIF-HCI project by Thomson Consulting International.
 * TCI, 31st Floor, Centre Point, 103 New Oxford Street, London. WC1A 1PG.
 *
 * SOURCE FILE
 *	language.js
 *
 * DESCRIPTION
 *	Contains a set of generic functions for handling language-dependent
 *	messages.
 *
 * FUNCTIONS
 *	localize ( key )
 *	setLocalMessage ( key, message)
 */

/*
 * Returns the localized form of a message given a message key. This function can
 * take up to five parameters to substitute into the message string.
 *
 * @param key the message key
 * @return the localized message
 */
function localize ( key, arg1, arg2, arg3, arg4, arg5 ) {

	assert(_localized != null, "Missing \'_localized\' object");
	var local = _localized[key];
	assert(local != null, "No localization for \'" + key + "\'");

	if (arg1 != null) {
		local = replace(local, "{1}", arg1);
	}
	
	if (arg2 != null) {
		local = replace(local, "{2}", arg2);
	}
	
	if (arg3 != null) {
		local = replace(local, "{3}", arg3);
	}

	if (arg4 != null) {
		local = replace(local, "{4}", arg4);
	}

	if (arg5 != null) {
		local = replace(local, "{5}", arg5);
	}

	return local;
}

/*
 * Defines a localized message for a given message key.
 *
 * @param key the message key
 * @param message the message
 */
function setLocalized ( key, message ) {
	//if (_localized == null) {
		_localized = new Object();
	//}

	_localized[key] = message;
}


