Skip to content

Commit

Permalink
Fix setLanguage method wrong implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
diazoxide committed Sep 11, 2019
1 parent 04a228a commit b5e8919
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions src/component/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ private function getType()
return isset($this->types[$content_type]) ? $this->types[$content_type] : 'html';
}

/**
* @return bool
*/
private function prepareDestination()
{
$dest = '/'.trim($_SERVER['REQUEST_URI'], '/');
$dest = '/' . trim($_SERVER['REQUEST_URI'], '/');
$dest = URL::removeQueryVars($dest, $this->context->languages->language_query_key);
$dest = urldecode($dest);
$this->setDestination($dest);
Expand All @@ -71,12 +74,7 @@ private function prepareDestination()
private function prepareSourceUrl()
{

$this->setTranslation(
$this
->context
->translation
->setLanguages([$this->getLanguage()])
);
$this->setTranslation($this->context->translation);

/*
* If current language is default language
Expand All @@ -91,19 +89,26 @@ private function prepareSourceUrl()
return false;
}



/*
* Set source origin URL
* */
$this->setSourceUrl($this->getSourceUrlFromTranslate(
$this->getDestination(),
$this->getLanguage())
);

/*
* Set current url all translations
* */
$this->setUrlTranslations(
$this->context->translation
$this->getTranslation()
->setLanguages($this->context->languages->getAcceptLanguages())
->url->translate([$this->getSourceUrl()])[$this->getSourceUrl()]
);

/**
* Setting source url as @REQUEST_URI
* */
$_SERVER['REQUEST_URI'] = $this->source_url;

if ($this->getDestination() != null && $this->getSourceUrl() == null) {
Expand Down Expand Up @@ -186,10 +191,6 @@ public function start()
'source_url'=>$this->getSourceUrl()
]);*/

/*
* Manipulating REQUEST_URI
* */

ob_start();

/**
Expand Down Expand Up @@ -222,7 +223,8 @@ public function start()
->translate([$content])[$content][$this->getLanguage()];

if ($type == "html") {
$content = preg_replace('/(<head.*?>)/is', '$1' . PHP_EOL . $this->getHeadAdditionalTags(), $content,
$content = preg_replace('/(<head.*?>)/is', '$1' . PHP_EOL . $this->getHeadAdditionalTags(),
$content,
1);
}

Expand All @@ -237,20 +239,23 @@ public function start()
/**
* @return string
*/
private function getHeadAdditionalTags(){
private function getHeadAdditionalTags()
{
$tags = '';
$tags.=$this->getXHRManipulationJavaScriptTag();
$tags.=$this->getAlternateLinkTags();
$tags .= $this->getXHRManipulationJavaScriptTag();
$tags .= $this->getAlternateLinkTags();
return $tags;
}

private function getAlternateLinkTags(){
private function getAlternateLinkTags()
{
$tags = '';
foreach($this->getUrlTranslations() as $language => $translate){
$tags.= sprintf("<link rel=\"alternate\" hreflang=\"%s\" href=\"%s\">", $language, $translate);
foreach ($this->getUrlTranslations() as $language => $translate) {
$tags .= sprintf("<link rel=\"alternate\" hreflang=\"%s\" href=\"%s\">", $language, $translate);
}
return $tags;
}

/**
* @return string
*/
Expand Down

0 comments on commit b5e8919

Please sign in to comment.