<?php
/**
 * @brief		Return JS language strings
 *
 * @copyright	(c) 2001 - 2016 Invision Power Services, Inc.
 *
 * @package		IPS Community Suite
 * @since		18 Feb 2013
 * @version		SVN_VERSION_NUMBER
 */

require_once '../../../../init.php';

$langId	= intval( \IPS\Request::i()->langId );
$_lang	= array();

foreach ( \IPS\Db::i()->select( '*', 'core_sys_lang_words', array( 'lang_id=? AND word_js=?', $langId, TRUE ) ) as $row )
{
	$_lang[ $row['word_key'] ] = $row['word_custom'] ?: $row['word_default'];
}

if ( \IPS\IN_DEV )
{
	foreach ( \IPS\Application::applications() as $app )
	{
		if( \IPS\Application::appIsEnabled( $app->directory ) )
		{
			if ( file_exists( \IPS\ROOT_PATH . "/applications/{$app->directory}/dev/jslang.php" ) )
			{
				require \IPS\ROOT_PATH . "/applications/{$app->directory}/dev/jslang.php";
				$_lang = array_merge( $_lang, $lang );
			}
		}
	}
	foreach ( \IPS\Plugin::plugins() as $plugin )
	{
		if ( file_exists( \IPS\ROOT_PATH . "/plugins/{$plugin->location}/dev/lang.php" ) )
		{
			require \IPS\ROOT_PATH . "/plugins/{$plugin->location}/dev/lang.php";
			$_lang = array_merge( $_lang, $lang );
		}
	}
}

$cacheHeaders	= ( \IPS\IN_DEV !== true AND \IPS\Theme::designersModeEnabled() !== true ) ? \IPS\Output::getCacheHeaders( time(), 360 ) : array();

/* Display */
\IPS\Output::i()->sendOutput( 'ips.setString( ' . json_encode( $_lang ) . ')', 200, 'text/javascript', $cacheHeaders );