/**
  * Create or update a language file.
  *
  * @static
  *
  * @param $extension
  * @param $scope
  * @param $lang
  *
  * @return mixed|string
  * @throws Exception
  */
 public static function updateLanguage($extension, $scope, $lang)
 {
     $languageFile = g11nExtensionHelper::findLanguageFile($lang, $extension, $scope);
     $templateFile = g11nStorage::getTemplatePath($extension, $scope);
     $msg = '';
     if (false == $languageFile) {
         //-- New file
         $scopePath = g11nExtensionHelper::getScopePath($scope);
         $extensionPath = g11nExtensionHelper::getExtensionLanguagePath($extension);
         $path = $scopePath . '/' . $extensionPath . '/' . $lang;
         if (!JFolder::exists($path)) {
             if (!JFolder::create($path)) {
                 throw new Exception('Can not create the language folder');
             }
         }
         $fileName = $lang . '.' . $extension . '.po';
         $input = '--input=' . $templateFile;
         $output = '--output=' . $path . '/' . $fileName;
         $noWrap = '--no-wrap';
         $locale = '--locale=' . $lang;
         $cmd = "msginit {$input} {$output} {$locale} {$noWrap} 2>&1";
         $msg .= ECR_DEBUG ? '<h3>' . $cmd . '</h3>' : '';
         ob_start();
         system($cmd);
         $msg .= ob_get_clean();
         $msg = str_replace("\n", BR, $msg);
         if (!JFile::exists($templateFile)) {
             throw new Exception('Can not copy create the language file');
         }
         $msg = jgettext('The language file has been created<br />') . $msg;
     } else {
         //-- Update existing file
         $msg .= jgettext('Updating language file...');
         $update = '--update';
         $backup = '--backup=numbered';
         $noFuzzy = '--no-fuzzy-matching';
         $verbose = '--verbose';
         $noWrap = '--no-wrap';
         $cmd = "msgmerge {$update} {$noFuzzy} {$backup} {$verbose} {$noWrap} {$languageFile} {$templateFile}  2>&1";
         $msg .= ECR_DEBUG ? '<h3>' . $cmd . '</h3>' : '';
         ob_start();
         system($cmd);
         $msg .= ob_get_clean();
     }
     return $msg;
 }