Commit 78c7c1e5 authored by damjan's avatar damjan
Browse files

[FEATURE] Dont touch original file when translating

* When user edits a file, languages from section 'Select up to two languages' are considered as 'edited languages'.
* If some language is not edited, its file will not be rewritten.

* XLF:
- If user edits default language (language from main file), all localisation files will be rewritten, because default language appears in them as source.

* XML:
- If there is one, merged, xml file, this feature is disabled.

Resolves: forge.typo3.org/issues/67499
parent 6ca4e511
......@@ -286,7 +286,13 @@ class EditFileController extends AbstractBackendController {
// write if no session continued
if (!$langDataSessionContinued) {
$this->configurationService->execWrite($langfileEditNewLangData);
// Making array of languages that were changed, so only that language files will be edited.
$editedLanguages = array($languageSelection);
if ($languageSelection !== $referenceLanguageSelection) {
$editedLanguages[] = $referenceLanguageSelection;
}
$this->configurationService->execWrite($langfileEditNewLangData, array(), FALSE, $editedLanguages);
$this->addFlashMessage(
LocalizationUtility::translate('lang.file.write.success', 'lfeditor'),
'',
......
......@@ -184,7 +184,7 @@ class ConfigurationService extends AbstractService {
}
// global extensions
if ($this->extConfig['viewGlobalExt'] && is_dir(Typo3Lib::pathGlobalExt)) {
if ($this->extConfig['viewGlobalExt']) {
if (count(
$content = Functions::searchExtensions(
PATH_site . Typo3Lib::pathGlobalExt, $this->extConfig['viewStateExt'],
......@@ -381,14 +381,17 @@ class ConfigurationService extends AbstractService {
/**
* Executes writing of language files
*
* @throws LFException raised if file could not be written or some param criterias are not correct
* @throws Exception|LFException
*
* @param array $modArray changes (constants with empty values will be deleted)
* @param array $modMetaArray meta changes (indexes with empty values will be deleted)
* @param boolean $forceDel set to true if you want delete default constants
* @param array|NULL $editedLanguages
* @throws Exception
* @throws LFException
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
* @return void
*/
public function execWrite($modArray, $modMetaArray = array(), $forceDel = FALSE) {
public function execWrite($modArray, $modMetaArray = array(), $forceDel = FALSE, $editedLanguages = NULL) {
// checks
if (!is_array($modArray)) {
throw new LFException('failure.file.notWritten');
......@@ -429,7 +432,7 @@ class ConfigurationService extends AbstractService {
}
// write new language data
$fileObject->writeFile();
$fileObject->writeFile($editedLanguages);
// delete possible language files
$absFile = $fileObject->getVar('absFile');
......@@ -709,4 +712,4 @@ class ConfigurationService extends AbstractService {
}
return $languages;
}
}
\ No newline at end of file
}
\ No newline at end of file
......@@ -447,10 +447,13 @@ class FileBackupService extends FileService {
/**
* prepares the backup file and writes the new meta information
*
* @throws LFException raised if meta file cant be written
* @return array backup file as key and content as value
* @param array | NULL $editedLanguages
* @return array raised if meta file cant be written
* @throws Exception
* @throws LFException
* @return array
*/
protected function prepareFileContents() {
protected function prepareFileContents($editedLanguages = NULL) {
// get content
$xml = $this->prepareBackupContent();
......
......@@ -227,9 +227,10 @@ class FileBasePHPService extends FileBaseService {
/**
* prepares the final content
*
* @param array | NULL $editedLanguages
* @return array language files as key and content as value
*/
protected function prepareFileContents() {
protected function prepareFileContents($editedLanguages = NULL) {
// convert all language values from utf-8 to the original charset
if (!Typo3Lib::isTypo3BackendInUtf8Mode()) {
$this->localLang = Typo3Lib::utf8($this->localLang, FALSE, array('default'));
......
......@@ -318,9 +318,10 @@ class FileBaseXLFService extends FileBaseService {
/**
* prepares the final content
*
* @param array | NULL $editedLanguages
* @return array language files as key and content as value
*/
protected function prepareFileContents() {
protected function prepareFileContents($editedLanguages = NULL) {
// convert all language values to utf-8
if (!Typo3Lib::isTypo3BackendInUtf8Mode()) {
$this->localLang = Typo3Lib::utf8($this->localLang, TRUE, array('default'));
......@@ -335,6 +336,11 @@ class FileBaseXLFService extends FileBaseService {
if ($lang === 'default') {
continue;
}
// If default language content and $lang language content are not edited, skip this file.
if ($editedLanguages !== NULL &&
!in_array('default', $editedLanguages) && !in_array($lang, $editedLanguages)) {
continue;
}
if (is_array($this->localLang[$lang]) && count($this->localLang[$lang])) {
$file = $this->originLang[$lang];
......@@ -350,6 +356,9 @@ class FileBaseXLFService extends FileBaseService {
if ($this->checkLocalizedFile(basename($this->absFile), implode('|', SgLib::getSystemLanguages()))) {
return $languageFiles;
}
if ($editedLanguages !== NULL && !in_array('default', $editedLanguages)) {
return $languageFiles;
}
// prepare content for the main file
$data = array(
......
......@@ -277,13 +277,15 @@ class FileBaseXMLService extends FileBaseService {
/**
* prepares the final content
*
* @param array | NULL $editedLanguages
* @return array language files as key and content as value
*/
protected function prepareFileContents() {
protected function prepareFileContents($editedLanguages = NULL) {
// convert all language values to utf-8
if (!Typo3Lib::isTypo3BackendInUtf8Mode()) {
$this->localLang = Typo3Lib::utf8($this->localLang, TRUE, array('default'));
}
$mergedFile = TRUE;
// prepare Content
$mainFileContent = array('meta' => $this->prepareMeta());
......@@ -292,7 +294,11 @@ class FileBaseXMLService extends FileBaseService {
foreach ($languages as $lang) {
// get content of localized and main file
if ($this->checkLocalizedFile(basename($this->originLang[$lang]), $lang)) {
if (is_array($this->localLang[$lang]) && count($this->localLang[$lang])) {
$mergedFile = FALSE;
if (is_array($this->localLang[$lang]) && count($this->localLang[$lang])
// check if this language content was edited
&& ($editedLanguages === NULL || in_array($lang, $editedLanguages))
) {
$languageFiles[$this->originLang[$lang]] .=
$this->array2xml(
$this->getLangContent($this->localLang[$lang], $lang),
......@@ -323,6 +329,9 @@ class FileBaseXMLService extends FileBaseService {
if ($this->checkLocalizedFile(basename($this->absFile), implode('|', SgLib::getSystemLanguages()))) {
return $languageFiles;
}
if (!$mergedFile && $editedLanguages !== NULL && !in_array('default', $editedLanguages)) {
return $languageFiles;
}
// prepare Content for the main file
$languageFiles[$this->absFile] = $this->array2xml($mainFileContent, 'T3locallang');
......
......@@ -128,10 +128,12 @@ class FileOverrideService extends FileBaseXMLService {
/**
* Writes language override files.
*
* @throws LFException raised if a file cant be written
* @param array|null $editedLanguages
* @throws LFException
* @throws \Exception
* @return void
*/
public function writeFile() {
public function writeFile($editedLanguages = NULL) {
$this->deleteDuplicates();
if (!$this->langDataExists() && !is_file($this->absFile)) {
return;
......
......@@ -81,9 +81,10 @@ abstract class FileService extends AbstractService {
protected $meta;
/**
* @param $editedLanguages
* @return mixed
*/
abstract protected function prepareFileContents();
abstract protected function prepareFileContents($editedLanguages);
/**
* @return mixed
......@@ -263,12 +264,13 @@ abstract class FileService extends AbstractService {
/**
* writes language files
*
* @param array | NULL $editedLanguages
* @throws LFException raised if a file cant be written
* @return void
*/
public function writeFile() {
public function writeFile($editedLanguages = NULL) {
// get prepared language files
$languageFiles = $this->prepareFileContents();
$languageFiles = $this->prepareFileContents($editedLanguages);
// check write permissions of all files
foreach ($languageFiles as $file => $content) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment