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 { | |
518fa0ee | 7 | |
00be9182 | 8 | public function run() { |
5e434adf ARW |
9 | $this->generateInstallLangs(); |
10 | $this->generateSchemaStructure(); | |
11 | } | |
12 | ||
00be9182 | 13 | public function generateInstallLangs() { |
5e434adf ARW |
14 | // CRM-7161: generate install/langs.php from the languages template |
15 | // grep it for enabled languages and create a 'xx_YY' => 'Language name' $langs mapping | |
be2fb01f | 16 | $matches = []; |
5e434adf | 17 | 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); |
be2fb01f | 18 | $langs = []; |
5e434adf ARW |
19 | for ($i = 0; $i < count($matches[0]); $i++) { |
20 | $langs[$matches[1][$i]] = $matches[2][$i]; | |
21 | } | |
2aa397bc | 22 | file_put_contents('../install/langs.php', "<?php \$langs = " . var_export($langs, TRUE) . ";"); |
5e434adf ARW |
23 | } |
24 | ||
00be9182 | 25 | public function generateSchemaStructure() { |
5e434adf | 26 | echo "Generating CRM_Core_I18n_SchemaStructure...\n"; |
be2fb01f CW |
27 | $columns = []; |
28 | $indices = []; | |
29 | $widgets = []; | |
5e434adf ARW |
30 | foreach ($this->tables as $table) { |
31 | if ($table['localizable']) { | |
be2fb01f CW |
32 | $columns[$table['name']] = []; |
33 | $widgets[$table['name']] = []; | |
5e434adf ARW |
34 | } |
35 | else { | |
36 | continue; | |
37 | } | |
38 | foreach ($table['fields'] as $field) { | |
b2f1ab29 SL |
39 | $required = $field['required'] ? ' NOT NULL' : ''; |
40 | $default = $field['default'] ? ' DEFAULT ' . $field['default'] : ''; | |
41 | $comment = $field['comment'] ? " COMMENT '" . $field['comment'] . "'" : ''; | |
5e434adf | 42 | if ($field['localizable']) { |
b2f1ab29 | 43 | $columns[$table['name']][$field['name']] = $field['sqlType'] . $required . $default . $comment; |
313df5ee | 44 | $widgets[$table['name']][$field['name']] = $field['widget']; |
5e434adf ARW |
45 | } |
46 | } | |
47 | if (isset($table['index'])) { | |
48 | foreach ($table['index'] as $index) { | |
49 | if ($index['localizable']) { | |
50 | $indices[$table['name']][$index['name']] = $index; | |
51 | } | |
52 | } | |
53 | } | |
54 | } | |
55 | ||
3eb2aab1 | 56 | $template = new CRM_Core_CodeGen_Util_Template('php', FALSE); |
5e434adf ARW |
57 | |
58 | $template->assign('columns', $columns); | |
59 | $template->assign('indices', $indices); | |
313df5ee | 60 | $template->assign('widgets', $widgets); |
5e434adf ARW |
61 | |
62 | $template->run('schema_structure.tpl', $this->config->phpCodePath . "/CRM/Core/I18n/SchemaStructure.php"); | |
63 | } | |
96025800 | 64 | |
5e434adf | 65 | } |