Fix skill translation with special characters - refs BT#13496

pull/3063/head
Angel Fernando Quiroz Campos 8 years ago
parent e9c8169f75
commit 130387aa3d
  1. 13
      main/admin/skill_translate.php
  2. 13
      main/inc/lib/skill.lib.php
  3. 17
      src/Chamilo/CoreBundle/Component/Utils/ChamiloApi.php
  4. 13
      src/Chamilo/CoreBundle/Entity/Skill.php

@ -4,6 +4,7 @@
use \Chamilo\CoreBundle\Entity\ExtraField;
use Chamilo\CoreBundle\Entity\Skill;
use Chamilo\CoreBundle\Entity\Language;
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
$cidReset = true;
@ -24,13 +25,15 @@ if (isset($_GET['skill'])) {
$skill = $em->find('ChamiloCoreBundle:Skill', intval($_GET['skill']));
if ($action === 'name') {
$variableLanguage = '$Skill'.api_underscore_to_camel_case(
str_replace(' ', '_', $skill->getName(false))
$variableLanguage = ChamiloApi::getLanguageVar(
$skill->getName(false),
'Skill'
);
$originalName = $skill->getName(false);
} elseif ($action === 'code') {
$variableLanguage = '$SkillCode'.api_underscore_to_camel_case(
str_replace(' ', '_', $skill->getShortCode(false))
$variableLanguage = ChamiloApi::getLanguageVar(
$skill->getShortCode(false),
'SkillCode'
);
$originalName = $skill->getShortCode(false);
}
@ -82,7 +85,7 @@ if ($languageId) {
}
$form->setDefaults([
'variable_language' => $variableLanguage,
'variable_language' => '$'.$variableLanguage,
'original_name' => $originalName,
'sub_language' => $languageId,
'new_language' => $action === 'code' ? $skill->getShortCode() : $skill->getName()

@ -3,6 +3,7 @@
use Chamilo\UserBundle\Entity\User;
use Chamilo\UserBundle\Entity\Repository\UserRepository;
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
/**
* Class SkillProfile
@ -1967,11 +1968,9 @@ class Skill extends Model
*/
public static function translateName($name)
{
$camelCase = 'Skill'.api_underscore_to_camel_case(
str_replace(' ', '_', $name)
);
$variable = ChamiloApi::getLanguageVar($name, 'Skill');
return isset($GLOBALS[$camelCase]) ? $GLOBALS[$camelCase] : $name;
return isset($GLOBALS[$variable]) ? $GLOBALS[$variable] : $name;
}
public static function translateCode($code)
@ -1980,10 +1979,8 @@ class Skill extends Model
return '';
}
$camelCase = 'SkillCode'.api_underscore_to_camel_case(
str_replace(' ', '_', $code)
);
$variable = ChamiloApi::getLanguageVar($code, 'SkillCode');
return isset($GLOBALS[$camelCase]) ? $GLOBALS[$camelCase] : $code;
return isset($GLOBALS[$variable]) ? $GLOBALS[$variable] : $code;
}
}

@ -214,4 +214,21 @@ class ChamiloApi
return $requestedWith === 'XMLHttpRequest';
}
/**
* Get a variable name for language file from a text
* @param string $text
* @param string $prefix
* @return string
*/
public static function getLanguageVar($text, $prefix = '')
{
$text = api_replace_dangerous_char($text);
$text = str_replace(['-', ' '], '_', $text);
$text = preg_replace('/\_{1,}/', '_', $text);
//$text = str_replace('_', '', $text);
$text = api_underscore_to_camel_case($text);
return $prefix.$text;
}
}

@ -3,6 +3,7 @@
namespace Chamilo\CoreBundle\Entity;
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
use Chamilo\SkillBundle\Entity\Profile;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
@ -124,11 +125,9 @@ class Skill
public function getName($translated = true)
{
if ($translated) {
$camelCase = 'Skill'.api_underscore_to_camel_case(
str_replace(' ', '_', $this->name)
);
$variable = ChamiloApi::getLanguageVar($this->name, 'Skill');
return isset($GLOBALS[$camelCase]) ? $GLOBALS[$camelCase] : $this->name;
return isset($GLOBALS[$variable]) ? $GLOBALS[$variable] : $this->name;
}
return $this->name;
@ -156,11 +155,9 @@ class Skill
public function getShortCode($translated = true)
{
if ($translated && !empty($this->shortCode)) {
$camelCase = 'SkillCode'.api_underscore_to_camel_case(
str_replace(' ', '_', $this->shortCode)
);
$variable = ChamiloApi::getLanguageVar($this->shortCode, 'SkillCode');
return isset($GLOBALS[$camelCase]) ? $GLOBALS[$camelCase] : $this->shortCode;
return isset($GLOBALS[$variable]) ? $GLOBALS[$variable] : $this->shortCode;
}
return $this->shortCode;

Loading…
Cancel
Save