/** * {@inheritdoc} */ public function prepare($connection = null) { if (!is_null($connection)) { $this->connection = $connection; $this->prepared = true; } $tables = $this->getTablesOf($this->connection); $run = new ScriptBuilder(['indent' => 4, 'padding' => 8]); foreach ($tables as $key => $value) { if (in_array($value['table_name'], self::$ignoring)) { continue; } $destination = $this->dictionary->translate($table['table_name']); $records = $this->getDataOf($value['table_name']); $clause = new ScriptBuilder(['indent' => 4, 'padding' => 12]); foreach ($records as $record) { $clause->append('[')->lineBreak()->indent(); foreach ($record as $column => $data) { $clause->append($this->parse($column, $data, $this->dictionary->getColumnsOf($table['table_name'])))->lineBreak(); } if ($this->hasRecords($records, 1)) { $clause->unindent()->append('],')->lineBreak(); } else { $clause->unindent()->append(']')->lineBreak(); } } if ($this->hasRecords($records)) { $run->append('DB::table("' . $destination . '")->insert([')->lineBreak()->append($clause->build(), false)->lineBreak()->append(']);')->lineBreak()->lineBreak(); } } $this->records = $run; return $this; }
/** * @param $string * @return null */ public static function translate($string) { if (is_null(self::$dico) && ENV == MicroMuffin::ENV_PROD) { return null; } else { echo self::$dico->translate($string); } }
/** * {@inheritdoc} */ public function render() { $up = new ScriptBuilder(['padding' => 8]); $down = new ScriptBuilder(['padding' => 8]); if (!is_null($this->schema) && count($this->schema)) { foreach ($this->schema as $name => $values) { if (in_array($name, self::$ignoring)) { continue; } $up->append('/** Table: ' . $this->dictionary->translate($name) . ' */')->lineBreak()->append('{$values["up"]}', false)->lineBreak(); $down->append('{$values["down"]}', false)->lineBreak(); } } $template = file_get_contents(__DIR__ . '/templates/migration.txt'); $template = str_replace('{{name}}', 'Create' . camel_case($this->connection) . 'Database', $template); $template = str_replace('{{up}}', $up->build(), $template); $template = str_replace('{{down}}', $down->build(), $template); return $template; }
public function translateStrings(&$arr) { if (CLI) { echo "Translation language package strings:" . PHP_EOL; } //$orgArr = $arr; //$this->loadPack($orgArr); require_once 'Dictionary.php'; $lang = $this->lang; $locale = explode("_", $lang); $target_lang = strtolower($locale[0]); $dictionary = new Dictionary('en', $target_lang); if ($this->systemOnly == false) { foreach (array("Module", "Theme") as $mainKey) { if (!isset($arr[$mainKey])) { continue; } foreach ($arr[$mainKey] as $key => $value) { $module_name = strtolower($key); foreach ($arr[$mainKey][$key] as $section => $value) { $str_count = count($arr[$mainKey][$key][$section]); $i = 0; foreach ($arr[$mainKey][$key][$section] as $str_key => $str_value) { $i++; $str_value_translated = $dictionary->translate($str_value); if ($str_value_translated) { $arr[$mainKey][$key][$section][$str_key] = $str_value_translated; if (CLI) { if ($target_lang == 'zh') { $str_value_translated = iconv("UTF-8", "GB2312", $str_value_translated); } echo " {$key}: (" . sprintf('%0' . strlen($str_count) . 'd', $i) . "/{$str_count}) Translation string : {$str_value} => {$str_value_translated}" . PHP_EOL; } } } } } } } //if ($this->module == '*') { if ($this->systemOnly) { //load system.ini if (CLI) { echo "Translation System strings:" . PHP_EOL; } $module_name = "SYSTEM"; $module_filename = OPENBIZ_APP_PATH . DIRECTORY_SEPARATOR . "languages" . DIRECTORY_SEPARATOR . $this->lang . DIRECTORY_SEPARATOR . "system.ini"; if (is_file($module_filename)) { //$strArr = parse_ini_file($module_filename,1); //foreach($strArr as $key=>$value){ foreach ($arr["System"] as $key => $value) { $i = 0; $str_count = count($arr["System"][$key]); foreach ($value as $str_key => $str_value) { $i++; $str_value_translated = $dictionary->translate($str_value); if ($str_value_translated) { $arr["System"][$key][$str_key] = $str_value_translated; if ($target_lang == 'zh') { $str_value_translated = iconv("UTF-8", "GB2312", $str_value_translated); } echo " {$key}: (" . sprintf('%0' . strlen($str_count) . 'd', $i) . "/{$str_count}) Translation string : {$str_value} => {$str_value_translated}" . PHP_EOL; } } } } } if (CLI) { echo PHP_EOL; } // update dictionary file $dictionary->update(); return $arr; }