Exemplo n.º 1
0
 public function __construct()
 {
     // get locale
     $this->locale = Config::get('letterpress.locale');
     // defaults
     if (Config::get('letterpress.microtypography.useDefaults')) {
         $this->fixers = Config::get('jolitypo.defaults');
         // locale additions
         $localeKey = sprintf('jolitypo.%s', $this->locale);
         if (Config::has($localeKey)) {
             $this->fixers = array_merge($this->fixers, Config::get($localeKey));
         }
     }
     // hyphenation
     if (Config::get('letterpress.microtypography.enableHyphenation')) {
         $this->fixers[] = 'Hyphen';
     }
     // user additions
     $this->fixers = array_merge($this->fixers, Config::get('letterpress.microtypography.additionalFixers'));
     if (count($this->fixers) === 0) {
         throw new LetterpressException('Typography fixing requires setting up fixers.');
     }
     $this->fixer = new Fixer($this->fixers);
     $this->fixer->setLocale($this->locale);
 }
Exemplo n.º 2
0
    public function testHtmlHeart()
    {
        $fixed = <<<HTML
<p>We &lt;3&nbsp;web.</p>
HTML;
        $to_fix = <<<HTML
<p>We &lt;3 web.</p>
HTML;
        $fixer = new Fixer($this->en_fixers);
        $fixer->setLocale('en');
        $this->assertInstanceOf('JoliTypo\\Fixer', $fixer);
        $this->assertEquals($fixed, $fixer->fix($to_fix));
    }
Exemplo n.º 3
0
    public function testEncodingMess()
    {
        $fixer = new Fixer($this->fr_fixers);
        $fixer->setLocale('fr');
        $this->assertInstanceOf('JoliTypo\\Fixer', $fixer);
        $fixed = <<<HTML
&Ccedil;a s&rsquo;ar&shy;r&ecirc;te l&agrave;&#8239;!
HTML;
        $to_fix = <<<HTML
Ça s'arrête là !
HTML;
        $this->assertEquals($fixed, $fixer->fix($to_fix));
    }
Exemplo n.º 4
0
 /**
  * Transform fr_FR to fr to fit the list of supported locales.
  *
  * @param $locale
  *
  * @return mixed
  */
 protected function fixLocale($locale)
 {
     if (in_array($locale, $this->supportedLocales)) {
         return $locale;
     }
     if (($short = Fixer::getLanguageFromLocale($locale)) !== $locale) {
         if (in_array($short, $this->supportedLocales)) {
             return $short;
         }
     }
     // If no better locale found...
     return $locale;
 }
Exemplo n.º 5
0
    /**
     * @see https://github.com/jolicode/JoliTypo/issues/16
     */
    public function testNoBreakingSpaceInsideGoodQuotes()
    {
        $fixer = new Fixer($this->fr_fixers);
        $fixer->setLocale('fr');
        $this->assertInstanceOf('JoliTypo\\Fixer', $fixer);
        $fixed = <<<HTML
&laquo;&nbsp;test&nbsp;&raquo; et &laquo;&nbsp;test&nbsp;&raquo; sont dans un bateau.
HTML;
        $to_fix = <<<HTML
« test » et «test» sont dans un bateau.
HTML;
        $this->assertEquals($fixed, $fixer->fix($to_fix));
        $to_fix = <<<HTML
&laquo; test &raquo; et &laquo;test&raquo; sont dans un bateau.
HTML;
        $this->assertEquals($fixed, $fixer->fix($to_fix));
    }
Exemplo n.º 6
0
    /**
     * @see https://github.com/jolicode/JoliTypo/issues/15
     */
    public function testNumericDoesNotBreakOtherFixers()
    {
        $fixer = new Fixer($this->fr_fixers);
        $fixer->setLocale('fr');
        $this->assertInstanceOf('JoliTypo\\Fixer', $fixer);
        $fixed = <<<HTML
2&nbsp;&times;&nbsp;5&nbsp;doit &ecirc;tre corrig&eacute;, et 2&nbsp;h aussi.
HTML;
        $to_fix = <<<HTML
2 x 5 doit être corrigé, et 2 h aussi.
HTML;
        $this->assertEquals($fixed, $fixer->fix($to_fix));
    }
Exemplo n.º 7
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testBadLocale()
 {
     $fixer = new Fixer(array('Ellipsis'));
     $fixer->setLocale(false);
 }
Exemplo n.º 8
0
 /**
  * Default configuration for supported lang.
  *
  * @param string $locale
  */
 public function setLocale($locale)
 {
     // Handle from locale + country
     switch (strtolower($locale)) {
         // “…”
         case 'pt-br':
             $this->opening = Fixer::LDQUO;
             $this->openingSuffix = '';
             $this->closing = Fixer::RDQUO;
             $this->closingPrefix = '';
             return;
     }
     // Handle from locale only
     $short = Fixer::getLanguageFromLocale($locale);
     switch ($short) {
         // « … »
         case 'fr':
             $this->opening = Fixer::LAQUO;
             $this->openingSuffix = Fixer::NO_BREAK_SPACE;
             $this->closing = Fixer::RAQUO;
             $this->closingPrefix = Fixer::NO_BREAK_SPACE;
             break;
             // «…»
         // «…»
         case 'hy':
         case 'az':
         case 'hz':
         case 'eu':
         case 'be':
         case 'ca':
         case 'el':
         case 'it':
         case 'no':
         case 'fa':
         case 'lv':
         case 'pt':
         case 'ru':
         case 'es':
         case 'uk':
             $this->opening = Fixer::LAQUO;
             $this->openingSuffix = '';
             $this->closing = Fixer::RAQUO;
             $this->closingPrefix = '';
             break;
             // „…“
         // „…“
         case 'de':
         case 'ka':
         case 'cs':
         case 'et':
         case 'is':
         case 'lt':
         case 'mk':
         case 'ro':
         case 'sk':
         case 'sl':
         case 'wen':
             $this->opening = Fixer::BDQUO;
             $this->openingSuffix = '';
             $this->closing = Fixer::LDQUO;
             $this->closingPrefix = '';
             break;
             // “…”
         // “…”
         case 'en':
         case 'us':
         case 'gb':
         case 'af':
         case 'ar':
         case 'eo':
         case 'id':
         case 'ga':
         case 'ko':
         case 'br':
         case 'th':
         case 'tr':
         case 'vi':
             $this->opening = Fixer::LDQUO;
             $this->openingSuffix = '';
             $this->closing = Fixer::RDQUO;
             $this->closingPrefix = '';
             break;
             // ”…”
         // ”…”
         case 'fi':
         case 'sv':
         case 'bs':
             $this->opening = Fixer::RDQUO;
             $this->openingSuffix = '';
             $this->closing = Fixer::RDQUO;
             $this->closingPrefix = '';
             break;
     }
 }