rainlab / location-plugin

Adds location based features, such as Country and State.
Other
21 stars 44 forks source link

RainLab\Location\Models\Country::getNameList not translated #70

Closed mauserrifle closed 5 years ago

mauserrifle commented 5 years ago

Because of the lists method on QueryBuilder, the names are not translated using Country::getNameList. I temporarly fixed it using the code below. But I think there could be a better solution I overlook.

    public static function getNameList()
    {
        if (self::$nameList) {
            return self::$nameList;
        }

        $countries = self::isEnabled()->orderBy('is_pinned', 'desc')->orderBy('name', 'asc')->get();

        $countriesById = [];
        foreach ($countries as $country) {
            $countriesById[$country->id] = trim($country->name);
        }

        // Sort again due translations
        asort($countriesById);

        return self::$nameList = $countriesById;
    }
alxy commented 5 years ago

@mauserrifle Does it work if you call lists() on the Collection rather than on the query builder, i.e. self::isEnabled()->orderBy('is_pinned', 'desc')->orderBy('name', 'asc')->get()->lists('name', 'id');

That would be much nicer.

w20k commented 5 years ago

Closing as it has been over a month since any activity on this occurred and we are trying to figure out what issues are still relevant. If this is still something that you would like to see through to fruition please respond and we can get the ball rolling.

iboved commented 4 years ago

Why this bug still is not fixed? The fix from @alxy works fine.

LukeTowers commented 4 years ago

@iboved feel free to submit a PR.