Ignore:
Timestamp:
Feb 6, 2009 11:33:46 AM (4 years ago)
Author:
thomasb
Message:

Add localization functions to plugin API

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-api/program/include/rcube_plugin.php

    r2267 r2279  
    4040    $this->api = $api; 
    4141    $this->home = $api->dir . DIRECTORY_SEPARATOR . $this->ID; 
    42  
    43     $this->init(); 
    4442  } 
    4543   
     
    5957    $this->api->register_hook($hook, $callback); 
    6058  } 
     59   
     60  /** 
     61   * Load localized texts from the plugins dir 
     62   * 
     63   * @param string Directory to search in 
     64   * @param string Domain to save texts 
     65   */ 
     66  public function add_texts($dir) 
     67  { 
     68    if (empty($domain)) 
     69      $domain = $this->ID; 
     70     
     71    $lang = $_SESSION['language']; 
     72    $locdir = slashify(realpath(slashify($this->home) . $dir)); 
     73    $texts = array(); 
     74     
     75    foreach (array('en_US', $lang) as $lng) { 
     76      @include($locdir . $lng . '.inc'); 
     77      $texts = (array)$labels + (array)$messages + (array)$texts; 
     78    } 
    6179 
     80    // prepend domain to text keys and add to the application texts repository 
     81    if (!empty($texts)) { 
     82      $add = array(); 
     83      foreach ($texts as $key => $value) 
     84        $add[$domain.'.'.$key] = $value; 
     85 
     86      $rcmail = rcmail::get_instance(); 
     87      $rcmail->load_language($lang, $add); 
     88    } 
     89  } 
     90   
     91  /** 
     92   * Wrapper for rcmail::gettext() adding the plugin ID as domain 
     93   */ 
     94  function gettext($p) 
     95  { 
     96    return rcmail::get_instance()->gettext($p, $this->ID); 
     97  } 
     98   
    6299  /** 
    63100    * Register a handler for a specific client-request action 
Note: See TracChangeset for help on using the changeset viewer.