Skip to content

Latest commit

 

History

History
115 lines (81 loc) · 2 KB

intl.md

File metadata and controls

115 lines (81 loc) · 2 KB

Intl Twig Extension

The intl twig extension gives you a simple and efficient way to get country, language or a locale in a specific locale.

Setup

Service Registration

The twig extension need to be registered as symfony service.

xml

<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/dic/services
        http://symfony.com/schema/dic/services/services-1.0.xsd">

    <services>
        <service id="app.twig.web_intl" class="Massive\Component\Web\IntlTwigExtension">
            <tag name="twig.extension" />
        </service>
    </services>
</container>

yml

services:
    app.twig.web_intl:
        class: Massive\Component\Web\IntlTwigExtension
        tags:
            - { name: twig.extension }

Usage

Get country

You can get a country in a specific language:

{{ intl_country('de') }}
{{ intl_country('de', 'de') }}

Output:

Germany
Deutschland

You can also get a list of countries by using intl_countries('de').

Get language

You can get a language in a specfic language:

{{ intl_language('de') }}
{{ intl_language('de', null, 'de') }}
{{ intl_language('de', 'AT') }}
{{ intl_language('de', 'AT', 'de') }}

Output:

German
Deutsch
Austrian German
Österreichisches Deutsch

You can also get a list of languages by using intl_languages('de').

Get locale

You can get a locale in a specfic language:

{{ intl_locale('de') }}
{{ intl_locale('de', 'de') }}
{{ intl_locale('de_AT') }}
{{ intl_locale('de_AT' 'de') }}

Output:

German
Deutsch
German (Austria)
Deutsch (Österreich)

You can also get a list of locales by using intl_locales('de').

Get icu locale

Convert a de-at locale to a valid de_AT:

{{ 'de-at'|intl_icu_locale }}

Output:

de_AT