skill_translate.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
  4. use Chamilo\CoreBundle\Entity\Language;
  5. use Chamilo\CoreBundle\Entity\Skill;
  6. $cidReset = true;
  7. require_once __DIR__.'/../inc/global.inc.php';
  8. api_protect_admin_script();
  9. $em = Database::getManager();
  10. $skill = null;
  11. $extraFieldOption = null;
  12. $variableLanguage = null;
  13. $originalName = null;
  14. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'name';
  15. if (isset($_GET['skill'])) {
  16. /** @var Skill $skill */
  17. $skill = $em->find('ChamiloCoreBundle:Skill', intval($_GET['skill']));
  18. if ($action === 'name') {
  19. $variableLanguage = ChamiloApi::getLanguageVar(
  20. $skill->getName(false),
  21. 'Skill'
  22. );
  23. $originalName = $skill->getName(false);
  24. } elseif ($action === 'code') {
  25. $variableLanguage = ChamiloApi::getLanguageVar(
  26. $skill->getShortCode(false),
  27. 'SkillCode'
  28. );
  29. $originalName = $skill->getShortCode(false);
  30. }
  31. }
  32. if (!$skill || empty($variableLanguage)) {
  33. api_not_allowed(true);
  34. }
  35. if (empty($originalName)) {
  36. Display::addFlash(
  37. Display::return_message(get_lang('Could not translate'), 'error')
  38. );
  39. header('Location: '.api_get_path(WEB_CODE_PATH).'admin/skill_edit.php?id='.$skill->getId());
  40. exit;
  41. }
  42. $languageId = isset($_GET['sub_language']) ? intval($_GET['sub_language']) : 0;
  43. $languages = $em
  44. ->getRepository('ChamiloCoreBundle:Language')
  45. ->findAllPlatformSubLanguages();
  46. $languagesOptions = [0 => get_lang('none')];
  47. /** @var Language $language */
  48. foreach ($languages as $language) {
  49. $languagesOptions[$language->getId()] = $language->getOriginalName();
  50. }
  51. $translateUrl = api_get_path(WEB_CODE_PATH).'admin/sub_language_ajax.inc.php?skill='.$skill->getId();
  52. $form = new FormValidator('new_lang_variable', 'POST', $translateUrl);
  53. $form->addHeader(get_lang('Add terms to the sub-language'));
  54. $form->addText('variable_language', get_lang('Language variable'), false);
  55. $form->addText('original_name', get_lang('Original name'), false);
  56. $form->addSelect(
  57. 'sub_language',
  58. [get_lang('Sub-language'), get_lang('OnlyActiveSub-languagesAreListed')],
  59. $languagesOptions
  60. );
  61. if ($languageId) {
  62. $languageInfo = api_get_language_info($languageId);
  63. $form->addText(
  64. 'new_language',
  65. [get_lang('Translation'), get_lang('If this term has already been translated, this operation will replace its translation for this sub-language.')]
  66. );
  67. $form->addHidden('file_id', 0);
  68. $form->addHidden('id', $languageInfo['parent_id']);
  69. $form->addHidden('sub', $languageInfo['id']);
  70. $form->addHidden('sub_language_id', $languageInfo['id']);
  71. $form->addHidden('redirect', true);
  72. $form->addButtonSave(get_lang('Save'));
  73. }
  74. $form->setDefaults([
  75. 'variable_language' => '$'.$variableLanguage,
  76. 'original_name' => $originalName,
  77. 'sub_language' => $languageId,
  78. 'new_language' => $action === 'code' ? $skill->getShortCode() : $skill->getName(),
  79. ]);
  80. $form->addRule('sub_language', get_lang('Required'), 'required');
  81. $form->freeze(['variable_language', 'original_name']);
  82. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Administration')];
  83. $interbreadcrumb[] = ['url' => 'skill_list.php', 'name' => get_lang('Manage skills')];
  84. $view = new Template(get_lang('Add terms to the sub-language'));
  85. $view->assign('form', $form->returnForm());
  86. $template = $view->get_template('extrafield/translate.tpl');
  87. $content = $view->fetch($template);
  88. $view->assign('content', $content);
  89. $view->display_one_col_template();