public function findAvailableLocales()
    {
        // Check for needed data
        $path   = $this->getPath();
        $domain = $this->getDomain();
        if (!$path || !$domain) {
            throw new Exception("Values for 'path' and 'domain' must be set.");
        }

        // Build regular expressions for finding domains and locales
        $regexLocale  = Locale::REGEX_LOCALE;
        $regexDefault = "/^{$regexLocale}\/LC_MESSAGES\/{$domain}\.mo$/ui";
        $regexVirtual = "/^(?<virtualLocale>C)\/LC_MESSAGES\/(?<virtualDomain>{$domain}[^a-z]{$regexLocale})\.mo$/ui";

        $glob = "{$path}/*/LC_MESSAGES/{$domain}*.mo";
        foreach (glob($glob) as $parse) {
            // Strip path prefix to fit regex
            $parse = str_replace($path . '/', '', $parse);

            // Check for default or virtual localized files
            if (preg_match($regexDefault, $parse, $found) || preg_match($regexVirtual, $parse, $found)) {
                $this->addLocale($found['locale']);
                if (!empty($found['virtualLocale'])) {
                    $map = [
                        'domain' => $found['virtualDomain'],
                        'locale' => $found['virtualLocale'],
                    ];
                    $this->addMap($found['locale'], $map);
                }
            }
        }

        return $this;
    }
public function findAvailableLocales()
    {
        // Check for needed data
        $path   = $this->getPath();
        $domain = $this->getDomain();
        if (!$path || !$domain) {
            throw new Exception("Values for 'path' and 'domain' must be set.");
        }

        // Build regular expressions for finding domains and locales
        $regexLocale  = Locale::REGEX_LOCALE;
        $regexDefault = "/^{$regexLocale}\/LC_MESSAGES\/{$domain}\.mo$/ui";
        $regexVirtual = "/^(?<virtualLocale>C)\/LC_MESSAGES\/(?<virtualDomain>{$domain}[^a-z]{$regexLocale})\.mo$/ui";

        $glob = "{$path}/*/LC_MESSAGES/{$domain}*.mo";
        foreach (glob($glob) as $parse) {
            // Strip path prefix to fit regex
            $parse = str_replace($path . '/', '', $parse);

            // Check for default or virtual localized files
            if (preg_match($regexDefault, $parse, $found) || preg_match($regexVirtual, $parse, $found)) {
                $this->addLocale($found['locale']);
                if (!empty($found['virtualLocale'])) {
                    $map = [
                        'domain' => $found['virtualDomain'],
                        'locale' => $found['virtualLocale'],
                    ];
                    $this->addMap($found['locale'], $map);
                }
            }
        }

        return $this;
    }
public function findAvailableLocales ( ) { // Check for needed data $ path = $ this -> getPath ( ) ; $ domain = $ this -> getDomain ( ) ; if ( ! $ path || ! $ domain ) { throw new Exception ( "Values for 'path' and 'domain' must be set." ) ; } // Build regular expressions for finding domains and locales $ regexLocale = Locale :: REGEX_LOCALE ; $ regexDefault = "/^{$regexLocale}\/LC_MESSAGES\/{$domain}\.mo$/ui" ; $ regexVirtual = "/^(?<virtualLocale>C)\/LC_MESSAGES\/(?<virtualDomain>{$domain}[^a-z]{$regexLocale})\.mo$/ui" ; $ glob = "{$path}/*/LC_MESSAGES/{$domain}*.mo" ; foreach ( glob ( $ glob ) as $ parse ) { // Strip path prefix to fit regex $ parse = str_replace ( $ path . '/' , '' , $ parse ) ; // Check for default or virtual localized files if ( preg_match ( $ regexDefault , $ parse , $ found ) || preg_match ( $ regexVirtual , $ parse , $ found ) ) { $ this -> addLocale ( $ found [ 'locale' ] ) ; if ( ! empty ( $ found [ 'virtualLocale' ] ) ) { $ map = [ 'domain' => $ found [ 'virtualDomain' ] , 'locale' => $ found [ 'virtualLocale' ] , ] ; $ this -> addMap ( $ found [ 'locale' ] , $ map ) ; } } } return $ this ; }
Dynamically find all available locales.

This class supports "virtual locales" because often not all locales are installed on the server. If you want to
use <code>gettext()</code> the used locale MUST be installed. This class uses the workaround via default internal
locale "C" and determining the locale via filename. The mapping is done automatically.

All locales must be stored in a "locale" folder (specified via <code>setPath()</code> in this structure:
- <code><pathToLocale>/<locale>/LC_MESSAGES/<domain>.mo</code> or
- <code><pathToLocale>/C/LC_MESSAGES/<domain>.<locale>.mo</code>

Examples:
- <code>de_DE/LC_MESSAGES/default.mo</code> or
- <code>C/LC_MESSAGES/app.en_GB.mo</code>

@throws Exception
Dynamically find all available locales .