/[drupal]/contributions/tricks/po-packager/po-packager.php
ViewVC logotype

Contents of /contributions/tricks/po-packager/po-packager.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Sun Sep 30 18:04:44 2007 UTC (2 years, 1 month ago) by goba
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +2 -2 lines
File MIME type: text/x-php
adapt to windows newlines (sort of)
1 <?php
2 // $Id: po-packager.php,v 1.1 2007/01/14 12:45:14 goba Exp $
3
4 define('LANGUAGE', $argv[1]); // language code
5 define('SOURCE', $argv[2]); // source folder
6 define('TARGET', $argv[3]); // target (temp) folder
7
8 if (!mkdir(TARGET, 0777, TRUE)) {
9 die('Unable to create temporary folder for package generation:' . TEMP);
10 }
11
12 $files = glob(rtrim(SOURCE, '/') .'/*.po');
13
14 foreach ($files as $filepath) {
15 $filename = basename($filepath);
16
17 // Special cases based on file names
18 switch ($filename) {
19
20 // Installer PO file goes to default profile folder
21 case 'installer.po':
22 @mkdir(TARGET . '/profiles/default/translations', 0777, TRUE);
23 copy($filepath, TARGET . '/profiles/default/translations/' . LANGUAGE . '.po');
24 continue 2;
25 break;
26
27 // General include files and the global strings go to system module
28 case 'common-inc.po':
29 case 'file-inc.po':
30 case 'form-inc.po':
31 case 'theme-inc.po':
32 case 'unicode-inc.po':
33 case 'general.po':
34 @mkdir(TARGET . '/modules/system/translations', 0777, TRUE);
35 copy(
36 $filepath,
37 TARGET . '/modules/system/translations/' . preg_replace('!^(.+)\\.po$!', '\\1.' . LANGUAGE . '.po', $filename)
38 );
39 continue 2;
40 break;
41
42 // Locale include file goes to locale module
43 case 'locale-inc.po':
44 @mkdir(TARGET . '/modules/locale/translations/', 0777, TRUE);
45 copy(
46 $filepath,
47 TARGET . '/modules/locale/translations/' . preg_replace('!^(.+)\\.po$!', '\\1.' . LANGUAGE . '.po', $filename)
48 );
49 continue 2;
50 break;
51 }
52
53 // Read in third line of file
54 $f = fopen($filepath, 'r');
55 $first = fgets($f);
56 fgets($f);
57 $third = fgets($f);
58 fclose($f);
59
60 // Trying to match first or third line for target folder, eg.
61 // # Hungarian translation of Drupal (modules/aggregator/aggregator.module)
62 $folder = FALSE;
63 if (preg_match("!\\((.+)\\)!", $first, $match)) {
64 $folder = dirname($match[1]);
65 }
66 elseif (preg_match("!\\((.+)\\)!", $third, $match)) {
67 $folder = dirname($match[1]);
68 }
69
70 if ($folder !== FALSE) {
71 @mkdir(TARGET . '/' . $folder . '/translations', 0777, TRUE);
72 copy(
73 $filepath,
74 TARGET . '/' . $folder . '/translations/' . preg_replace('!^(.+)\\.po$!', '\\1.' . LANGUAGE . '.po', $filename)
75 );
76 }
77 else {
78 print "ERROR: unable to identify where $filename should be placed!\n";
79 }
80 }

  ViewVC Help
Powered by ViewVC 1.1.2