Merge pull request #14016 from seamuslee001/mailing_group_grant_friend_new_style
[civicrm-core.git] / CRM / Core / CodeGen / I18n.php
CommitLineData
5e434adf
ARW
1<?php
2
3/**
4 * Generate language files and classes
5 */
6class 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
be2fb01f 15 $matches = [];
5e434adf 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);
be2fb01f 17 $langs = [];
5e434adf
ARW
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 25 echo "Generating CRM_Core_I18n_SchemaStructure...\n";
be2fb01f
CW
26 $columns = [];
27 $indices = [];
28 $widgets = [];
5e434adf
ARW
29 foreach ($this->tables as $table) {
30 if ($table['localizable']) {
be2fb01f
CW
31 $columns[$table['name']] = [];
32 $widgets[$table['name']] = [];
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}