load->helper('directory'); // for simplicity, we don't use views $this->output('h1', 'Open Source Point of Sale - Language file checking and validation'); // determine the language file path if ( ! is_dir($this->lang_path) ) { $this->lang_path = APPPATH . $this->lang_path; if ( ! is_dir($this->lang_path) ) { $this->output('h2', 'Defined language path "'.$this->lang_path.'" not found!', TRUE); exit; } } // fetch the languages directory map $languages = directory_map( $this->lang_path, TRUE ); // is our reference language present? if ( ! in_array($this->reference, $languages ) ) { $this->output('h2', 'Reference language "'.$this->reference.'" not found!', TRUE); exit; } // load the list of language files for the reference language $references = directory_map( $this->lang_path . '/' . $this->reference, TRUE ); // now process the list foreach( $references as $reference ) { // skip non-language files in the language directory if ( strpos($reference, '_lang'.EXT) === FALSE ) { continue; } // process it $this->output('h2', 'Processing '.$this->reference . ' » ' .$reference); // load the language file include $this->lang_path . '/' . $this->reference . '/' . $reference; // did the file contain any language strings? if ( empty($lang) ) { // language file was empty or not properly defined $this->output('h3', 'Language file doesn\'t contain any language strings. Skipping file!', TRUE); continue; } // store the loaded language strings $lang_ref = $lang; unset($lang); // now loop through the available languages foreach ( $languages as $language ) { // skip the reference language if ( $language == $this->reference ) { continue; } // language file to check $file = $this->lang_path . '/' . $language . '/' . $reference; // check if the language file exists for this language if ( ! file_exists( $file ) ) { // file not found $this->output('h3', 'Language file doesn\'t exist for the language '.$language.'!', TRUE); } else { // load the file to compare include $file; // did the file contain any language strings? if ( empty($lang) ) { // language file was empty or not properly defined $this->output('h3', 'Language file for the language '.$language.' doesn\'t contain any language strings!', TRUE); } else { // start comparing $this->output('h3', 'Comparing with the '.$language.' version:'); // assume all goes well $failures = 0; // start comparing language keys foreach( $lang_ref as $key => $value ) { if ( ! isset($lang[$key]) ) { // report the missing key $this->output('', 'Missing language string "'.$key.'"', TRUE); // increment the failure counter $failures++; } } if ( ! $failures ) { $this->output('', 'The two language files have matching strings.'); } } // make sure the lang array is deleted before the next check if ( isset($lang) ) { unset($lang); } } } } $this->output('h2', 'Language file checking and validation completed'); } // ----------------------------------------------------------------- private function output($type = '', $line = '', $highlight = FALSE) { switch ($type) { case 'h1': $html = "