basz / SlmLocale

Auto detection of locale through different strategies for Zend Framework 2
Other
68 stars 34 forks source link

Issues with host strategy #45

Closed glen-84 closed 10 years ago

glen-84 commented 10 years ago
Warning: Invalid argument supplied for foreach() in SlmLocale\Strategy\HostStrategy.php on line 166

Use:

protected $aliases = array();

Then, tries to redirect to "http://domain./de/" because there is no alias (which shouldn't be required).

This code:

    if (!$this->redirectToCanonical()) {
        $locale = $this->getAliasForLocale($locale);
    }

Should be something like this (untested):

    if (!$this->redirectToCanonical() && ($alias = array_search($locale, $this->aliases, true)) !== false) {
        $locale = $alias;
    }

getAliasForLocale() is not required unless I'm missing something.

juriansluiman commented 10 years ago

The point is that the locale is de-DE or en-US (so always the full locale and not the language part). There simply doesn't exist a TLD which is a locale. Even if you have .de or .nl, those are the language part so you have to make a mapping from the language to the locale.

Again here, it's good to have proper docs to explain this, as it doesn't seem logical.