4 * Generate language files and classes
6 class CRM_Core_CodeGen_I18n
extends CRM_Core_CodeGen_BaseTask
{
8 public function run() {
9 $this->generateInstallLangs();
10 $this->generateSchemaStructure();
13 public function generateInstallLangs() {
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
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);
19 for ($i = 0; $i < count($matches[0]); $i++
) {
20 $langs[$matches[1][$i]] = $matches[2][$i];
22 file_put_contents('../install/langs.php', "<?php \$langs = " . var_export($langs, TRUE) . ";");
25 public function generateSchemaStructure() {
26 echo "Generating CRM_Core_I18n_SchemaStructure...\n";
30 foreach ($this->tables
as $table) {
31 if ($table['localizable']) {
32 $columns[$table['name']] = [];
33 $widgets[$table['name']] = [];
38 foreach ($table['fields'] as $field) {
39 $required = $field['required'] ?
' NOT NULL' : '';
40 $default = $field['default'] ?
' DEFAULT ' . $field['default'] : '';
41 $comment = $field['comment'] ?
" COMMENT '" . $field['comment'] . "'" : '';
42 if ($field['localizable']) {
43 $columns[$table['name']][$field['name']] = $field['sqlType'] . $required . $default . $comment;
44 $widgets[$table['name']][$field['name']] = $field['widget'];
47 if (isset($table['index'])) {
48 foreach ($table['index'] as $index) {
49 if ($index['localizable']) {
50 $indices[$table['name']][$index['name']] = $index;
56 $template = new CRM_Core_CodeGen_Util_Template('php', FALSE);
58 $template->assign('columns', $columns);
59 $template->assign('indices', $indices);
60 $template->assign('widgets', $widgets);
62 $template->run('schema_structure.tpl', $this->config
->phpCodePath
. "/CRM/Core/I18n/SchemaStructure.php");