blob: 3a1e5c75820b18738971f1c492e3aed77f411ca0 [file] [log] [blame]
gobrien1a8e02f2008-01-30 01:46:26 +00001<?php
2/*******************************************************************************
3 * Copyright (c) 2008 Eclipse Foundation and others.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Eclipse Foundation - Initial API and implementation
droy133e7462008-05-13 17:37:24 +000011 * Motoki MORT mori-m@mxa.nes.nec.co.jp - patch, bug 227366
kitlo58d8a5a2008-09-24 20:08:44 +000012 * Kit Lo (IBM) - patch, bug 217339, generate pseudo translations language packs
13 *******************************************************************************/
gobrien1a8e02f2008-01-30 01:46:26 +000014
15/*
kitlo58d8a5a2008-09-24 20:08:44 +000016 * Documentation: http://wiki.eclipse.org/Babel_/_Server_Tool_Specification#Outputs
gobrien1a8e02f2008-01-30 01:46:26 +000017 */
gobrienb854dcb2008-01-30 18:50:45 +000018
droyb6e25c72008-07-18 13:01:13 +000019ob_start();
kitlo58d8a5a2008-09-24 20:08:44 +000020ini_set("memory_limit", "12M");
21define("BABEL_BASE_DIR", "../../");
kitlo399df202008-09-30 15:32:25 +000022require(BABEL_BASE_DIR."html/common_functions.php");
23require(BABEL_BASE_DIR."classes/system/dbconnection.class.php");
24$dbc = new DBConnection();
25$dbh = $dbc->connect();
droyb6e25c72008-07-18 13:01:13 +000026
kitlo58d8a5a2008-09-24 20:08:44 +000027$work_dir = "/home/babel-working/";
28if (!($ini = @parse_ini_file(BABEL_BASE_DIR."classes/base.conf"))) {
gobrienb854dcb2008-01-30 18:50:45 +000029 errorLog("Failed to find/read database conf file - aborting.");
30 exitTo("error.php?errNo=101300","error: 101300 - database conf can not be found");
31}
gobrienb854dcb2008-01-30 18:50:45 +000032$context = $ini['context'];
gobrienb854dcb2008-01-30 18:50:45 +000033
kitlo58d8a5a2008-09-24 20:08:44 +000034$work_context_dir = $work_dir.$context."/";
35$tmp_dir = $work_context_dir."tmp/";
36$output_dir = $work_context_dir."output/";
37$source_files_dir = "source_files_for_generate/";
gobrienb854dcb2008-01-30 18:50:45 +000038
gobrien1a8e02f2008-01-30 01:46:26 +000039$leader = ". . ";
kitlo58d8a5a2008-09-24 20:08:44 +000040$timestamp = date("Ymdhis");
gobrien1a8e02f2008-01-30 01:46:26 +000041
kitlo58d8a5a2008-09-24 20:08:44 +000042exec("rm -rf $work_dir*");
43exec("mkdir $work_context_dir");
44exec("mkdir $output_dir");
droy0b08d292008-05-28 15:18:11 +000045
kitlo58d8a5a2008-09-24 20:08:44 +000046echo "Generating update site\n";
47$train_result = mysql_query('SELECT DISTINCT train_id FROM release_train_projects');
48while (($train_row = mysql_fetch_assoc($train_result)) != null) {
49 $train_id = $train_row['train_id'];
50 $train_version = "3.4.0";
51 if (strcmp($train_id, "europa") == 0) {
52 $train_version = "3.3.0";
droy0b08d292008-05-28 15:18:11 +000053 }
kitlo58d8a5a2008-09-24 20:08:44 +000054 $site_xml = '';
55
56 $output_dir_for_train = $output_dir . $train_row['train_id'] . "/";
57 exec("mkdir $output_dir_for_train");
58 exec("mkdir ${output_dir_for_train}features/");
59 exec("mkdir ${output_dir_for_train}plugins/");
60
kitlo58d8a5a2008-09-24 20:08:44 +000061 $language_result = mysql_query('SELECT * FROM languages WHERE languages.is_active');
droy0b08d292008-05-28 15:18:11 +000062 while( ($language_row = mysql_fetch_assoc($language_result)) != null ) {
63 $language_name = $language_row['name'];
kitlo58d8a5a2008-09-24 20:08:44 +000064 $language_iso = $language_row['iso_code'];
65 $language_locale = $language_row['locale'];
66 $language_id = $language_row['language_id'];
67 if (strcmp($language_iso, "en") == 0) {
68 $language_iso = "en_AA";
69 $language_name = "Pseudo Translations";
70 }
71 if ($language_locale != null) {
droy0b08d292008-05-28 15:18:11 +000072 $language_name = $language_locale . " " . $language_name;
gobrien1a8e02f2008-01-30 01:46:26 +000073 }
kitlo58d8a5a2008-09-24 20:08:44 +000074 echo "${leader}Generating language pack for $train_id - $language_name ($language_iso) (language_id=" . $language_id . ")\n";
75
gobrien1a8e02f2008-01-30 01:46:26 +000076 /*
droy0b08d292008-05-28 15:18:11 +000077 * Determine which plug-ins need to be in this language pack.
gobrien1a8e02f2008-01-30 01:46:26 +000078 */
kitlo58d8a5a2008-09-24 20:08:44 +000079 if (strcmp($language_iso, "en_AA") == 0) {
80 $file_result = mysql_query("SELECT DISTINCT f.project_id, f.version, f.file_id, f.name
81 FROM files AS f
82 INNER JOIN strings AS s ON f.file_id = s.file_id
83 INNER JOIN release_train_projects as v ON (f.project_id = v.project_id AND f.version = v.version)
84 WHERE f.is_active
85 AND v.train_id = '" . $train_row['train_id'] . "'");
86
87 $index_file = fopen("${output_dir}BabelPseudoTranslationsIndex.html", "w");
88 fwrite($index_file, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\n<html>\n<head>\n<title>Babel Pseudo Translations Index</title>\n" .
89 "<meta http-equiv=Content-Type content=\"text/html; charset=UTF-8\">\n</head>\n<body>\n\t<h1>Babel Pseudo Translations Index</h1>\n" .
90 "\t<h2>" . $train_version . ".v" . $timestamp . "</h2>\n\t<ul>\n");
91 } else {
92 $file_result = mysql_query("SELECT DISTINCT f.project_id, f.version, f.file_id, f.name
93 FROM files AS f
94 INNER JOIN strings AS s ON f.file_id = s.file_id
95 INNER JOIN translations AS t ON (s.string_id = t.string_id AND t.is_active)
96 INNER JOIN release_train_projects as v ON (f.project_id = v.project_id AND f.version = v.version)
97 WHERE t.language_id = " . $language_id . "
98 AND f.is_active
99 AND v.train_id = '" . $train_row['train_id'] . "'");
100 }
101
droy0b08d292008-05-28 15:18:11 +0000102 $plugins = array();
kitlo58d8a5a2008-09-24 20:08:44 +0000103 while (($file_row = mysql_fetch_assoc($file_result)) != null) {
104 # save original filename
105 $file_row['origname'] = $file_row['name'];
106
droy02c430a2008-06-02 19:42:08 +0000107 # strip useless CVS structure before the plugin name (bug 221675 c14):
108 $pattern = '/^([a-zA-Z0-9\/_-])+\/([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)(.*)\.properties$/i';
109 $replace = '${2}.${3}${4}.properties';
110 $file_row['name'] = preg_replace($pattern, $replace, $file_row['name']);
kitlo58d8a5a2008-09-24 20:08:44 +0000111
droy02c430a2008-06-02 19:42:08 +0000112 # strip source folder (bug 221675) (org.eclipse.plugin/source_folder/org/eclipse/plugin)
113 $pattern = '/^([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)\.([a-zA-Z0-9\._-]+)(.*)\/(\1)([\.\/])(\2)([\.\/])(.*)\.properties$/i';
114 $replace = '${1}.${2}.${3}/${5}${6}${7}${8}${9}.properties';
droy0b08d292008-05-28 15:18:11 +0000115 $file_row['name'] = preg_replace($pattern, $replace, $file_row['name']);
kitlo58d8a5a2008-09-24 20:08:44 +0000116
117 if (preg_match("/^([a-zA-Z0-9\.]+)\/(.*)$/", $file_row['name'], $matches)) {
droy0b08d292008-05-28 15:18:11 +0000118 $file_row['subname'] = $matches[2];
119 $plugins[$matches[1]][] = $file_row;
120 } else {
121 echo " WARNING: no plug-in name found in file " . $file_row['file_id'] . " \"" . $file_row['name'] . "\"\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000122 }
droy0b08d292008-05-28 15:18:11 +0000123 }
kitlo58d8a5a2008-09-24 20:08:44 +0000124
droy0b08d292008-05-28 15:18:11 +0000125 /*
126 * Generate one plug-in fragment for each plug-in
127 */
kitlo58d8a5a2008-09-24 20:08:44 +0000128 foreach ($plugins as $plugin_name => $plugin_row) {
129 echo "${leader}${leader}Generating plug-in fragment $plugin_name\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000130 /*
droy0b08d292008-05-28 15:18:11 +0000131 * Clean and create the temporary directory
gobrien1a8e02f2008-01-30 01:46:26 +0000132 */
kitlo58d8a5a2008-09-24 20:08:44 +0000133 if (file_exists($tmp_dir)) {
134 exec("rm -rf $tmp_dir; mkdir $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000135 } else {
kitlo58d8a5a2008-09-24 20:08:44 +0000136 exec("mkdir $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000137 }
kitlo58d8a5a2008-09-24 20:08:44 +0000138
gobrien1a8e02f2008-01-30 01:46:26 +0000139 /*
droy0b08d292008-05-28 15:18:11 +0000140 * Generate each *.properties file
gobrien1a8e02f2008-01-30 01:46:26 +0000141 */
droy0b08d292008-05-28 15:18:11 +0000142 foreach ($plugin_row as $properties_file) {
143 /*
144 * Convert the filename to *_lang.properties, e.g., foo_fr.properties
145 */
146 $filename = $properties_file['subname'];
kitlo58d8a5a2008-09-24 20:08:44 +0000147 if (preg_match( "/^(.*)\.properties$/", $filename, $matches)) {
droy0b08d292008-05-28 15:18:11 +0000148 $filename = $matches[1] . '_' . $language_iso . '.properties';
gobrien1a8e02f2008-01-30 01:46:26 +0000149 }
kitlo58d8a5a2008-09-24 20:08:44 +0000150 echo "${leader}${leader}${leader}Generating properties file $filename (file_id=" . $properties_file['file_id'] . ")\n";
droy0b08d292008-05-28 15:18:11 +0000151 /*
152 * Create any needed sub-directories
153 */
kitlo58d8a5a2008-09-24 20:08:44 +0000154 $fullpath = $tmp_dir . $filename;
155 preg_match("/^((.*)\/)?(.+?)$/", $fullpath, $matches);
156 exec("mkdir -p \"" . $matches[1] . "\"");
droy0b08d292008-05-28 15:18:11 +0000157 /*
158 * Start writing to the file
159 */
kitlo58d8a5a2008-09-24 20:08:44 +0000160 $outp = fopen($fullpath, "w");
161 fwrite($outp, "# Copyright by many contributors; see http://babel.eclipse.org/\n");
162 if (strcmp($language_iso, "en_AA") == 0) {
163 $sql = "SELECT string_id, name, value FROM strings WHERE file_id = " . $properties_file['file_id'] .
164 " AND is_active AND non_translatable = 0";
165 $strings_result = mysql_query($sql);
166 while (($strings_row = mysql_fetch_assoc($strings_result)) != null) {
167 fwrite($outp, $strings_row['name'] . "=");
168 fwrite($outp, $properties_file['project_id'] . $strings_row['string_id'] . ":" . $strings_row['value']);
169 fwrite($outp, "\n");
170
171 $value = htmlspecialchars($strings_row['value']);
172 if (strlen($value) > 100) {
173 $value = substr($value, 0, 100) . " ...";
174 }
175 fwrite($index_file, "\t\t<li><a href=\"http://babel.eclipse.org/babel/translate.php?project=" . $properties_file['project_id'] .
176 "&version=" . $properties_file['version'] . "&file=" . $properties_file['origname'] . "&string=" . $strings_row['name'] .
177 "\">" . $properties_file['project_id'] . $strings_row['string_id'] . "</a>&nbsp;" . $value . "</li>\n");
178 }
179 } else {
180 $sql = "SELECT
181 strings.name AS 'key',
182 strings.value AS orig,
183 translations.value AS trans
droy0b08d292008-05-28 15:18:11 +0000184 FROM strings, translations
185 WHERE strings.string_id = translations.string_id
kitlo58d8a5a2008-09-24 20:08:44 +0000186 AND translations.language_id = " . $language_id . "
droy0b08d292008-05-28 15:18:11 +0000187 AND strings.file_id = " . $properties_file['file_id'] . "
kitlo58d8a5a2008-09-24 20:08:44 +0000188 AND translations.is_active";
189 $strings_result = mysql_query($sql);
190 while (($strings_row = mysql_fetch_assoc($strings_result)) != null) {
191 fwrite($outp, $strings_row['key'] . "=");
192 #echo "${leader1S}${leaderS}${leaderS}${leaderS}" . $strings_row['key'] . "=";
193 if ($strings_row['trans']) {
194 # json_encode returns the string with quotes fore and aft. Need to strip them.
195 # $tr_string = preg_replace('/^"(.*)"$/', '${1}', json_encode($strings_row['trans']));
196 # $tr_string = str_replace('\\\\', '\\', $tr_string);
197 $tr_string = toescapedunicode($strings_row['trans']);
198 fwrite($outp, $tr_string);
199 # echo $strings_row['trans'];
200 } else {
201 fwrite($outp, $strings_row['orig']);
202 }
203 fwrite($outp, "\n");
droy0b08d292008-05-28 15:18:11 +0000204 }
droy0b08d292008-05-28 15:18:11 +0000205 }
206 /*
207 * Finish the properties file
208 */
kitlo58d8a5a2008-09-24 20:08:44 +0000209 fclose($outp);
210 echo "${leader}${leader}${leader}Completed properties file $filename\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000211 }
212 /*
droy0b08d292008-05-28 15:18:11 +0000213 * Copy in the various legal files
gobrien1a8e02f2008-01-30 01:46:26 +0000214 */
kitlo58d8a5a2008-09-24 20:08:44 +0000215 exec("cp ${source_files_dir}about.html ${tmp_dir}");
droy0b08d292008-05-28 15:18:11 +0000216 /*
217 * Generate the META-INF/MANIFEST.MF file
218 */
219 $parent_plugin_id = $plugin_name;
220 $fragment_id = "${parent_plugin_id}.nl_$language_iso";
kitlo58d8a5a2008-09-24 20:08:44 +0000221 $fragment_version = $train_version . ".v" . $timestamp;
droy0b08d292008-05-28 15:18:11 +0000222 $fragment_filename = $fragment_id . "_" . $fragment_version . ".jar";
kitlo58d8a5a2008-09-24 20:08:44 +0000223
droy0b08d292008-05-28 15:18:11 +0000224 $plugins[$plugin_name]['id'] = $fragment_id;
225 $plugins[$plugin_name]['version'] = $fragment_version;
kitlo58d8a5a2008-09-24 20:08:44 +0000226
227 exec("mkdir $tmp_dir/META-INF" );
228 $outp = fopen("$tmp_dir/META-INF/MANIFEST.MF", "w");
229 fwrite($outp, "Manifest-Version: 1.0\n");
230 fwrite($outp, "Bundle-Name: $parent_plugin_id $language_name NLS Support\n");
231 fwrite($outp, "Bundle-SymbolicName: $fragment_id ;singleton=true\n");
232 fwrite($outp, "Bundle-Version: $fragment_version\n");
233 fwrite($outp, "Bundle-Vendor: Eclipse Foundation Inc.\n");
234 fwrite($outp, "Fragment-Host: $parent_plugin_id\n");
235 fclose($outp);
droy0b08d292008-05-28 15:18:11 +0000236 /*
237 * Jar up this directory as the fragment plug-in jar
238 */
kitlo58d8a5a2008-09-24 20:08:44 +0000239 system("cd $tmp_dir; jar cfM ${output_dir_for_train}plugins/$fragment_filename .");
240 echo "${leader}${leader}Completed plug-in fragment $plugin_name\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000241 }
kitlo58d8a5a2008-09-24 20:08:44 +0000242 /*
243 * Clean and create the temporary directory
244 */
245 if (file_exists($tmp_dir)) {
246 exec("rm -rf $tmp_dir; mkdir $tmp_dir");
247 } else {
248 exec("mkdir $tmp_dir");
249 }
gobrien1a8e02f2008-01-30 01:46:26 +0000250 /*
droy0b08d292008-05-28 15:18:11 +0000251 * Create the feature.xml
252 *
253 * TODO <url><update label=... url=... and <url><discovery label=... url=... are not implemented
254 *
kitlo58d8a5a2008-09-24 20:08:44 +0000255 * <url>
256 * <update label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
257 * <discovery label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
droy0b08d292008-05-28 15:18:11 +0000258 * </url>
gobrien1a8e02f2008-01-30 01:46:26 +0000259 */
kitlo58d8a5a2008-09-24 20:08:44 +0000260 $feature_id = "org.eclipse.babel.nls.$language_iso";
261 $feature_version = $train_version . ".v" . $timestamp;
262 $feature_filename = $feature_id . "_" . $feature_version . ".jar";
263
264 $outp = fopen("$tmp_dir/feature.xml", "w");
265 fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
266<feature
267 id=\"$feature_id\"
268 label=\"Eclipse Language Pack for $language_name\"
269 image=\"eclipse_update_120.jpg\"
270 provider-name=\"Eclipse Foundation Inc.\"
271 version=\"$feature_version\">
272 <license url=\"license.html\">\n" . htmlspecialchars(file_get_contents("${source_files_dir}license.txt")) . "\t</license>
273 <description>Translations in $language_name for all Eclipse Projects</description>" );
274 foreach ($plugins as $plugin_name => $plugin_row) {
275 fwrite($outp, '
276 <plugin fragment="true" id="' .
277 $plugin_row['id'] . '" unpack="false" version="' .
278 $plugin_row['version'] . '"/>');
droy0b08d292008-05-28 15:18:11 +0000279 }
kitlo58d8a5a2008-09-24 20:08:44 +0000280 fwrite($outp, '
281</feature>');
282 fclose($outp);
283 /*
284 * Copy in the various legal files
285 */
286 exec("cp ${source_files_dir}about.html ${tmp_dir}");
287 exec("cp ${source_files_dir}license.html ${tmp_dir}");
288 exec("cp ${source_files_dir}epl-v10.html ${tmp_dir}");
289 exec("cp ${source_files_dir}eclipse_update_120.jpg ${tmp_dir}");
290 /*
291 * Copy in the Babel Pseudo Translations Index file
292 */
293 if (strcmp($language_iso, "en_AA") == 0) {
294 fwrite($index_file, "\t</ul>\n</body>\n</html>");
295 fclose($index_file);
296 exec("cp ${output_dir}BabelPseudoTranslationsIndex.html ${tmp_dir}");
297 exec("rm ${output_dir}BabelPseudoTranslationsIndex.html");
298 }
299 /*
300 * Jar up this directory as the feature jar
301 */
302 system("cd $tmp_dir; jar cfM ${output_dir_for_train}features/$feature_filename .");
gobrien1a8e02f2008-01-30 01:46:26 +0000303 /*
droy0b08d292008-05-28 15:18:11 +0000304 * Register this feature with the site.xml
gobrien1a8e02f2008-01-30 01:46:26 +0000305 */
kitlo58d8a5a2008-09-24 20:08:44 +0000306 $site_xml .= " <feature url=\"features/$feature_filename\" id=\"$feature_id\" version=\"$feature_version\">
307 <category name=\"Language Packs\"/>
308 </feature>\n";
309 echo "${leader}Completed language pack for $language_name ($language_iso)\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000310 }
gobrien1a8e02f2008-01-30 01:46:26 +0000311 /*
droy0b08d292008-05-28 15:18:11 +0000312 * <site mirrorsURL=... implemented in the weekly build process by sed'ing <site>
gobrien1a8e02f2008-01-30 01:46:26 +0000313 */
kitlo58d8a5a2008-09-24 20:08:44 +0000314 $outp = fopen("${output_dir_for_train}site.xml", "w");
315 fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
316<site>
317 <description url=\"http://babel.eclipse.org/\">
318 This update site contains user-contributed translations of the strings in all Eclipse projects.
319 Please see the http://babel.eclipse.org/ Babel project web pages for a full how-to-use explanation of
320 these translations as well as how you can contribute to the translations of this and future versions of Eclipse.
321 </description>
322 <category-def name=\"Language Packs\" label=\"Language Packs\">
323 <description>Language packs for all Eclipse projects</description>
324 </category-def>\n");
325 fwrite($outp, $site_xml);
326 fwrite($outp, "</site>");
327 fclose($outp);
gobrien1a8e02f2008-01-30 01:46:26 +0000328}
gobrien1a8e02f2008-01-30 01:46:26 +0000329echo "Completed generating update site\n";
330
331/*
kitlo58d8a5a2008-09-24 20:08:44 +0000332 2. what happens if the translation feature includes plug-in fragments for
333 plug-ins that are not in the current image?
334 does it load correctly and ignore those fragments? if so, good
335 A: warnings appear in the run-time error log
336 does it fail to load? if so, then we need to generate different features, perhaps
337 one feature for each plug or else we need to know more about the project
338 distro structure to know which plug-ins to put in each feature
339 what happens if those plug-ins are later added - does it load the strings now?
340 A: probably not
341 3. need to handle different versions of each feature/plugin/platform; generate different
342 language packs for each
343 */
gobrien1a8e02f2008-01-30 01:46:26 +0000344
kitlo58d8a5a2008-09-24 20:08:44 +0000345$alloutput = fopen($output_dir."langpack_output_".date("m_d_Y"), "w");
346fwrite($alloutput,ob_get_contents());
kitlo399df202008-09-30 15:32:25 +0000347?>