Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Korbeil committed Mar 29, 2019
1 parent 466e4de commit 67b5404
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 67 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
],
"require": {
"php": "^5.5 || ^7.0",
"ext-mbstring": "*",
"php-http/httplug": "^1.0",
"php-http/client-implementation": "^1.0",
"php-http/discovery": "^1.0",
Expand Down
66 changes: 0 additions & 66 deletions src/Service/AbstractTranslator.php

This file was deleted.

48 changes: 47 additions & 1 deletion src/Service/HttpTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
use Http\Discovery\HttpClientDiscovery;
use Http\Discovery\MessageFactoryDiscovery;
use Http\Message\RequestFactory;
use Translation\Translator\TranslatorService;

/**
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
abstract class HttpTranslator extends AbstractTranslator
abstract class HttpTranslator implements TranslatorService
{
/**
* @var HttpClient
Expand Down Expand Up @@ -57,4 +58,49 @@ protected function getRequestFactory()
{
return $this->requestFactory;
}

/**
* {@inheritdoc}
*/
public function translateArray($strings, $from, $to)
{
$array = [];

foreach ($strings as $string) {
$array[] = $this->translate($string, $from, $to);
}

return $array;
}

/**
* @param string $original
* @param string $translationHtmlEncoded
*
* @return string
*/
protected function format($original, $translationHtmlEncoded)
{
$translation = htmlspecialchars_decode($translationHtmlEncoded);

// if capitalized, make sure we also capitalize.
$firstChar = \mb_substr($original, 0, 1);
$originalIsUpper = \mb_strtoupper($firstChar) === $firstChar;

if ($originalIsUpper) {
$first = \mb_strtoupper(\mb_substr($translation, 0, 1));
$translation = $first.\mb_substr($translation, 1);
}

// also check on translated if capitalize and original isn't
$transFirstChar = \mb_substr($translationHtmlEncoded, 0, 1);
$translationIsUpper = \mb_strtoupper($transFirstChar) === $transFirstChar;

if (!$originalIsUpper && $translationIsUpper) {
$first = \mb_strtolower(\mb_substr($translation, 0, 1));
$translation = $first.\mb_substr($translation, 1);
}

return $translation;
}
}

0 comments on commit 67b5404

Please sign in to comment.