Twig icon indicating copy to clipboard operation
Twig copied to clipboard

List languages, countries, locales, currencies, timezones

Open seb-jean opened this issue 2 years ago • 2 comments

I think it would be interesting to be able to list with Twig functions the languages, countries, locales, currencies, timezones

For instance, for languages, we will reuse:

$languages = Languages::getNames();
// ('languageCode' => 'languageName')
// => ['ab' => 'Abkhazian', 'ace' => 'Achinese', ...]

seb-jean avatar Sep 16 '22 12:09 seb-jean

Hi,

The filters are already available through https://github.com/twigphp/intl-extra , for example:

countries: https://twig.symfony.com/doc/3.x/filters/country_name.html locales: https://twig.symfony.com/doc/3.x/filters/locale_name.html currencies: https://twig.symfony.com/doc/3.x/filters/currency_name.html

If you need a list of values that you can than use in the filters I would suggest looking at: https://symfony.com/doc/current/components/intl.html#country-names and than insert these values in your templates.

So I think it is a good idea to have these type of "common" or "general" data available through FOSS, but it is already there :) It is just not here in the core of Twig. You will have to pick the packages you like yourself and than add those together.

SpacePossum avatar Sep 16 '22 13:09 SpacePossum

I just created a PR.

seb-jean avatar Sep 16 '22 14:09 seb-jean

Closing as there is an associated PR.

fabpot avatar Dec 26 '22 16:12 fabpot