translate.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use \Chamilo\CoreBundle\Entity\ExtraField;
  4. $cidReset = true;
  5. require_once '../inc/global.inc.php';
  6. api_protect_admin_script();
  7. $em = Database::getManager();
  8. $extraField = null;
  9. $extraFieldOption = null;
  10. $variableLanguage = null;
  11. $originalName = null;
  12. if (isset($_GET['extra_field'])) {
  13. $extraField = $em->find('ChamiloCoreBundle:ExtraField', intval($_GET['extra_field']));
  14. $variableLanguage = '$' . api_underscore_to_camel_case($extraField->getVariable());
  15. $originalName = $extraField->getDisplayText(false);
  16. } elseif (isset($_GET['extra_field_option'])) {
  17. $extraFieldOption = $em->find('ChamiloCoreBundle:ExtraFieldOptions', intval($_GET['extra_field_option']));
  18. $extraField = $extraFieldOption->getField();
  19. $variableLanguage = '$' . ExtraFieldOption::getLanguageVariable($extraFieldOption->getDisplayText());
  20. $originalName = $extraFieldOption->getDisplayText(false);
  21. }
  22. if (!$extraField || empty($variableLanguage) || empty($originalName)) {
  23. api_not_allowed(true);
  24. }
  25. $languageId = isset($_GET['sub_language']) ? intval($_GET['sub_language']) : 0;
  26. $languages = $em
  27. ->getRepository('ChamiloCoreBundle:Language')
  28. ->findAllPlatformSubLanguages();
  29. $languagesOptions = [0 => get_lang('None')];
  30. foreach ($languages as $language) {
  31. $languagesOptions[$language->getId()] = $language->getOriginalName();
  32. }
  33. $translateUrl = api_get_path(WEB_CODE_PATH) . 'admin/sub_language_ajax.inc.php';
  34. $form = new FormValidator('new_lang_variable', 'POST', $translateUrl);
  35. $form->addHeader(get_lang('AddWordForTheSubLanguage'));
  36. $form->addText('variable_language', get_lang('LanguageVariable'), false);
  37. $form->addText('original_name', get_lang('OriginalName'), false);
  38. $form->addSelect('sub_language', [get_lang('SubLanguage'), get_lang('OnlyActiveSubLanguagesAreListed')], $languagesOptions);
  39. if ($languageId) {
  40. $languageInfo = api_get_language_info($languageId);
  41. $form->addText('new_language', [get_lang('Translation'), get_lang('IfThisTranslationExistsThisWillReplaceTheTerm')]);
  42. $form->addHidden('file_id', 0);
  43. $form->addHidden('id', $languageInfo['parent_id']);
  44. $form->addHidden('sub', $languageInfo['id']);
  45. $form->addHidden('sub_language_id', $languageInfo['id']);
  46. $form->addHidden('redirect', true);
  47. $form->addHidden('extra_field_type', $extraField->getExtraFieldType());
  48. $form->addButtonSave(get_lang('Save'));
  49. }
  50. $form->setDefaults([
  51. 'variable_language' => $variableLanguage,
  52. 'original_name' => $originalName,
  53. 'sub_language' => $languageId
  54. ]);
  55. $form->addRule('sub_language', get_lang('Required'), 'required');
  56. $form->freeze(['variable_language', 'original_name']);
  57. $interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH) . 'admin', 'name' => get_lang('Administration')];
  58. switch ($extraField->getExtraFieldType()) {
  59. case ExtraField::USER_FIELD_TYPE:
  60. $interbreadcrumb[] = [
  61. 'url' => api_get_path(WEB_CODE_PATH) . 'admin/extra_fields.php?type=user',
  62. 'name' => get_lang('UserFields')
  63. ];
  64. break;
  65. case ExtraField::COURSE_FIELD_TYPE:
  66. $interbreadcrumb[] = [
  67. 'url' => api_get_path(WEB_CODE_PATH) . 'admin/extra_fields.php?type=course',
  68. 'name' => get_lang('CourseFields')
  69. ];
  70. break;
  71. case ExtraField::SESSION_FIELD_TYPE:
  72. $interbreadcrumb[] = [
  73. 'url' => api_get_path(WEB_CODE_PATH) . 'admin/extra_fields.php?type=session',
  74. 'name' => get_lang('SessionFields')
  75. ];
  76. break;
  77. }
  78. $view = new Template(get_lang('AddWordForTheSubLanguage'));
  79. $view->assign('form', $form->returnForm());
  80. $template = $view->get_template('extrafield/translate.tpl');
  81. $content = $view->fetch($template);
  82. $view->assign('content', $content);
  83. $view->display_one_col_template();