1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7// TransifexContoller extends the language controller with Transifex (www.transifex.com) related functionalities
8
9class Services_Language_TransifexController extends Services_Language_Controller
10{
11
12	function __construct()
13	{
14		$this->utilities = new Services_Language_Utilities;
15	}
16
17	function setUp()
18	{
19		global $prefs;
20
21		if ($prefs['feature_transifex'] = 'n') { //TODO: change it to != y
22			throw new Services_Exception(tr('Feature Disabled'), 403);
23		}
24	}
25
26	/**
27	 * Process a transifex language.php file
28	 *
29	 * @param $file Complete path to the file including file name
30	 *
31	 * @return array
32	 */
33	private function processTransifexLanguagePhp($file)
34	{
35		//check if file is available
36		if (! is_file($file)) {
37			throw new Services_Exception_Denied(tr('Invalid file parameter supplied'));
38		}
39
40		//language.php file is big, set time limit to prevent timeout
41		set_time_limit(0);
42
43		//read the file into an array
44		$fileContent = file($file);
45
46		//preg_match array values to get translation strings from the language.php file
47		//$captureFullString |(^\/\/\s*?".+"\s*=>\s*".*".*)|
48		//$captureSource |^\/\/\s*?".+"\s*=>\s*"(.*)".*|
49		//$captureTranslation |^\/\/\s*?"(.+)"\s*=>\s*".*".*|
50		foreach ($fileContent as $line) {
51			if (preg_match('|^\/\/\s*?"(.+)"\s*=>\s*"(.*)".*|', $line, $matches)) {
52				//assuming that untranslated lines are those, that have the same key and value OR where value is empty
53				if (($matches[1] === $matches[2]) || ($matches[2] === '')) {
54					$untranslated[$matches[1]] = $matches[2];
55					//lets keep the original lines as they were so that untranslated strings remain commented out
56					$lang[] = $matches[0];
57				} //assuming translated lines are those, where key and value are different
58				else {
59					$translated[$matches[1]] = $matches[2];
60					//remove slashes and space to activate translated lines
61					$lang[] = substr($matches[0], 3);
62					//$lang[] = Language::removePhpSlashes($matches[0]);
63				}
64			}
65		}
66		return [
67			'lang' => $lang,
68			'translated' => $translated,
69			'untranslated' => $untranslated,
70		];
71	}
72}
73