<?php

$sPath = implode(DIRECTORY_SEPARATOR, Array('.', 'locale', $GLOBALS['sLanguage'], 'LC_MESSAGES', 'XPindex.po'));
$aPot = Array();

if (file_exists($sPath)) {
	$aRawPot = file($sPath);
	$aPot = Array();
	$sLastmatch = '';

	foreach ($aRawPot as $sLine) {
		// Comments
		if (preg_match('/^(?:[\s]+)?#/', $sLine) > 0) continue;

		// Empty Lines
		if (preg_match('/^(?:[\s]+)?$/', $sLine) > 0) continue;

		// Identifier
		if (preg_match('/^(?:[\s]+)?msgid(?:[\s]+)?"((?:.+)?)"$/', $sLine, $aMatch)) {
			$sLastmatch = $aMatch[1];

			$aPot[$sLastmatch] = $sLastmatch;

			continue;
		}

		// Translation
		if (preg_match('/^(?:[\s]+)?msgstr(?:[\s]+)?"((?:.+)?)"$/', $sLine, $aMatch)) {
			if ($aMatch[1] != "") $aPot[$sLastmatch] = $aMatch[1];

			continue;
		}

		// Multi-line Translation
		if (preg_match('/^(?:[\s]+)?"((?:.+)?)"$/', $sLine, $aMatch)) {
			if ($aMatch[1] != "") $aPot[$sLastmatch] .= $aMatch[1];

			continue;
		}
	}
}

function _($String) {
	global $aPot;

	if (!isset($aPot)) {
		return $String;
	} else {
		return $aPot[$String];
	}
}

?>
