팁/튜토리얼

Context::loadLang($path)

2015.08.16 15:43
9,906
1

정의 위치

  • ./classes/context/Context.class.php

정의 내용

/**
 * Load language file according to language type
 *
 * @param string $path Path of the language file
 * @return void
 */
function loadLang($path)
{
    global $lang;

    is_a($this, 'Context') ? $self = $this : $self = self::getInstance();
    if(!$self->lang_type)
    {
        return;
    }
    if(!is_object($lang))
    {
        $lang = new stdClass;
    }

    if(!($filename = $self->_loadXmlLang($path)))
    {
        $filename = $self->_loadPhpLang($path);
    }

    if(!is_array($self->loaded_lang_files))
    {
        $self->loaded_lang_files = array();
    }
    if(in_array($filename, $self->loaded_lang_files))
    {
        return;
    }

    if($filename && is_readable($filename))
    {
        $self->loaded_lang_files[] = $filename;
        include($filename);
    }
    else
    {
        $self->_evalxmlLang($path);
    }
}

 

파라메터

  • string $path : 불러오려는 언어파일이 존재하는 디렉토리 위치 문자열. 예를 들어서 ./common/lang/lang.xml 을 불러온다면, ./common/lang

용도

  • 필요한 언어파일을 불러올 수 있다.
  • XE Core 초기 버전에서 사용하던 lang.언어코드.php 형식의 언어파일도 잘 불러온다.
  • 참고 : 템플릿에서는 <load> 구문을 이용할 수 있다. <load target="./lang" />
  • 참고2 : XE Core 구문상 이미 언어 파일이 로드 되어 있는 경우가 많을 것이다.

예제

  • ./classes/context/Context.class.php 내용 중 loadJavascriptPlugin 메소드
    • /**
       * Load javascript plugin
       *
       * @param string $plugin_name plugin name
       * @return void
       */
      function loadJavascriptPlugin($plugin_name)
      {
          static $loaded_plugins = array();

          is_a($this, 'Context') ? $self = $this : $self = self::getInstance();
          if($plugin_name == 'ui.datepicker')
          {
              $plugin_name = 'ui';
          }

          if($loaded_plugins[$plugin_name])
          {
              return;
          }
          $loaded_plugins[$plugin_name] = TRUE;

          $plugin_path = './common/js/plugins/' . $plugin_name . '/';
          $info_file = $plugin_path . 'plugin.load';
          if(!is_readable($info_file))
          {
              return;
          }

          $list = file($info_file);
          foreach($list as $filename)
          {
              $filename = trim($filename);
              if(!$filename)
              {
                  continue;
              }

              if(strncasecmp('./', $filename, 2) === 0)
              {
                  $filename = substr($filename, 2);
              }
              if(substr_compare($filename, '.js', -3) === 0)
              {
                  $self->loadFile(array($plugin_path . $filename, 'body', '', 0), TRUE);
              }
              if(substr_compare($filename, '.css', -4) === 0)
              {
                  $self->loadFile(array($plugin_path . $filename, 'all', '', 0), TRUE);
              }
          }

          if(is_dir($plugin_path . 'lang'))
          {
              $self->loadLang($plugin_path . 'lang');
          }
      }

       
  • ./classes/module/ModuleHandler.class.php 내용 중 getModuleInstance 메소드 :  이 덕에 모듈로 불러오면 이미 언어파일이 로드된 경우가 많다.
    • /**
       * It creates a module instance
       * @param string $module module name
       * @param string $type instance type, (e.g., view, controller, model)
       * @param string $kind admin or svc
       * @return ModuleObject module instance (if failed it returns null)
       * @remarks if there exists a module instance created before, returns it.
       * */
      function &getModuleInstance($module, $type = 'view', $kind = '')
      {

          if(__DEBUG__ == 3)
          {
              $start_time = getMicroTime();
          }

          $parent_module = $module;
          $kind = strtolower($kind);
          $type = strtolower($type);

          $kinds = array('svc' => 1, 'admin' => 1);
          if(!isset($kinds[$kind]))
          {
              $kind = 'svc';
          }

          $key = $module . '.' . ($kind != 'admin' ? '' : 'admin') . '.' . $type;

          if(is_array($GLOBALS['__MODULE_EXTEND__']) && array_key_exists($key, $GLOBALS['__MODULE_EXTEND__']))
          {
              $module = $extend_module = $GLOBALS['__MODULE_EXTEND__'][$key];
          }

          // if there is no instance of the module in global variable, create a new one
          if(!isset($GLOBALS['_loaded_module'][$module][$type][$kind]))
          {
              ModuleHandler::_getModuleFilePath($module, $type, $kind, $class_path, $high_class_file, $class_file, $instance_name);

              if($extend_module && (!is_readable($high_class_file) || !is_readable($class_file)))
              {
                  $module = $parent_module;
                  ModuleHandler::_getModuleFilePath($module, $type, $kind, $class_path, $high_class_file, $class_file, $instance_name);
              }

              // Check if the base class and instance class exist
              if(!class_exists($module, true))
              {
                  return NULL;
              }
              if(!class_exists($instance_name, true))
              {
                  return NULL;
              }

              // Create an instance
              $oModule = new $instance_name();
              if(!is_object($oModule))
              {
                  return NULL;
              }

              // Load language files for the class
              Context::loadLang($class_path . 'lang');
              if($extend_module)
              {
                  Context::loadLang(ModuleHandler::getModulePath($parent_module) . 'lang');
              }

              // Set variables to the instance
              $oModule->setModule($module);
              $oModule->setModulePath($class_path);

              // If the module has a constructor, run it.
              if(!isset($GLOBALS['_called_constructor'][$instance_name]))
              {
                  $GLOBALS['_called_constructor'][$instance_name] = TRUE;
                  if(@method_exists($oModule, $instance_name))
                  {
                      $oModule->{$instance_name}();
                  }
              }

              // Store the created instance into GLOBALS variable
              $GLOBALS['_loaded_module'][$module][$type][$kind] = $oModule;
          }

          if(__DEBUG__ == 3)
          {
              $GLOBALS['__elapsed_class_load__'] += getMicroTime() - $start_time;
          }

          // return the instance
          return $GLOBALS['_loaded_module'][$module][$type][$kind];
      }

       
  • ./modules/editor/skins/ckeditor/file_upload.html
    • <!--%load_js_plugin("jquery.fileupload")-->
      <!--%load_js_plugin("jquery.finderSelect")-->
      <!--%load_js_plugin("handlebars")-->
      <load target="./lang" />
      <div cond="$allow_fileupload" id="xefu-container-{$editor_sequence}" class="xefu-container xe-clearfix" data-editor-sequence="{$editor_sequence}">
          <!--// dropzone -->
          <div class="xefu-dropzone">
              <span class="xefu-btn fileinput-button xefu-act-selectfile">
                  <span><i class="xi-icon xi-file-add"></i> {$lang->edit->upload_file}</span>
                  <input id="xe-fileupload" type="file" class="fileupload-processing " value="{$lang->edit->upload_file}" name="Filedata" data-auto-upload="true" data-editor-sequence="{$editor_sequence}" multiple />
              </span>

              <p class="xefu-dropzone-message">{$lang->ckeditor_about_file_drop_area}</p>

              <p class="upload_info">{$lang->allowed_filesize} : <span class="allowed_filesize">0MB</span> <span>({$lang->allowed_filetypes} : <span class="allowed_filetypes">*.*</span>)</span></p>

              <p class="xefu-progress-status" style="display: none;">{$lang->ckeditor_file_uploading} (<span class="xefu-progress-percent">0%</span>)</p>
              <div class="xefu-progressbar" style="display: none;"><div></div></div>
          </div>
          <!--// END:dropzone -->

          <div class="xefu-controll xe-clearfix">
              <div style="float: left;">
                  {$lang->ckeditor_file_count} (<span class="attached_size"></span> / <span class="allowed_attach_size"></span>)
              </div>

              <div style="float: right">
                  <input type="button" class="xefu-btn xefu-act-link-selected" style=" vertical-align: middle; vertical-align: middle;" value="{$lang->edit->link_file}">
                  <input type="button" class="xefu-btn xefu-act-delete-selected" style=" vertical-align: middle; vertical-align: middle;" value="{$lang->edit->delete_selected}">
              </div>
          </div>

          <div class="xefu-list">
              <div class="xefu-list-images">
                  <ul>
                  </ul>
              </div>

              <div class="xefu-list-files">
                  <ul>
                  </ul>
              </div>
          </div>

      </div>

      <script>
          jQuery(function($){
              // uploader
              <!--@if($allow_fileupload)-->
              var setting = {
                  maxFileSize: {$file_config->allowed_filesize},
                  limitMultiFileUploadSize: {$file_config->allowed_filesize}
              };
              var uploader = $('#xefu-container-{$editor_sequence}').xeUploader(setting);
              window.xe.msg_exceeds_limit_size = '{$lang->msg_exceeds_limit_size}';
              window.xe.msg_checked_file_is_deleted = '{$lang->msg_checked_file_is_deleted}';
              window.xe.msg_file_cart_is_null = '{$lang->msg_file_cart_is_null}';
              window.xe.msg_checked_file_is_deleted = '{$lang->msg_checked_file_is_deleted}';
              window.xe.msg_not_allowed_filetype = '{$lang->msg_not_allowed_filetype}';
              window.xe.msg_file_upload_error = '{$lang->msg_file_upload_error}';
              <!--@endif-->
          });
      </script>

       

댓글 1