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); }
public function testHtmlHeart() { $fixed = <<<HTML <p>We <3 web.</p> HTML; $to_fix = <<<HTML <p>We <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)); }
public function testEncodingMess() { $fixer = new Fixer($this->fr_fixers); $fixer->setLocale('fr'); $this->assertInstanceOf('JoliTypo\\Fixer', $fixer); $fixed = <<<HTML Ça s’ar­rête là ! HTML; $to_fix = <<<HTML Ça s'arrête là ! HTML; $this->assertEquals($fixed, $fixer->fix($to_fix)); }
/** * 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; }
/** * @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 « test » et « test » 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 « test » et «test» sont dans un bateau. HTML; $this->assertEquals($fixed, $fixer->fix($to_fix)); }
/** * @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 × 5 doit être corrigé, et 2 h aussi. HTML; $to_fix = <<<HTML 2 x 5 doit être corrigé, et 2 h aussi. HTML; $this->assertEquals($fixed, $fixer->fix($to_fix)); }
/** * @expectedException \InvalidArgumentException */ public function testBadLocale() { $fixer = new Fixer(array('Ellipsis')); $fixer->setLocale(false); }
/** * 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; } }