Skip to content

Commit

Permalink
new method to save language ini
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepereiradasilva committed Dec 30, 2016
1 parent 0bb6c5c commit cb162a2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
10 changes: 1 addition & 9 deletions administrator/components/com_languages/models/override.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,8 @@ public function save($data, $opposite_client = false)
$strings = array($data['key'] => $data['override']) + $strings;
}

foreach ($strings as $key => $string)
{
$strings[$key] = str_replace('"', '"_QQ_"', $string);
}

// Write override.ini file with the strings.
$registry = new Registry($strings);
$reg = $registry->toString('INI');

if (!JFile::write($filename, $reg))
if (JLanguageHelper::saveToIniFile($filename, $strings) === false)
{
return false;
}
Expand Down
14 changes: 2 additions & 12 deletions administrator/components/com_languages/models/overrides.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,8 @@ public function delete($cids)
}
}

foreach ($strings as $key => $string)
{
$strings[$key] = str_replace('"', '"_QQ_"', $string);
}

// Write override.ini file with the left strings.
$registry = new Registry($strings);
$reg = $registry->toString('INI');

$filename = constant('JPATH_' . $client) . '/language/overrides/' . $this->getState('filter.language') . '.override.ini';

if (!JFile::write($filename, $reg))
// Write override.ini file with the strings.
if (JLanguageHelper::saveToIniFile($filename, $strings) === false)
{
return false;
}
Expand Down
26 changes: 26 additions & 0 deletions libraries/joomla/language/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,30 @@ public static function getContentLanguages($checkPublished = true, $checkInstall

return $languages;
}

/**
* Save strings to a language file.
*
* @param string $filename The language ini file path.
* @param array $strings The array of strings.
*
* @return boolean True if saved, false otherwise.
*
* @since __DEPLOY_VERSION__
*/
public static function saveToIniFile($filename, array $strings)
{
JLoader::register('JFile', JPATH_LIBRARIES . '/joomla/filesystem/file.php');

// Escape double quotes.
foreach ($strings as $key => $string)
{
$strings[$key] = addcslashes($string, '"');
}

// Write override.ini file with the strings.
$registry = new Registry($strings);

return JFile::write($filename, $registry->toString('INI'));
}
}

0 comments on commit cb162a2

Please sign in to comment.