1<?php
2/* Allows a new language po file to be created */
3
4/* Steve Kitchen/Kaill */
5
6//$PageSecurity = 15;
7
8include ('includes/session.php');
9
10/* Was the Cancel button pressed the last time through ? */
11
12if (isset($_POST['cancel'])) {
13
14	header ('Location:' . $RootPath . '/Z_poAdmin.php');
15	exit;
16
17}
18
19$Title = _('New Language');// _('Add a New Language to the System')
20$ViewTopic = "SpecialUtilities";
21$BookMark = "Z_poAddLanguage";// Anchor's id in the manual's html document.
22include('includes/header.php');
23echo '<p class="page_title_text"><img alt="" src="' . $RootPath . '/css/' . $Theme .
24		'/images/maintenance.png" title="' .
25		_('Add a New Language to the System') . '" />' . ' ' .
26		_('Add a New Language to the System') . '</p>';
27
28/* Your webserver user MUST have read/write access to here,	otherwise you'll be wasting your time */
29
30echo '<br />&nbsp;<a href="' . $RootPath . '/Z_poAdmin.php">' . _('Back to the translation menu') . '</a>';
31echo '<br /><br />&nbsp;' . _('Utility to create a new language file');
32echo '<br />&nbsp;' . _('Current language is') . ' ' . $_SESSION['Language'];
33
34$DefaultLanguage = 'en_GB';// The default language is English-United Kingdom (British English).
35$PathToDefault = './locale/' . $DefaultLanguage . '.utf8/LC_MESSAGES/messages.pot';
36
37if (isset($_POST['submit']) AND isset($_POST['NewLanguage'])) {
38
39	if(mb_strlen($_POST['NewLanguage'])<5
40		OR mb_strlen($_POST['NewLanguage'])>5
41		OR mb_substr($_POST['NewLanguage'],2,1)!='_'){
42
43		prnMsg(_('Languages must be in the format of a two character country code an underscore _ and a two character language code in upper case'),'error');
44	} else {
45
46		/*Make sure the language characters are in upper case*/
47
48		$_POST['NewLanguage'] = mb_substr($_POST['NewLanguage'],0,3) . mb_strtoupper(mb_substr($_POST['NewLanguage'],3,2));
49
50		echo '<div class="centre">';
51		echo '<br />';
52		echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">';
53		echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
54
55
56		/* check for directory existence */
57
58		if (!file_exists('./locale/' . $_POST['NewLanguage'])) {
59			prnMsg (_('Attempting to create the new language file') . '.....<br />', 'info', ' ');
60			$Result = mkdir('./locale/' . $_POST['NewLanguage'] . '.utf8');
61			$Result = mkdir('./locale/' . $_POST['NewLanguage'] . '.utf8/LC_MESSAGES');
62		} else {
63			prnMsg(_('This language cannot be added because it already exists!'),'error');
64  			echo '</form>';
65	  		echo '</div>';
66			include('includes/footer.php');
67			exit;
68		}
69
70		$PathToNewLanguage = './locale/' . $_POST['NewLanguage'] . '.utf8/LC_MESSAGES/messages.po';
71		$Result = copy($PathToDefault, $PathToNewLanguage);
72
73		prnMsg (_('Done. You should now change to your newly created language from the user settings link above. Then you can edit the new language file header and use the language module editor to translate the system strings'), 'info');
74
75		echo '</form>';
76		echo '</div>';
77		include('includes/footer.php');
78		exit;
79	}
80
81}
82
83
84echo '<div class="centre">';
85echo '<br />';
86prnMsg (_('This utility will create a new language and a new language translation file for it from the system default') . '<br /><br />' .
87		_('If the language already exists then you cannot recreate it'), 'info', _('PLEASE NOTE'));
88echo '<br /></div>';
89echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">';
90echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
91
92echo '<table><tr>';
93echo '<td>' . _('Full code of the new language in the format en_US') . '</td>';
94echo '<td><input type="text" size="5" name="NewLanguage" />';
95echo '</td></tr></table>';
96
97echo '<br /><input type="submit" name="submit" value="' . _('Proceed') . '" />&nbsp;&nbsp;&nbsp;&nbsp;';
98echo '</form>';
99
100include('includes/footer.php');
101
102?>
103