setLocale() public method

Change the locale of the Fixer.
public setLocale ( string $locale )
$locale string An IETF language tag
Ejemplo 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);
 }
Ejemplo 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));
    }
Ejemplo 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));
    }
Ejemplo n.º 4
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));
    }
Ejemplo n.º 5
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));
    }
Ejemplo n.º 6
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testBadLocale()
 {
     $fixer = new Fixer(array('Ellipsis'));
     $fixer->setLocale(false);
 }