basz / SlmLocale

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

Add helper function to get the supported locales excluding mappings #101

Open Erikvv opened 6 years ago

Erikvv commented 6 years ago

I've been using the mappings feature and found I needed this helper function often enough that it might be worthwhile to add.

Maybe it's also nice to include this option in LocaleMenu

coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.2%) to 82.552% when pulling 40af6708874abb016a428aac1d5b49876de08cf1 on Erikvv:feature/main-locales into 2a8a0a66eced2cdddd60462ef62aa3df62002653 on basz:master.

svycka commented 6 years ago

not sure about this. Why do you need this?

Erikvv commented 6 years ago

I use this to show a dropdown of locales to select. I will store it in the database and then later use it in jobs to determine which language to send an e-mail or generate a PDF for that particular user.

It makes no sense to show mapped locales in this dropdown, they would be duplicates and using them would break the application as they are not supported.

The mapped locales are only used for Accept-Language headers they aren't visible anywhere else. This was always the intention. See discussion https://github.com/basz/SlmLocale/issues/42

IMHO mapped locale's should not have to be included in Detector::supported in order to work. I misinterpreted the original PR believing that it would work that way (https://github.com/basz/SlmLocale/pull/87)

TLDR; Instead of this feature I should fix it so that you can have mapped-from locales which are not present in the "supported" array. Agreed @svycka?

The mapping feature itself is still necessary I see no way around that. The added complexity is unfortunate but seems necessary.

svycka commented 6 years ago

for dropdown we have https://github.com/basz/SlmLocale/blob/master/src/SlmLocale/View/Helper/LocaleMenu.php this view helper with use supported locales can't you use this? Or does this return wrong locales? Maybe then we should fix this helper?

Erikvv commented 6 years ago

The view helper returns the wrong locales also.

My config is currently like so (shortened example):

return [
    'slm_locale' => [
        'supported' => [
            'de_DE',
            // will be mapped:
            'de_AT',
        ],
        'mappings' => [
            'de_AT' => 'de_DE',
        ]
    ],
];

I want it to be like this but this doesn't work:

return [
    'slm_locale' => [
        'supported' => [
            'de_DE',
        ],
        'mappings' => [
            'de_AT' => 'de_DE',
        ]
    ],
];

If I fix that then I don't need this PR. Understand?

svycka commented 6 years ago

okay now I understand your pain :) then fixing this would be better or maybe add an option to localeMenu helper to include or skip mapped locales? @basz what do you think?