Neos\Flow\I18n\Utility::extractLocaleTagFromFilename PHP Method

extractLocaleTagFromFilename() public static method

Locale tag should be placed just before the extension of the file. For example, filename bar.png can be localized as bar.en_GB.png, and this method extracts en_GB from the name. Note: this ignores matches on rss, xml and php and validates the identifier.
public static extractLocaleTagFromFilename ( string $filename ) : mixed
$filename string Filename to extract locale identifier from
return mixed The string with extracted locale identifier of FALSE on failure
    public static function extractLocaleTagFromFilename($filename)
    {
        if (strpos($filename, '.') === false) {
            return false;
        }
        $filenameParts = explode('.', $filename);
        if (in_array($filenameParts[count($filenameParts) - 2], ['php', 'rss', 'xml'])) {
            return false;
        } elseif (count($filenameParts) === 2 && preg_match(Locale::PATTERN_MATCH_LOCALEIDENTIFIER, $filenameParts[0]) === 1) {
            return $filenameParts[0];
        } elseif (preg_match(Locale::PATTERN_MATCH_LOCALEIDENTIFIER, $filenameParts[count($filenameParts) - 2]) === 1) {
            return $filenameParts[count($filenameParts) - 2];
        } else {
            return false;
        }
    }

Usage Example

 /**
  * @test
  * @dataProvider filenamesWithLocale
  */
 public function localeIdentifiersAreCorrectlyExtractedFromFilename($filename, $expectedResult)
 {
     $result = I18n\Utility::extractLocaleTagFromFilename($filename);
     $this->assertEquals($expectedResult, $result);
 }
All Usage Examples Of Neos\Flow\I18n\Utility::extractLocaleTagFromFilename