2011-02-12 4 views
1

gettext 번역을 위해 하나의 라이브러리를 추가했습니다. 해당하는 po 및 mo 파일을 추가했습니다.codeigniter의 gettext 문제

번역이 제대로 작동합니다.

이제 po 파일을 업데이트 할 때 일부 번역본을 변경하십시오. 그 후 페이지를 새로 고침하면 새 번역본이 아닌 이전 번역본을 얻게됩니다.

$this->pos_language->load_gettext('fr_FR'); 
echo $this->pos_language->_trans('Hello world, good morning'); 
+0

도움이 될 희망이 http://bit.ly/rrITVx

가 다시 시작 되세요 멋지 & 코드 점화와 PHP-gettext를 통합하기 위해 도우미를 썼다 아파치 (당신이 사용하고있는 웹 서버라고 가정)? – salathe

답변

1

난 당신이 파일을 .mo 귀하와 .po 파일을 컴파일 할 필요가 있다고 생각 :

/** 
* This method overides the original load method. Its duty is loading the domain files by config or by default internal settings. 
* 
*/ 
function load_gettext($userlang = false) { 

    /* I want the super object */ 
    if ($userlang) 
     $this->gettext_language = $userlang; 
    else 
     $this->gettext_language = 'it_IT'; 
    log_message('debug', 'Gettext Class gettext_language was set by parameter:' . $this->gettext_language); 

    putenv("LANG=$this->gettext_language"); 
    setlocale(LC_ALL, $this->gettext_language); 

    /* Let's set the path of .po files */ 
    $this->gettext_path = APPPATH . 'language/locale'; 
    log_message('debug', 'Gettext Class path chosen is: ' . $this->gettext_path); 

    bindtextdomain($this->gettext_domain, $this->gettext_path); 
    textdomain($this->gettext_domain); 
    log_message('debug', 'Gettext Class the domain chosen is: ' . $this->gettext_domain); 
    return true; 
} 

/** 
* Plural forms added by Tchinkatchuk 
* http://www.codeigniter.com/forums/viewthread/2168/ 
*/ 

/** 
* The translator method 
* 
* @param string $original the original string to translate 
* @param array $aParams the plural parameters 
* @return the string translated 
*/ 
function _trans($original, $aParams = false) { 
    if (isset($aParams['plural']) && isset($aParams['count'])) { 
     $sTranslate = ngettext($original, $aParams['plural'], $aParams['count']); 
     $sTranslate = $this->replaceDynamically($sTranslate, $aParams); 
    } else { 
     $sTranslate = gettext($original); 
     if (is_array($aParams) && count($aParams)) 
      $sTranslate = $this->replaceDynamically($sTranslate, $aParams); 
    } 
    return $sTranslate; 
} 

이것은 컨트롤러의 사용은 다음과 같습니다

여기 라이브러리 코드입니다. Gettext는 .mo 파일을 사용하고 .po는 사람이 읽을 수있는 형식입니다. http://wiki.creativecommons.org/Translating_PO_Files

+0

고마워 .. 그게 내가 생각하는 문제 였어, 지금은 매력처럼 작동하고있다 :) 건배 ... – viMaL

0
: 당신은 컴파일 단계를 수행하지 않은 경우

, 응용 프로그램이 여전히 ... 번역되지 않은 문자열,

을 이전 .mo 파일을 읽고이 페이지는 gettext의 번역에 대한 몇 가지 더 많은 정보를 가지고

나는 나는 그것이