/*
Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
<info@greenscale.de>

»heimdall« is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

»heimdall« is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with »heimdall«. If not, see <http://www.gnu.org/licenses/>.
 */


namespace _heimdall
{
	
	/**
	 */
	export async function init(
	) : Promise<void>
	{
		const workdir : string = __dirname;
		
		// translation
		{
			const language_order : Array<string> = ["de", "en"];
			await lib_plankton.translate.initialize_promise(
				{
					"verbosity": 1,
					"order": language_order,
					"packages": await Promise.all(
						[
							{"identifier": "de", "path": (workdir + "/localization/de.json")},
							{"identifier": "en", "path": (workdir + "/localization/en.json")},
						]
						.map(
							(entry) => (
								lib_plankton.file.read(entry.path)
								.then(content => Promise.resolve(JSON.parse(content)))
								.then(tree => Promise.resolve({"meta": {"identifier": entry.identifier}, "tree": tree}))
							)
						)
					),
				}
			);
			const env_language : (null | string) = _heimdall.helpers.misc.get_env_language();
			if (
				! (
					(env_language !== null)
					&&
					language_order.includes(env_language)
				)
			) {
				// do nothing
			}
			else {
				lib_plankton.translate.promote(env_language);
			}
		}
	}
	
}
