4 * Generate language files and classes
6 class CRM_Core_CodeGen_I18n
extends CRM_Core_CodeGen_BaseTask
{
7 public function run() {
8 $this->generateInstallLangs();
9 $this->generateSchemaStructure();
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
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);
18 for ($i = 0; $i < count($matches[0]); $i++
) {
19 $langs[$matches[1][$i]] = $matches[2][$i];
21 file_put_contents('../install/langs.php', "<?php \$langs = " . var_export($langs, TRUE) . ";");
24 public function generateSchemaStructure() {
25 echo "Generating CRM_Core_I18n_SchemaStructure...\n";
29 foreach ($this->tables
as $table) {
30 if ($table['localizable']) {
31 $columns[$table['name']] = array();
32 $widgets[$table['name']] = array();
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'];
43 if (isset($table['index'])) {
44 foreach ($table['index'] as $index) {
45 if ($index['localizable']) {
46 $indices[$table['name']][$index['name']] = $index;
52 $template = new CRM_Core_CodeGen_Util_Template('php');
54 $template->assign('columns', $columns);
55 $template->assign('indices', $indices);
56 $template->assign('widgets', $widgets);
58 $template->run('schema_structure.tpl', $this->config
->phpCodePath
. "/CRM/Core/I18n/SchemaStructure.php");