updated streamline-setup v2

This commit is contained in:
2025-01-15 08:53:49 -08:00
committed by alec.turner
parent a2ce9248f0
commit 4b569f81b0
20228 changed files with 2932048 additions and 63204 deletions
@@ -28,7 +28,7 @@ class CsvFileDumper extends FileDumper
$handle = fopen('php://memory', 'r+');
foreach ($messages->all($domain) as $source => $target) {
fputcsv($handle, [$source, $target], $this->delimiter, $this->enclosure);
fputcsv($handle, [$source, $target], $this->delimiter, $this->enclosure, '\\');
}
rewind($handle);
@@ -44,7 +44,7 @@ final class TransMethodVisitor extends AbstractVisitor implements NodeVisitor
if ('trans' === $name || 't' === $name) {
$firstNamedArgumentIndex = $this->nodeFirstNamedArgumentIndex($node);
if (!$messages = $this->getStringArguments($node, 0 < $firstNamedArgumentIndex ? 0 : 'message')) {
if (!$messages = $this->getStringArguments($node, 0 < $firstNamedArgumentIndex ? 0 : 'id')) {
return null;
}
@@ -22,7 +22,7 @@ class CsvFileLoader extends FileLoader
{
private string $delimiter = ';';
private string $enclosure = '"';
private string $escape = '\\';
private string $escape = '';
protected function loadResource(string $resource): array
{
@@ -55,7 +55,7 @@ class CsvFileLoader extends FileLoader
*
* @return void
*/
public function setCsvControl(string $delimiter = ';', string $enclosure = '"', string $escape = '\\')
public function setCsvControl(string $delimiter = ';', string $enclosure = '"', string $escape = '')
{
$this->delimiter = $delimiter;
$this->enclosure = $enclosure;
@@ -112,16 +112,20 @@ class XliffFileLoader implements LoaderInterface
continue;
}
if (isset($translation->target) && 'needs-translation' === (string) $translation->target->attributes()['state']) {
$source = (string) (isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source);
if (isset($translation->target)
&& 'needs-translation' === (string) $translation->target->attributes()['state']
&& \in_array((string) $translation->target, [$source, (string) $translation->source], true)
) {
continue;
}
$source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
// If the xlf file has another encoding specified, try to convert it because
// simple_xml will always return utf-8 encoded values
$target = $this->utf8ToCharset((string) ($translation->target ?? $translation->source), $encoding);
$catalogue->set((string) $source, $target, $domain);
$catalogue->set($source, $target, $domain);
$metadata = [
'source' => (string) $translation->source,
@@ -144,7 +148,7 @@ class XliffFileLoader implements LoaderInterface
$metadata['id'] = (string) $attributes['id'];
}
$catalogue->setMetadata((string) $source, $metadata, $domain);
$catalogue->setMetadata($source, $metadata, $domain);
}
}
}
@@ -34,9 +34,14 @@ class LocaleSwitcher implements LocaleAwareInterface
public function setLocale(string $locale): void
{
if (class_exists(\Locale::class)) {
\Locale::setDefault($locale);
// Silently ignore if the intl extension is not loaded
try {
if (class_exists(\Locale::class, false)) {
\Locale::setDefault($locale);
}
} catch (\Exception) {
}
$this->locale = $locale;
$this->requestContext?->setParameter('_locale', $locale);
@@ -162,11 +162,11 @@ function extractLocaleFromFilePath($filePath)
function extractTranslationKeys($filePath): array
{
$translationKeys = [];
$contents = new \SimpleXMLElement(file_get_contents($filePath));
$contents = new SimpleXMLElement(file_get_contents($filePath));
foreach ($contents->file->body->{'trans-unit'} as $translationKey) {
$translationId = (string) $translationKey['id'];
$translationKey = (string) $translationKey->source;
$translationKey = (string) ($translationKey['resname'] ?? $translationKey->source);
$translationKeys[$translationId] = $translationKey;
}