-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing the code style to be PSR-1 & PSR-2 compliance, this change will make the code more readable.
- Loading branch information
1 parent
4dd18b6
commit dbec284
Showing
11 changed files
with
429 additions
and
610 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,118 +1,120 @@ | ||
<?php | ||
|
||
namespace charlemagne\Shuwa; | ||
namespace charlemagne\Shuwa; | ||
|
||
use charlemagne\Shuwa\Shuwa; | ||
use charlemagne\Shuwa\Shuwa; | ||
|
||
class FShuwa extends Shuwa { | ||
class FShuwa extends Shuwa | ||
{ | ||
protected $blacklist; | ||
|
||
protected $blacklist; | ||
|
||
public function __construct($source = 'en', $target = 'it') { | ||
|
||
parent::__construct($source, $target); | ||
$this->blacklist = $this->config['FILE']['BLACKLIST']; | ||
|
||
public function __construct($source = 'en', $target = 'it') | ||
{ | ||
parent::__construct($source, $target); | ||
$this->blacklist = $this->config['FILE']['BLACKLIST']; | ||
} | ||
|
||
// private class services | ||
|
||
private function safeTranslation( $quote ) { | ||
|
||
$targetToken = $this->config['FILE']['TARGET']; | ||
private function safeTranslation($quote) | ||
{ | ||
$targetToken = $this->config['FILE']['TARGET']; | ||
$wordsInQuote = explode(' ', $quote); | ||
$target = null; | ||
foreach ($wordsInQuote as $word) { | ||
if(strpos($word, $targetToken) !== false) { | ||
$target = $word; | ||
} | ||
if (strpos($word, $targetToken) !== false) { | ||
$target = $word; | ||
} | ||
} | ||
$target = substr($target, 1); | ||
$cleanQuote = str_replace($targetToken, '', $quote); | ||
$translatedTarget = $this->translate($target); | ||
$translatedQuote = $this->translate($cleanQuote); | ||
$safeQuote = str_replace($translatedTarget, $targetToken.$target, $translatedQuote); | ||
if(strpos($safeQuote, $targetToken) !== false) return $safeQuote; | ||
if (strpos($safeQuote, $targetToken) !== false) { | ||
return $safeQuote; | ||
} | ||
return $quote; | ||
|
||
} | ||
|
||
|
||
|
||
private function innerTranslate( $file, $key, $value ) { | ||
|
||
if( is_array( $value ) ) { | ||
private function innerTranslate($file, $key, $value) | ||
{ | ||
if (is_array($value)) { | ||
fwrite($file, "'{$key}' => [\n"); | ||
foreach ($value as $subkey => $subvalue) | ||
$this->innerTranslate($file, $subkey, $subvalue); | ||
foreach ($value as $subkey => $subvalue) { | ||
$this->innerTranslate($file, $subkey, $subvalue); | ||
} | ||
fwrite($file, "\n ], \n"); | ||
} else { | ||
if($this->validate($value)) { | ||
$targetToken = $this->config['FILE']['TARGET']; | ||
if($targetToken != -1 && strpos($value, $targetToken) !== false) { | ||
if ($this->validate($value)) { | ||
$targetToken = $this->config['FILE']['TARGET']; | ||
if ($targetToken != -1 && strpos($value, $targetToken) !== false) { | ||
$value = $this->safeTranslation($value, true); | ||
} | ||
else { | ||
} else { | ||
$value = $this->translate($value, true); | ||
} | ||
$value = $this->bind($value); | ||
} | ||
$value = $this->bind($value); | ||
fwrite($file, "'{$key}' => '{$value}', \n"); | ||
} | ||
else { | ||
$value = $this->bind($value); | ||
} else { | ||
$value = $this->bind($value); | ||
fwrite($file, "'{$key}' => '{$value}', \n"); | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
|
||
|
||
public function validate( $quote ) { | ||
|
||
if( ! $this->config['FILE']['VALIDATION'] ) return true; | ||
if( $this->config['FILE']['HTML_INTEGRITY'] && $quote != strip_tags($quote) ) return false; | ||
if( $this->config['FILE']['MANTAIN_SINGLE_WORDS'] && strpos($quote, " ") === false ) return false; | ||
public function validate($quote) | ||
{ | ||
if (! $this->config['FILE']['VALIDATION']) { | ||
return true; | ||
} | ||
if ($this->config['FILE']['HTML_INTEGRITY'] && $quote != strip_tags($quote)) { | ||
return false; | ||
} | ||
if ($this->config['FILE']['MANTAIN_SINGLE_WORDS'] && strpos($quote, " ") === false) { | ||
return false; | ||
} | ||
|
||
foreach ($this->blacklist as $word) | ||
if(strpos($quote, $word) !== false) return false; | ||
foreach ($this->blacklist as $word) { | ||
if (strpos($quote, $word) !== false) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
|
||
} | ||
} | ||
|
||
|
||
|
||
public function bind( $quote ) { | ||
public function bind($quote) | ||
{ | ||
return str_replace("'", "\\'", $quote); | ||
} | ||
|
||
|
||
public function laravelTranslation( $source, $destination ) { | ||
public function laravelTranslation($source, $destination) | ||
{ | ||
$quotes = include($source); | ||
$output = fopen($destination, "w"); | ||
$output = fopen($destination, "w"); | ||
fwrite($output, $this->config['FILE']['HEADER']); | ||
foreach ($quotes as $key => $value) | ||
foreach ($quotes as $key => $value) { | ||
$this->innerTranslate($output, $key, $value); | ||
fwrite($output, $this->config['FILE']['TRAILER'] ); | ||
|
||
} | ||
|
||
} | ||
fwrite($output, $this->config['FILE']['TRAILER']); | ||
} | ||
|
||
|
||
public function codeIgniterTranslation( &$lang ) { | ||
|
||
public function codeIgniterTranslation(&$lang) | ||
{ | ||
foreach ($lang as $key => $value) { | ||
if( $this->validate($value) ) { | ||
$lang[$key] = $this->bind( $this->translate( $value ) ); | ||
if ($this->validate($value)) { | ||
$lang[$key] = $this->bind($this->translate($value)); | ||
} | ||
} | ||
return $lang; | ||
|
||
return $lang; | ||
} | ||
|
||
}; | ||
|
||
|
||
|
||
}; |
Oops, something went wrong.