blob: 629bd4e6e396e4604904b532ad1e7e2046d36b9f [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", "../../");
gobrienb854dcb2008-01-30 18:50:45 +000022
kitlo58d8a5a2008-09-24 20:08:44 +000023define("USE_PHOENIX", false);
24require(BABEL_BASE_DIR."html/global.php");
droyb6e25c72008-07-18 13:01:13 +000025InitPage("");
26
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
61 # $language_result = mysql_query( 'SELECT * FROM languages WHERE languages.is_active' );
62 $language_result = mysql_query('SELECT * FROM languages WHERE languages.is_active');
droy0b08d292008-05-28 15:18:11 +000063 while( ($language_row = mysql_fetch_assoc($language_result)) != null ) {
64 $language_name = $language_row['name'];
kitlo58d8a5a2008-09-24 20:08:44 +000065 $language_iso = $language_row['iso_code'];
66 $language_locale = $language_row['locale'];
67 $language_id = $language_row['language_id'];
68 if (strcmp($language_iso, "en") == 0) {
69 $language_iso = "en_AA";
70 $language_name = "Pseudo Translations";
71 }
72 if ($language_locale != null) {
droy0b08d292008-05-28 15:18:11 +000073 $language_name = $language_locale . " " . $language_name;
gobrien1a8e02f2008-01-30 01:46:26 +000074 }
kitlo58d8a5a2008-09-24 20:08:44 +000075 echo "${leader}Generating language pack for $train_id - $language_name ($language_iso) (language_id=" . $language_id . ")\n";
76
gobrien1a8e02f2008-01-30 01:46:26 +000077 /*
droy0b08d292008-05-28 15:18:11 +000078 * Determine which plug-ins need to be in this language pack.
gobrien1a8e02f2008-01-30 01:46:26 +000079 */
kitlo58d8a5a2008-09-24 20:08:44 +000080 if (strcmp($language_iso, "en_AA") == 0) {
81 $file_result = mysql_query("SELECT DISTINCT f.project_id, f.version, f.file_id, f.name
82 FROM files AS f
83 INNER JOIN strings AS s ON f.file_id = s.file_id
84 INNER JOIN release_train_projects as v ON (f.project_id = v.project_id AND f.version = v.version)
85 WHERE f.is_active
86 AND v.train_id = '" . $train_row['train_id'] . "'");
87
88 $index_file = fopen("${output_dir}BabelPseudoTranslationsIndex.html", "w");
89 fwrite($index_file, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\n<html>\n<head>\n<title>Babel Pseudo Translations Index</title>\n" .
90 "<meta http-equiv=Content-Type content=\"text/html; charset=UTF-8\">\n</head>\n<body>\n\t<h1>Babel Pseudo Translations Index</h1>\n" .
91 "\t<h2>" . $train_version . ".v" . $timestamp . "</h2>\n\t<ul>\n");
92 } else {
93 $file_result = mysql_query("SELECT DISTINCT f.project_id, f.version, f.file_id, f.name
94 FROM files AS f
95 INNER JOIN strings AS s ON f.file_id = s.file_id
96 INNER JOIN translations AS t ON (s.string_id = t.string_id AND t.is_active)
97 INNER JOIN release_train_projects as v ON (f.project_id = v.project_id AND f.version = v.version)
98 WHERE t.language_id = " . $language_id . "
99 AND f.is_active
100 AND v.train_id = '" . $train_row['train_id'] . "'");
101 }
102
droy0b08d292008-05-28 15:18:11 +0000103 $plugins = array();
kitlo58d8a5a2008-09-24 20:08:44 +0000104 while (($file_row = mysql_fetch_assoc($file_result)) != null) {
105 # save original filename
106 $file_row['origname'] = $file_row['name'];
107
droy02c430a2008-06-02 19:42:08 +0000108 # strip useless CVS structure before the plugin name (bug 221675 c14):
109 $pattern = '/^([a-zA-Z0-9\/_-])+\/([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)(.*)\.properties$/i';
110 $replace = '${2}.${3}${4}.properties';
111 $file_row['name'] = preg_replace($pattern, $replace, $file_row['name']);
kitlo58d8a5a2008-09-24 20:08:44 +0000112
droy02c430a2008-06-02 19:42:08 +0000113 # strip source folder (bug 221675) (org.eclipse.plugin/source_folder/org/eclipse/plugin)
114 $pattern = '/^([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)\.([a-zA-Z0-9\._-]+)(.*)\/(\1)([\.\/])(\2)([\.\/])(.*)\.properties$/i';
115 $replace = '${1}.${2}.${3}/${5}${6}${7}${8}${9}.properties';
droy0b08d292008-05-28 15:18:11 +0000116 $file_row['name'] = preg_replace($pattern, $replace, $file_row['name']);
kitlo58d8a5a2008-09-24 20:08:44 +0000117
118 if (preg_match("/^([a-zA-Z0-9\.]+)\/(.*)$/", $file_row['name'], $matches)) {
droy0b08d292008-05-28 15:18:11 +0000119 $file_row['subname'] = $matches[2];
120 $plugins[$matches[1]][] = $file_row;
121 } else {
122 echo " WARNING: no plug-in name found in file " . $file_row['file_id'] . " \"" . $file_row['name'] . "\"\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000123 }
droy0b08d292008-05-28 15:18:11 +0000124 }
kitlo58d8a5a2008-09-24 20:08:44 +0000125
droy0b08d292008-05-28 15:18:11 +0000126 /*
127 * Generate one plug-in fragment for each plug-in
128 */
kitlo58d8a5a2008-09-24 20:08:44 +0000129 foreach ($plugins as $plugin_name => $plugin_row) {
130 echo "${leader}${leader}Generating plug-in fragment $plugin_name\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000131 /*
droy0b08d292008-05-28 15:18:11 +0000132 * Clean and create the temporary directory
gobrien1a8e02f2008-01-30 01:46:26 +0000133 */
kitlo58d8a5a2008-09-24 20:08:44 +0000134 if (file_exists($tmp_dir)) {
135 exec("rm -rf $tmp_dir; mkdir $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000136 } else {
kitlo58d8a5a2008-09-24 20:08:44 +0000137 exec("mkdir $tmp_dir");
droy0b08d292008-05-28 15:18:11 +0000138 }
kitlo58d8a5a2008-09-24 20:08:44 +0000139
gobrien1a8e02f2008-01-30 01:46:26 +0000140 /*
droy0b08d292008-05-28 15:18:11 +0000141 * Generate each *.properties file
gobrien1a8e02f2008-01-30 01:46:26 +0000142 */
droy0b08d292008-05-28 15:18:11 +0000143 foreach ($plugin_row as $properties_file) {
144 /*
145 * Convert the filename to *_lang.properties, e.g., foo_fr.properties
146 */
147 $filename = $properties_file['subname'];
kitlo58d8a5a2008-09-24 20:08:44 +0000148 if (preg_match( "/^(.*)\.properties$/", $filename, $matches)) {
droy0b08d292008-05-28 15:18:11 +0000149 $filename = $matches[1] . '_' . $language_iso . '.properties';
gobrien1a8e02f2008-01-30 01:46:26 +0000150 }
kitlo58d8a5a2008-09-24 20:08:44 +0000151 echo "${leader}${leader}${leader}Generating properties file $filename (file_id=" . $properties_file['file_id'] . ")\n";
droy0b08d292008-05-28 15:18:11 +0000152 /*
153 * Create any needed sub-directories
154 */
kitlo58d8a5a2008-09-24 20:08:44 +0000155 $fullpath = $tmp_dir . $filename;
156 preg_match("/^((.*)\/)?(.+?)$/", $fullpath, $matches);
157 exec("mkdir -p \"" . $matches[1] . "\"");
droy0b08d292008-05-28 15:18:11 +0000158 /*
159 * Start writing to the file
160 */
kitlo58d8a5a2008-09-24 20:08:44 +0000161 $outp = fopen($fullpath, "w");
162 fwrite($outp, "# Copyright by many contributors; see http://babel.eclipse.org/\n");
163 if (strcmp($language_iso, "en_AA") == 0) {
164 $sql = "SELECT string_id, name, value FROM strings WHERE file_id = " . $properties_file['file_id'] .
165 " AND is_active AND non_translatable = 0";
166 $strings_result = mysql_query($sql);
167 while (($strings_row = mysql_fetch_assoc($strings_result)) != null) {
168 fwrite($outp, $strings_row['name'] . "=");
169 fwrite($outp, $properties_file['project_id'] . $strings_row['string_id'] . ":" . $strings_row['value']);
170 fwrite($outp, "\n");
171
172 $value = htmlspecialchars($strings_row['value']);
173 if (strlen($value) > 100) {
174 $value = substr($value, 0, 100) . " ...";
175 }
176 fwrite($index_file, "\t\t<li><a href=\"http://babel.eclipse.org/babel/translate.php?project=" . $properties_file['project_id'] .
177 "&version=" . $properties_file['version'] . "&file=" . $properties_file['origname'] . "&string=" . $strings_row['name'] .
178 "\">" . $properties_file['project_id'] . $strings_row['string_id'] . "</a>&nbsp;" . $value . "</li>\n");
179 }
180 } else {
181 $sql = "SELECT
182 strings.name AS 'key',
183 strings.value AS orig,
184 translations.value AS trans
droy0b08d292008-05-28 15:18:11 +0000185 FROM strings, translations
186 WHERE strings.string_id = translations.string_id
kitlo58d8a5a2008-09-24 20:08:44 +0000187 AND translations.language_id = " . $language_id . "
droy0b08d292008-05-28 15:18:11 +0000188 AND strings.file_id = " . $properties_file['file_id'] . "
kitlo58d8a5a2008-09-24 20:08:44 +0000189 AND translations.is_active";
190 $strings_result = mysql_query($sql);
191 while (($strings_row = mysql_fetch_assoc($strings_result)) != null) {
192 fwrite($outp, $strings_row['key'] . "=");
193 #echo "${leader1S}${leaderS}${leaderS}${leaderS}" . $strings_row['key'] . "=";
194 if ($strings_row['trans']) {
195 # json_encode returns the string with quotes fore and aft. Need to strip them.
196 # $tr_string = preg_replace('/^"(.*)"$/', '${1}', json_encode($strings_row['trans']));
197 # $tr_string = str_replace('\\\\', '\\', $tr_string);
198 $tr_string = toescapedunicode($strings_row['trans']);
199 fwrite($outp, $tr_string);
200 # echo $strings_row['trans'];
201 } else {
202 fwrite($outp, $strings_row['orig']);
203 }
204 fwrite($outp, "\n");
droy0b08d292008-05-28 15:18:11 +0000205 }
droy0b08d292008-05-28 15:18:11 +0000206 }
207 /*
208 * Finish the properties file
209 */
kitlo58d8a5a2008-09-24 20:08:44 +0000210 fclose($outp);
211 echo "${leader}${leader}${leader}Completed properties file $filename\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000212 }
213 /*
droy0b08d292008-05-28 15:18:11 +0000214 * Copy in the various legal files
gobrien1a8e02f2008-01-30 01:46:26 +0000215 */
kitlo58d8a5a2008-09-24 20:08:44 +0000216 exec("cp ${source_files_dir}about.html ${tmp_dir}");
droy0b08d292008-05-28 15:18:11 +0000217 /*
218 * Generate the META-INF/MANIFEST.MF file
219 */
220 $parent_plugin_id = $plugin_name;
221 $fragment_id = "${parent_plugin_id}.nl_$language_iso";
kitlo58d8a5a2008-09-24 20:08:44 +0000222 $fragment_version = $train_version . ".v" . $timestamp;
droy0b08d292008-05-28 15:18:11 +0000223 $fragment_filename = $fragment_id . "_" . $fragment_version . ".jar";
kitlo58d8a5a2008-09-24 20:08:44 +0000224
droy0b08d292008-05-28 15:18:11 +0000225 $plugins[$plugin_name]['id'] = $fragment_id;
226 $plugins[$plugin_name]['version'] = $fragment_version;
kitlo58d8a5a2008-09-24 20:08:44 +0000227
228 exec("mkdir $tmp_dir/META-INF" );
229 $outp = fopen("$tmp_dir/META-INF/MANIFEST.MF", "w");
230 fwrite($outp, "Manifest-Version: 1.0\n");
231 fwrite($outp, "Bundle-Name: $parent_plugin_id $language_name NLS Support\n");
232 fwrite($outp, "Bundle-SymbolicName: $fragment_id ;singleton=true\n");
233 fwrite($outp, "Bundle-Version: $fragment_version\n");
234 fwrite($outp, "Bundle-Vendor: Eclipse Foundation Inc.\n");
235 fwrite($outp, "Fragment-Host: $parent_plugin_id\n");
236 fclose($outp);
droy0b08d292008-05-28 15:18:11 +0000237 /*
238 * Jar up this directory as the fragment plug-in jar
239 */
kitlo58d8a5a2008-09-24 20:08:44 +0000240 system("cd $tmp_dir; jar cfM ${output_dir_for_train}plugins/$fragment_filename .");
241 echo "${leader}${leader}Completed plug-in fragment $plugin_name\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000242 }
kitlo58d8a5a2008-09-24 20:08:44 +0000243 /*
244 * Clean and create the temporary directory
245 */
246 if (file_exists($tmp_dir)) {
247 exec("rm -rf $tmp_dir; mkdir $tmp_dir");
248 } else {
249 exec("mkdir $tmp_dir");
250 }
gobrien1a8e02f2008-01-30 01:46:26 +0000251 /*
droy0b08d292008-05-28 15:18:11 +0000252 * Create the feature.xml
253 *
254 * TODO <url><update label=... url=... and <url><discovery label=... url=... are not implemented
255 *
kitlo58d8a5a2008-09-24 20:08:44 +0000256 * <url>
257 * <update label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
258 * <discovery label="%updateSiteName" url="http://update.eclipse.org/updates/3.2" />
droy0b08d292008-05-28 15:18:11 +0000259 * </url>
gobrien1a8e02f2008-01-30 01:46:26 +0000260 */
kitlo58d8a5a2008-09-24 20:08:44 +0000261 $feature_id = "org.eclipse.babel.nls.$language_iso";
262 $feature_version = $train_version . ".v" . $timestamp;
263 $feature_filename = $feature_id . "_" . $feature_version . ".jar";
264
265 $outp = fopen("$tmp_dir/feature.xml", "w");
266 fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
267<feature
268 id=\"$feature_id\"
269 label=\"Eclipse Language Pack for $language_name\"
270 image=\"eclipse_update_120.jpg\"
271 provider-name=\"Eclipse Foundation Inc.\"
272 version=\"$feature_version\">
273 <license url=\"license.html\">\n" . htmlspecialchars(file_get_contents("${source_files_dir}license.txt")) . "\t</license>
274 <description>Translations in $language_name for all Eclipse Projects</description>" );
275 foreach ($plugins as $plugin_name => $plugin_row) {
276 fwrite($outp, '
277 <plugin fragment="true" id="' .
278 $plugin_row['id'] . '" unpack="false" version="' .
279 $plugin_row['version'] . '"/>');
droy0b08d292008-05-28 15:18:11 +0000280 }
kitlo58d8a5a2008-09-24 20:08:44 +0000281 fwrite($outp, '
282</feature>');
283 fclose($outp);
284 /*
285 * Copy in the various legal files
286 */
287 exec("cp ${source_files_dir}about.html ${tmp_dir}");
288 exec("cp ${source_files_dir}license.html ${tmp_dir}");
289 exec("cp ${source_files_dir}epl-v10.html ${tmp_dir}");
290 exec("cp ${source_files_dir}eclipse_update_120.jpg ${tmp_dir}");
291 /*
292 * Copy in the Babel Pseudo Translations Index file
293 */
294 if (strcmp($language_iso, "en_AA") == 0) {
295 fwrite($index_file, "\t</ul>\n</body>\n</html>");
296 fclose($index_file);
297 exec("cp ${output_dir}BabelPseudoTranslationsIndex.html ${tmp_dir}");
298 exec("rm ${output_dir}BabelPseudoTranslationsIndex.html");
299 }
300 /*
301 * Jar up this directory as the feature jar
302 */
303 system("cd $tmp_dir; jar cfM ${output_dir_for_train}features/$feature_filename .");
gobrien1a8e02f2008-01-30 01:46:26 +0000304 /*
droy0b08d292008-05-28 15:18:11 +0000305 * Register this feature with the site.xml
gobrien1a8e02f2008-01-30 01:46:26 +0000306 */
kitlo58d8a5a2008-09-24 20:08:44 +0000307 $site_xml .= " <feature url=\"features/$feature_filename\" id=\"$feature_id\" version=\"$feature_version\">
308 <category name=\"Language Packs\"/>
309 </feature>\n";
310 echo "${leader}Completed language pack for $language_name ($language_iso)\n";
gobrien1a8e02f2008-01-30 01:46:26 +0000311 }
gobrien1a8e02f2008-01-30 01:46:26 +0000312 /*
droy0b08d292008-05-28 15:18:11 +0000313 * <site mirrorsURL=... implemented in the weekly build process by sed'ing <site>
gobrien1a8e02f2008-01-30 01:46:26 +0000314 */
kitlo58d8a5a2008-09-24 20:08:44 +0000315 $outp = fopen("${output_dir_for_train}site.xml", "w");
316 fwrite($outp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
317<site>
318 <description url=\"http://babel.eclipse.org/\">
319 This update site contains user-contributed translations of the strings in all Eclipse projects.
320 Please see the http://babel.eclipse.org/ Babel project web pages for a full how-to-use explanation of
321 these translations as well as how you can contribute to the translations of this and future versions of Eclipse.
322 </description>
323 <category-def name=\"Language Packs\" label=\"Language Packs\">
324 <description>Language packs for all Eclipse projects</description>
325 </category-def>\n");
326 fwrite($outp, $site_xml);
327 fwrite($outp, "</site>");
328 fclose($outp);
gobrien1a8e02f2008-01-30 01:46:26 +0000329}
gobrien1a8e02f2008-01-30 01:46:26 +0000330echo "Completed generating update site\n";
331
332/*
kitlo58d8a5a2008-09-24 20:08:44 +0000333 2. what happens if the translation feature includes plug-in fragments for
334 plug-ins that are not in the current image?
335 does it load correctly and ignore those fragments? if so, good
336 A: warnings appear in the run-time error log
337 does it fail to load? if so, then we need to generate different features, perhaps
338 one feature for each plug or else we need to know more about the project
339 distro structure to know which plug-ins to put in each feature
340 what happens if those plug-ins are later added - does it load the strings now?
341 A: probably not
342 3. need to handle different versions of each feature/plugin/platform; generate different
343 language packs for each
344 */
gobrien1a8e02f2008-01-30 01:46:26 +0000345
kitlo58d8a5a2008-09-24 20:08:44 +0000346$alloutput = fopen($output_dir."langpack_output_".date("m_d_Y"), "w");
347fwrite($alloutput,ob_get_contents());
348?>