1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-15 11:14:12 +02:00
This commit is contained in:
Ryan Cramer
2023-05-03 11:03:34 -04:00
parent f6c2ad6ed5
commit 9bfce99352

View File

@@ -3,7 +3,7 @@
/**
* ProcessWire Language Translator
*
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
* ProcessWire 3.x, Copyright 2023 by Ryan Cramer
* https://processwire.com
*
*
@@ -538,21 +538,33 @@ class LanguageTranslator extends Wire {
} else {
$textdomain = $this->filenameToTextdomain($filename);
}
$this->textdomains[$textdomain] = $this->textdomainTemplate(ltrim($filename, '/'), $textdomain);
$file = $this->getTextdomainTranslationFile($textdomain);
if(empty($file)) {
$this->error("Unable to get textdomain translation file: $textdomain");
return false;
}
if(is_file($file)) {
$result = true;
} else {
$this->textdomains[$textdomain] = $this->textdomainTemplate(ltrim($filename, '/'), $textdomain);
$result = file_put_contents($file, $this->encodeJSON($this->textdomains[$textdomain]), LOCK_EX);
if($result && $this->config->chmodFile) chmod($file, octdec($this->config->chmodFile));
}
if($result) {
$fieldName = 'language_files';
if(strpos($textdomain, 'wire--') !== 0) {
if($this->wire('fields')->get('language_files_site')) {
if($this->wire()->fields->get('language_files_site')) {
$fieldName = 'language_files_site';
}
}
$this->currentLanguage->$fieldName->add($file);
/** @var Pagefiles $pagefiles */
$pagefiles = $this->currentLanguage->$fieldName;
if(!$pagefiles->has(basename($file))) {
$pagefiles->add($file);
if($save) $this->currentLanguage->save();
}
}
return $result ? $textdomain : false;
}
@@ -677,5 +689,3 @@ class LanguageTranslator extends Wire {
}
}