/[drupal]/contributions/modules/autolocale/autolocale.install
ViewVC logotype

Contents of /contributions/modules/autolocale/autolocale.install

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


Revision 1.10 - (show annotations) (download) (as text)
Wed May 9 09:14:43 2007 UTC (2 years, 6 months ago) by goba
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +3 -2 lines
File MIME type: text/x-php
adapt autolocale to new installer state system:

 - open a batch if in the finalize state and we have files to parse
 - import files progressively with batch API if in localeimport state
 - advance to 'complete' state if finished (or initially if no file is there to import)
 - also fixed a small SQL glitch in language creation
1 <?php
2 // $Id: autolocale.install,v 1.9 2007/05/06 20:12:58 goba Exp $
3
4 /**
5 * Implementation of hook_install().
6 */
7 function autolocale_install() {
8 // Check whether we run on a live site
9 if (!function_exists('install_main')) {
10 drupal_set_message(t('Now you can <a href="@url">import interface translations</a> automatically', array('@url' => url('admin/build/autolocale'))));
11 }
12 }
13
14 /**
15 * Import all PO files for the given locale.
16 *
17 * @param langcode
18 * The code of the language as used in filenames and in the database
19 */
20 function _autolocale_import_po_files($langcode) {
21 // Try to set time limit to unlimited if host allows that
22 @set_time_limit(0);
23
24 // Get a list of modules turned on plus the autolocale module
25 $result = db_query("SELECT name, filename FROM {system} WHERE status = 1 OR name = 'autolocale'");
26 while ($component = db_fetch_object($result)) {
27 _autolocale_import_po_files_for_component($langcode, $component);
28 }
29 }
30
31 /**
32 * Import all PO files for one component to the given locale.
33 *
34 * @param langcode
35 * The code of the language as used in filenames and in the database
36 * @param component
37 * An object representation of a {system} table row
38 */
39 function _autolocale_po_files_for_component($langcode, $component) {
40 // Although the locale module is turned on this is not included
41 // This is not only used from here, so ensure we have locale.inc included
42 include_once 'includes/locale.inc';
43
44 // PO files under the component folder
45 $podir = dirname($component->filename) . '/po/';
46
47 // Search for filename.langcode.po named files
48 // Could have been done using glob(), but it is disabled on many shared hosts
49 $files = array();
50 if (is_dir($podir) && ($dh = opendir($podir))) {
51 while (($file = readdir($dh)) !== false) {
52 if (preg_match("!^.*\\.$langcode\\.po$!", $file) && is_readable($podir . $file)) {
53 $files[] = $podir . $file;
54 }
55 }
56 closedir($dh);
57 }
58
59 // Add langcode.po file if exists and readable
60 if (is_readable($podir. $langcode .'.po')) {
61 $files[] = $podir . $langcode . '.po';
62 }
63 return $files;
64 }
65
66 /**
67 * Add a language and set is as the default.
68 */
69 function _autolocale_install_language($language) {
70
71 // Only if there is a non-English locale used to install.
72 if (!empty($language) && ($language != 'en')) {
73
74 // Although the locale module is turned on this is not included.
75 include_once 'includes/locale.inc';
76
77 // Add language into database.
78 $langlist = _locale_get_predefined_list();
79 $direction = isset($langlist[$language][2]) ? 1 : 0;
80 $native = isset($langlist[$language][1]) ? $langlist[$language][1] : '';
81 // @todo:
82 // Possibly rework locale_add_language() to be able to silently
83 // add a new language and enable it at the same time, to reuse.
84 db_query("INSERT INTO {languages} (language, name, native, direction, enabled, domain, prefix) VALUES ('%s', '%s', '%s', %d, '%s', '%s', '%s')", $language, $langlist[$language][0], $native, $direction, 1, '', $language);
85
86 // Set default language.
87 variable_set('language_default', (object) array('language' => $language, 'name' => $langlist[$language][0], 'native' => $langlist[$language][1], 'direction' => $direction, 'enabled' => 1, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => $language, 'weight' => 0));
88
89 // Increment count of enabled languages.
90 variable_set('language_count', variable_get('language_count', 1) + 1);
91 }
92 }

  ViewVC Help
Powered by ViewVC 1.1.2