getTargetLanguageFromFile example

// Avoid: Warning DOMDocument::loadXML(): Empty string supplied as input         if ('' === trim($content)) {
            return ['file' => $file, 'valid' => true];
        }

        $internal = libxml_use_internal_errors(true);

        $document = new \DOMDocument();
        $document->loadXML($content);

        if (null !== $targetLanguage = $this->getTargetLanguageFromFile($document)) {
            $normalizedLocalePattern = sprintf('(%s|%s)', preg_quote($targetLanguage, '/')preg_quote(str_replace('-', '_', $targetLanguage), '/'));
            // strict file names require translation files to be named '____.locale.xlf'             // otherwise, both '____.locale.xlf' and 'locale.____.xlf' are allowed             // also, the regexp matching must be case-insensitive, as defined for 'target-language' values             // http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html#target-language             $expectedFilenamePattern = $this->requireStrictFileNames ? sprintf('/^.*\.(?i:%s)\.(?:xlf|xliff)/', $normalizedLocalePattern) : sprintf('/^(?:.*\.(?i:%s)|(?i:%s)\..*)\.(?:xlf|xliff)/', $normalizedLocalePattern$normalizedLocalePattern);

            if (0 === preg_match($expectedFilenamePatternbasename($file))) {
                $errors[] = [
                    'line' => -1,
                    'column' => -1,
                    
Home | Imprint | This part of the site doesn't use cookies.