Commit | Line | Data |
---|---|---|
5e434adf ARW |
1 | <?php |
2 | ||
3 | /** | |
4 | * Generate language files and classes | |
5 | */ | |
6 | class CRM_Core_CodeGen_I18n extends CRM_Core_CodeGen_BaseTask { | |
00be9182 | 7 | public function run() { |
5e434adf ARW |
8 | $this->generateInstallLangs(); |
9 | $this->generateSchemaStructure(); | |
10 | } | |
11 | ||
00be9182 | 12 | public function generateInstallLangs() { |
5e434adf ARW |
13 | // CRM-7161: generate install/langs.php from the languages template |
14 | // grep it for enabled languages and create a 'xx_YY' => 'Language name' $langs mapping | |
15 | $matches = array(); | |
16 | preg_match_all('/, 1, \'([a-z][a-z]_[A-Z][A-Z])\', \'..\', \{localize\}\'\{ts escape="sql"\}(.+)\{\/ts\}\'\{\/localize\}, /', file_get_contents('templates/languages.tpl'), $matches); | |
17 | $langs = array(); | |
18 | for ($i = 0; $i < count($matches[0]); $i++) { | |
19 | $langs[$matches[1][$i]] = $matches[2][$i]; | |
20 | } | |
2aa397bc | 21 | file_put_contents('../install/langs.php', "<?php \$langs = " . var_export($langs, TRUE) . ";"); |
5e434adf ARW |
22 | } |
23 | ||
00be9182 | 24 | public function generateSchemaStructure() { |
5e434adf ARW |
25 | echo "Generating CRM_Core_I18n_SchemaStructure...\n"; |
26 | $columns = array(); | |
27 | $indices = array(); | |
313df5ee | 28 | $widgets = array(); |
5e434adf ARW |
29 | foreach ($this->tables as $table) { |
30 | if ($table['localizable']) { | |
31 | $columns[$table['name']] = array(); | |
313df5ee | 32 | $widgets[$table['name']] = array(); |
5e434adf ARW |
33 | } |
34 | else { | |
35 | continue; | |
36 | } | |
37 | foreach ($table['fields'] as $field) { | |
38 | if ($field['localizable']) { | |
39 | $columns[$table['name']][$field['name']] = $field['sqlType']; | |
313df5ee | 40 | $widgets[$table['name']][$field['name']] = $field['widget']; |
5e434adf ARW |
41 | } |
42 | } | |
43 | if (isset($table['index'])) { | |
44 | foreach ($table['index'] as $index) { | |
45 | if ($index['localizable']) { | |
46 | $indices[$table['name']][$index['name']] = $index; | |
47 | } | |
48 | } | |
49 | } | |
50 | } | |
51 | ||
52 | $template = new CRM_Core_CodeGen_Util_Template('php'); | |
53 | ||
54 | $template->assign('columns', $columns); | |
55 | $template->assign('indices', $indices); | |
313df5ee | 56 | $template->assign('widgets', $widgets); |
5e434adf ARW |
57 | |
58 | $template->run('schema_structure.tpl', $this->config->phpCodePath . "/CRM/Core/I18n/SchemaStructure.php"); | |
59 | } | |
96025800 | 60 | |
5e434adf | 61 | } |