websemantics / lcss2php

A straightforward library that extracts variable declarations from multiple Less / Scss sources and returns a PHP associative array.
MIT License
3 stars 0 forks source link

Issue with locale #3

Closed stijntilleman closed 7 years ago

stijntilleman commented 7 years ago

In a multilingual site with the locale "nl_NL" which indicates the use of "," instead of "." as comma delimiter for numeric values there's an issue with compiled css

$some-var: 1.2em;
...

font-size: $some-var;

is compiled as

font-size: 1, 2 em;

which is wrong

A solution could be to add the same locale reset to the getEnvVariables function in ScssCompiler and LessCompilser like

  # from \Websemantics\Lcss2php\Compiler\ScssCompiler
  public function getEnvVariables($code, $ignore = []){
        $vars = [];

        $locale = setlocale(LC_NUMERIC, 0);
        setlocale(LC_NUMERIC, 'C');

        $this->compile($code);

        foreach ($this->rootEnv->store as $name => $value) {
            if(!in_array(is_object($value) ? $value->type : $value[0], $ignore)){
                $vars[str_replace('_', '-', $name)] = $this->compileValue($value);
            }
        }

        setlocale(LC_NUMERIC, $locale);

        return $vars;
    }