Skip to content

Commit

Permalink
Backwards-compatibility fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisrollins65 committed May 7, 2016
1 parent d1e8d95 commit 8c5522a
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 11 deletions.
31 changes: 31 additions & 0 deletions upload/admin/language/english/module/cr_translate_mate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
$_['heading_title'] = 'Translate Mate';
$_['text_module'] = 'Modules';
$_['text_success'] = 'Success: Changes saved to the language file(s): %s';
$_['text_edit'] = 'Edit the Translate Mate Module';
$_['text_main_lang_file'] = 'Main language file';
$_['text_page'] = 'Page';
$_['text_key'] = 'Key';
$_['text_all_pages'] = 'All pages';
$_['text_search_keys'] = 'Search keys';
$_['text_search_text'] = 'Search for text';
$_['text_not_translated_only'] = 'Show only non-translated';
$_['text_not_translated'] = 'Not translated';
$_['text_help_errors'] = '<strong><i class="fa fa-exclamation-circle"></i> Errors:</strong> Check the <strong>README</strong> FIRST, then <a href="%s">open an issue on Github</a> (preferred) or <a href="%s">leave a comment on Opencart\'s page</a>.';
$_['text_help_hotkeys'] = '<strong><i class="fa fa-info-circle"></i> Hotkeys:</strong> <code>Cntl+Enter</code> to save and <code>Esc</code> to cancel.';
$_['text_help_caution'] = '<strong><i class="fa fa-exclamation-triangle"></i> Caution!</strong> <u>Don\'t</u> translate HTML code (basically anything in angle brackets <code>< ></code>) nor placeholders (things like <code>%s</code>, <code>%d</code>, etc).';
$_['text_no_texts_found'] = 'No texts found.';
$_['text_loading_please_wait'] = 'Loading texts. Please wait.';
$_['text_load_more'] = 'Load more';
$_['text_save_translation'] = 'Save translation';
$_['text_cancel'] = 'Cancel';
$_['tab_frontend'] = 'Frontend';
$_['tab_backend'] = 'Backend';
$_['entry_status'] = 'Status';
$_['error_permission'] = 'Warning: You do not have permission to access/modify the Translate Mate module!';
$_['error_missing'] = 'Unable to save translation. The following required fields are missing:';
$_['error_post'] = 'Unable to save translation. It must be made via a POST request.';
$_['error_write_permission'] = 'Unable to write to the file \'%s\'. Ensure that Opencart has write permissions for this file and it\'s language directory (for example: try 750, 755, or 775).';
$_['error_unexpected'] = 'Unexpected results loaded (Please notify the developer)';
$_['error_error'] = 'Error';
?>
52 changes: 45 additions & 7 deletions upload/admin/model/module/cr_translate_mate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,22 @@
*/
class ModelModuleCrTranslateMate extends Model {

public function install() {
// for the moment, no installation action is needed
protected $model; // instance of the model - used to avoid OpenCart's proxy system

public function __construct($registry)
{
$this->model = new CrTranslateMateModel($registry);
parent::__construct($registry);
}

public function uninstall() {
// for the moment, no uninstallation action is needed
public function install()
{
$this->model->install();
}

public function uninstall()
{
$this->model->uninstall();
}

/**
Expand All @@ -22,7 +32,7 @@ public function uninstall() {
*/
public function getInstance()
{
return new CrTranslateMateModel($this->registry);
return $this->model;
}
}

Expand Down Expand Up @@ -58,6 +68,28 @@ public function __construct($registry)
parent::__construct($registry);
}

public function install()
{
// Language folder names changed in OpenCart 2.2.0.0, so make sure the language strings for this extension
// are in the correct directory and remove the directory that isn't needed.
if ( version_compare(VERSION, '2.2.0.0', '<')
&& file_exists($this->dirs['admin'].'en-gb/module/cr_translate_mate.php') ) {
unlink($this->dirs['admin'].'en-gb/module/cr_translate_mate.php');
rmdir($this->dirs['admin'].'en-gb/module');
rmdir($this->dirs['admin'].'en-gb');
}
else if ( file_exists($this->dirs['admin'].'english/module/cr_translate_mate.php') ) {
unlink($this->dirs['admin'].'english/module/cr_translate_mate.php');
rmdir($this->dirs['admin'].'english/module');
rmdir($this->dirs['admin'].'english');
}
}

public function uninstall()
{
// for the moment, no uninstallation action is needed
}

// update the language file specified in the input
public function saveTranslation($input)
{
Expand Down Expand Up @@ -106,8 +138,14 @@ protected function getFilePath($dirKey, $file, $lang) {
public function langs() {
if ( !empty($this->langs) ) { return $this->langs; }
$this->load->model('localisation/language');
$this->langs = $this->model_localisation_language->getLanguages();
// ensure the directory is specified for each language for OpenCart 2.2.0.0 and later
if ( version_compare(VERSION, '2.2.0.0', '>=') )
foreach ($this->langs as $key=>$value) {
$this->langs[$key]['directory'] = $this->langs[$key]['code'];
}

return $this->langs = $this->model_localisation_language->getLanguages();
return $this->langs;
}

// extracts the language name from the language arrays
Expand Down Expand Up @@ -330,5 +368,5 @@ public function adminPath(){
public function getLastLoadedFile(){
return $this->lastLoadedFile;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ $(document).ready(function() {
translation : $textarea.val(),
dirKey : $('input[name=interface]:checked').val(), // admin or catalog
}
console.log(params);

$.post(crtm.url+'save', params)
.done(function(data){
Expand Down
6 changes: 3 additions & 3 deletions upload/admin/view/template/module/cr_translate_mate_table.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<td class="pageCol"><?php e($page == '_main_lang_file' ? $text_main_lang_file : $page); ?></td>
<td class="keyCol"><?php e($key); ?></td>
<?php foreach ( $languages as $l ) { ?>
<td class="translationCol" data-lang="<?php e($l['code']); ?>">
<td class="translationCol" data-lang="<?php e($l['directory']); ?>">
<div class="transDiv"><?php
echo (isset($translations[$l['code']]) && $translations[$l['code']] != '') ?
hs($translations[$l['code']]) : '<span class="notTranslatedSpan text-danger">'.h($text_not_translated).'</span>';
echo (isset($translations[$l['directory']]) && $translations[$l['directory']] != '') ?
hs($translations[$l['directory']]) : '<span class="notTranslatedSpan text-danger">'.h($text_not_translated).'</span>';
?></div><!-- end .transDiv -->
</td>
<?php } // end foreach ( $languages as $l ) ?>
Expand Down

0 comments on commit 8c5522a

Please sign in to comment.