Merge pull request #12978 from mattwire/datepicker_manageevent_search
[civicrm-core.git] / CRM / Core / CodeGen / I18n.php
1 <?php
2
3 /**
4 * Generate language files and classes
5 */
6 class CRM_Core_CodeGen_I18n extends CRM_Core_CodeGen_BaseTask {
7 public function run() {
8 $this->generateInstallLangs();
9 $this->generateSchemaStructure();
10 }
11
12 public function generateInstallLangs() {
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 }
21 file_put_contents('../install/langs.php', "<?php \$langs = " . var_export($langs, TRUE) . ";");
22 }
23
24 public function generateSchemaStructure() {
25 echo "Generating CRM_Core_I18n_SchemaStructure...\n";
26 $columns = array();
27 $indices = array();
28 $widgets = array();
29 foreach ($this->tables as $table) {
30 if ($table['localizable']) {
31 $columns[$table['name']] = array();
32 $widgets[$table['name']] = array();
33 }
34 else {
35 continue;
36 }
37 foreach ($table['fields'] as $field) {
38 if ($field['localizable']) {
39 $columns[$table['name']][$field['name']] = $field['sqlType'];
40 $widgets[$table['name']][$field['name']] = $field['widget'];
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);
56 $template->assign('widgets', $widgets);
57
58 $template->run('schema_structure.tpl', $this->config->phpCodePath . "/CRM/Core/I18n/SchemaStructure.php");
59 }
60
61 }