translate.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\ExtraField;
  4. $cidReset = true;
  5. require_once __DIR__.'/../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']) ? (int) $_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('Add terms to the sub-language'));
  36. $form->addText('variable_language', get_lang('Language variable'), false);
  37. $form->addText('original_name', get_lang('Original name'), false);
  38. $form->addSelect(
  39. 'sub_language',
  40. [get_lang('Sub-language'), get_lang('OnlyActiveSub-languagesAreListed')],
  41. $languagesOptions
  42. );
  43. if ($languageId) {
  44. $languageInfo = api_get_language_info($languageId);
  45. $form->addText(
  46. 'new_language',
  47. [get_lang('Translation'), get_lang('If this term has already been translated, this operation will replace its translation for this sub-language.')]
  48. );
  49. $form->addHidden('file_id', 0);
  50. $form->addHidden('id', $languageInfo['parent_id']);
  51. $form->addHidden('sub', $languageInfo['id']);
  52. $form->addHidden('sub_language_id', $languageInfo['id']);
  53. $form->addHidden('redirect', true);
  54. $form->addHidden('extra_field_type', $extraField->getExtraFieldType());
  55. $form->addButtonSave(get_lang('Save'));
  56. }
  57. $form->setDefaults([
  58. 'variable_language' => $variableLanguage,
  59. 'original_name' => $originalName,
  60. 'sub_language' => $languageId,
  61. ]);
  62. $form->addRule('sub_language', get_lang('Required'), 'required');
  63. $form->freeze(['variable_language', 'original_name']);
  64. $interbreadcrumb[] = ['url' => api_get_path(WEB_CODE_PATH).'admin', 'name' => get_lang('Administration')];
  65. switch ($extraField->getExtraFieldType()) {
  66. case ExtraField::USER_FIELD_TYPE:
  67. $interbreadcrumb[] = [
  68. 'url' => api_get_path(WEB_CODE_PATH).'admin/extra_fields.php?type=user',
  69. 'name' => get_lang('Profile attributes'),
  70. ];
  71. break;
  72. case ExtraField::COURSE_FIELD_TYPE:
  73. $interbreadcrumb[] = [
  74. 'url' => api_get_path(WEB_CODE_PATH).'admin/extra_fields.php?type=course',
  75. 'name' => get_lang('Course fields'),
  76. ];
  77. break;
  78. case ExtraField::SESSION_FIELD_TYPE:
  79. $interbreadcrumb[] = [
  80. 'url' => api_get_path(WEB_CODE_PATH).'admin/extra_fields.php?type=session',
  81. 'name' => get_lang('Session fields'),
  82. ];
  83. break;
  84. }
  85. $view = new Template(get_lang('Add terms to the sub-language'));
  86. $view->assign('form', $form->returnForm());
  87. $template = $view->get_template('extrafield/translate.tpl');
  88. $content = $view->fetch($template);
  89. $view->assign('content', $content);
  90. $view->display_one_col_template();