2014-10-18 5 views
0

다중 언어 PHP 웹 사이트의 리소스 파일을 만들려고합니다. .po 파일을 만든 다음이 작은 라이브러리 https://github.com/josscrowcroft/php.mo을 사용하여 이진 .mo 파일로 변환했지만 작동하지 않는 것 같습니다. 하지만 생성 된 .po 파일을 Poedit으로 열고 저장을 누르면 .mo 파일 크기가 초기 파일 크기와 약간 변경되고 .po 파일이 작동하는 것을 관찰했습니다. Poedit Tool을 사용하지 않고 직접 작동시키는 법을 모르겠습니다.PHP에서 데이터베이스의 번역 된 strigs를 사용하여 .po 파일을 생성하는 방법은 무엇입니까?

갖고 계시다면 제안 해주세요. 감사합니다

+0

가능한 복제본 [.po에서 .mo 변환기에있는 PHP?] (http://stackoverflow.com/questions/1181681/po-to-mo-convertor-in-php) –

+0

문제는 .mo 파일에서 .po를 변환하는 것이 아니라 .po 파일을 생성합니다. 나와 Poedit에서 만든 .po 파일을 보면 내용이 동일하게 보이지만 어쨌든 크기는 조금 다르다! 나는 희망한다. 더 분명 해지다. – Bogdan

답변

0

다음 텍스트는 "마음에두고 중요한 것은 : 가와 .po 파일에 문자 집합을 설정하는 것을 잊지 마세요 예를 들면 다음과 같습니다!

"http://php.net/manual/en/book.gettext.php

에서 복사 내용 유형 : 텍스트/일반; 문자셋 = UTF-8이 때문에 \ n "

그리고 PHP는 CHARSET의 세트로와 .po 파일에서, 당신은 msgfmt에서를 사용하여 생성 된 .mo 파일을 찾을 수있을 것입니다.

내가 낭비했습니다

<?php 

//this: 
setlocale(LC_MESSAGES, 'pt_BR') 
//or this: 
setlocale(LC_MESSAGES, 'pt_BR.utf8') 
//or this: 
setlocale(LC_MESSAGES, '') 

//this: 
putenv("LANG=pt_BR.utf8"); 
//or this: 
putenv("LANGUAGE=pt_BR.utf8"); 

//this: 
bindtextdomain('mydomain', dirname(__FILE__).'/locale'); 
//or this: 
bindtextdomain("*", dirname(__FILE__).'/locale'); 
//or this: 
bindtextdomain('*', dirname(__FILE__).'/locale'); 

//setting or not "bind_textdomain_codeset()": 
bind_textdomain_codeset("mydomain", 'UTF-8'); 
?> 

뿐만 아니라 로케일 디렉토리의 이름을 설정하려면 무엇 :

./locale/pt_BR.UTF8/LC_MESSAGES을 많은 시간, 내 코드를 디버깅 할 때마다 하나의 작은 변화 사람들을 테스트 본 설명서와 인터넷을 통해 제안 /mydomain.mo

또는

./locale/pt_BR/LC_MESSAGES/mydomain.mo

또는

./locale/pt/LC_MESSAGES/mydomain.mo가

마지막 코드 가져 어느

<?php 

$directory = dirname(__FILE__).'/locale'; 
$domain = 'mydomain'; 
$locale ="pt_BR.utf8"; 

//putenv("LANG=".$locale); //not needed for my tests, but people say it's useful for windows 

setlocale(LC_MESSAGES, $locale); 
bindtextdomain($domain, $directory); 
textdomain($domain); 
bind_textdomain_codeset($domain, 'UTF-8'); 
?> 

올바른 번역 된 문자열은 다음과 같습니다. pt_BR을 사용하여 3 개의 디렉토리 이름을 계산했습니다. .utf8 로켈. (내 테스트는 아파치를 다시 시작한 다음 각 디렉토리를 시도했다.) 우분투 8.04 (하디) 아파치 2.2.8 PHP의 5.2.4-2ubuntu5을 :

내가 사용 = P

... 내가 낭비 한대로 다른 사람이 많은 시간을 낭비하지 않도록하기 위해 희망 .6 "